> mcp integration
Postgres MCP Server: What It Does & How to Use It with Claude
What the Postgres MCP server does — run SQL, inspect schemas, analyze query performance, tune indexes — and connect it to Claude Cowork, Code, or Desktop.
The Postgres MCP server lets an AI assistant connect directly to a PostgreSQL database to inspect schemas, run SQL, and analyze query performance without you hand-copying results into the chat. The most capable, actively-maintained option is Postgres MCP Pro from Crystal DBA, since the original MCP reference server has been archived.
What can the Postgres MCP server do?
These are the tools exposed by Crystal DBA’s Postgres MCP Pro, the leading community server.
| Capability | What it enables |
|---|---|
| list_schemas | Lists all schemas in the database so the assistant can orient itself. |
| list_objects | Lists tables, views, sequences, and extensions within a schema. |
| get_object_details | Returns columns, constraints, and indexes for a specific table or object. |
| execute_sql | Runs SQL statements: read-only when connected in restricted mode, read/write in unrestricted mode. |
| explain_query | Shows the EXPLAIN execution plan, including simulation of hypothetical indexes. |
| get_top_queries | Surfaces the slowest queries by total execution time via pg_stat_statements. |
| analyze_workload_indexes | Recommends indexes for the most resource-intensive queries in the workload. |
| analyze_query_indexes | Suggests indexes for up to 10 specific queries you pass in. |
| analyze_db_health | Runs health checks across buffer cache, connections, constraints, indexes, sequences, and vacuum. |
Official vs community server: which one?
- Official reference server (
@modelcontextprotocol/server-postgres). Provided read-only access with schema inspection and read-only query execution inside aREAD ONLYtransaction. It has been moved to theservers-archivedrepository and is no longer maintained, so treat it as legacy. - Postgres MCP Pro (Crystal DBA). The practical default today. It is open source (MIT), actively maintained, and goes well beyond raw query execution: index tuning,
EXPLAINanalysis, and database health checks. It supports a restricted (read-only) and an unrestricted (read/write) access mode.
How do you connect it to Claude (Cowork / Code / Desktop)?
-
Get a connection string. Use a
postgresql://user:password@host:5432/dbnameURI for the database you want to expose. Start with a read-only role. -
Pick a runtime. Install via
pipx install postgres-mcp,uv pip install postgres-mcp, or pull the Docker imagecrystaldba/postgres-mcp. -
Add it to your MCP client config. In
claude_desktop_config.json(Desktop), your Claude Code MCP config, or your Cowork workspace’s connectors, register the server. With Docker it looks like:{ "mcpServers": { "postgres": { "command": "docker", "args": ["run", "-i", "--rm", "-e", "DATABASE_URI", "crystaldba/postgres-mcp", "--access-mode=restricted"], "env": { "DATABASE_URI": "postgresql://readonly:password@localhost:5432/mydb" } } } } -
Pass
--access-mode=restrictedexplicitly. The server defaults to unrestricted (read/write), so set restricted yourself until you trust the workflow, and only switch tounrestrictedin development.
How we use it: Good for letting Claude answer “why is this query slow?” against a staging replica.
explain_queryplusanalyze_workload_indexesturn a vague performance complaint into a concrete index recommendation you can review. Bad for letting an agent run migrations orUPDATEs on production; that is what unrestricted mode tempts you into, and it does not belong in an autonomous loop. The one gotcha:get_top_queriesand the workload index analysis rely on thepg_stat_statementsextension being installed and enabled. If it is not, those tools return empty or error, and the assistant may quietly fall back to guessing. Enable the extension first.
Security & permissions
Connect with a dedicated, least-privilege role and pass --access-mode=restricted whenever the database resembles production. Restricted mode forces read-only transactions and applies execution-time limits. Remember the server runs in unrestricted (read/write) mode by default, so you have to set this flag yourself. Never expose write or schema-modifying access to an agent that runs unattended.
Wiring Postgres into your stack
A Postgres MCP server is most useful when it sits alongside the rest of your data tooling: paired with Supabase for managed Postgres, GitHub for the code that queries it, or Grafana for the dashboards it feeds. If you want help scoping read-only roles, choosing access modes, and wiring it safely into Claude, that is the kind of work we do. Book a discovery call.
Sources: Postgres MCP Pro (Crystal DBA) · archived reference server · @modelcontextprotocol/server-postgres on npm