> 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.

By Rhode Labs · Updated 2026-06-03

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.

CapabilityWhat it enables
list_schemasLists all schemas in the database so the assistant can orient itself.
list_objectsLists tables, views, sequences, and extensions within a schema.
get_object_detailsReturns columns, constraints, and indexes for a specific table or object.
execute_sqlRuns SQL statements: read-only when connected in restricted mode, read/write in unrestricted mode.
explain_queryShows the EXPLAIN execution plan, including simulation of hypothetical indexes.
get_top_queriesSurfaces the slowest queries by total execution time via pg_stat_statements.
analyze_workload_indexesRecommends indexes for the most resource-intensive queries in the workload.
analyze_query_indexesSuggests indexes for up to 10 specific queries you pass in.
analyze_db_healthRuns 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 a READ ONLY transaction. It has been moved to the servers-archived repository 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, EXPLAIN analysis, 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)?

  1. Get a connection string. Use a postgresql://user:password@host:5432/dbname URI for the database you want to expose. Start with a read-only role.

  2. Pick a runtime. Install via pipx install postgres-mcp, uv pip install postgres-mcp, or pull the Docker image crystaldba/postgres-mcp.

  3. 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" }
        }
      }
    }
  4. Pass --access-mode=restricted explicitly. The server defaults to unrestricted (read/write), so set restricted yourself until you trust the workflow, and only switch to unrestricted in development.

How we use it: Good for letting Claude answer “why is this query slow?” against a staging replica. explain_query plus analyze_workload_indexes turn a vague performance complaint into a concrete index recommendation you can review. Bad for letting an agent run migrations or UPDATEs on production; that is what unrestricted mode tempts you into, and it does not belong in an autonomous loop. The one gotcha: get_top_queries and the workload index analysis rely on the pg_stat_statements extension 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

Frequently asked questions

Does the Postgres MCP server work with Claude?
Yes. It works with any MCP client, including Claude Cowork, Claude Code, and Claude Desktop. You point it at a PostgreSQL connection string and Claude can inspect schemas and run SQL through the server's tools.
Is there an official Postgres MCP server?
There was a reference server (@modelcontextprotocol/server-postgres) from the MCP project, but it has been moved to the servers-archived repo and is no longer maintained. The leading actively-maintained option is the community Postgres MCP Pro from Crystal DBA.
Is the Postgres MCP server free?
Yes. Both the archived reference server and Crystal DBA's Postgres MCP Pro are open source under the MIT license. You only pay for the database and infrastructure you run it against.
Can the Postgres MCP server modify my data?
It depends on the access mode. Postgres MCP Pro defaults to unrestricted mode, which allows writes and schema changes; set --access-mode=restricted to force read-only transactions with execution-time limits, which is what you want for anything touching production.

Start Here

Ready to modernize?

Tell us where your team is stuck. We'll map the path from manual to automated, and show you what's possible in the first two weeks.

Book a Discovery Call