Skip to main content
Community resource — not affiliated with Anthropic. Learn more


PostgreSQL MCP

Databases · Official

Connect to PostgreSQL databases. Run queries, inspect schemas, manage tables, analyze data, and build reports with full SQL capabilities and read/write access.

4.7 rating 8,900+ connects Free · Open source Protocol v1.0
PostgreSQL SQL Schemas Official Transactions

Connect command

claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@localhost/db
View on GitHub →

Free · Open source · MIT license

8.9kConnects
4.7Rating

What it does

PostgreSQL MCP connects Claude to any Postgres database using a standard connection string. Claude becomes a capable SQL collaborator: it can explore an unfamiliar schema, write complex analytical queries, identify performance bottlenecks using EXPLAIN, and manage data with INSERT and UPDATE statements.

It works with local Postgres instances, cloud-hosted databases (AWS RDS, GCP Cloud SQL, Azure Database, Supabase, Neon), and any Postgres-compatible system like CockroachDB or Aurora.

  • Run any SQL query with results formatted as a table
  • List all tables across all schemas
  • Describe column definitions, types, nullability, and defaults
  • List available schemas within the database
  • Run EXPLAIN ANALYZE to profile query performance
  • Execute multi-statement transactions

How to connect

Replace the connection string with your actual database credentials:

terminal
claude mcp add postgres -- npx -y @modelcontextprotocol/server-postgres \
  "postgresql://myuser:mypassword@localhost:5432/mydb"

For cloud databases, use the full connection URL from your provider's dashboard.

Available tools

  • query — run a SQL query and return results
  • list_tables — list tables in the current schema
  • describe_table — return column definitions for a table
  • list_schemas — list all schemas in the database
  • explain_query — return the query execution plan
  • execute_transaction — run multiple statements atomically

Example usage

Ask Claude to investigate slow queries or build a monthly cohort analysis:

example prompt
# User prompt
Find the 5 slowest queries in my orders table,
show me their execution plans, and suggest
which columns to index.
tool call sequence
list_tables()
describe_table("orders")
explain_query("SELECT * FROM orders
  WHERE customer_id = $1 AND status = 'pending'
  ORDER BY created_at DESC LIMIT 20")
→ Seq Scan cost=0.00..8243.50
→ Claude recommends: CREATE INDEX ON orders(customer_id, status)

Production safety: For production databases, create a read-only Postgres user and use that connection string. Grant only SELECT privileges on the relevant schemas to prevent accidental data modification.