MCP & Connectors

How do you connect Claude to PostgreSQL via MCP?

QUICK ANSWER

To connect Claude to a PostgreSQL database, configure the postgres MCP server in your Claude Desktop configuration file and pass your database connection URI as an argument.

Configuration

Include the database connector configuration in your claude_desktop_config.json:

{
  "mcpServers": {
    "postgres-db": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "--conn",
        "postgresql://username:password@localhost:5432/dbname"
      ]
    }
  }
}

Replace username, password, localhost, 5432, and dbname with your target PostgreSQL server details.

Verified against: PostgreSQL MCP Server v0.2.1