
Postgres MCP Pro
Read/write Postgres access plus index tuning, EXPLAIN plans, and database health analysis for AI agents.
Add to your client
Copy the config for your MCP client and paste it into its config file.
uvx postgres-mcp --access-mode=restrictedPaste into ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"postgres-mcp-pro": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"DATABASE_URI",
"crystaldba/postgres-mcp",
"--access-mode=restricted"
],
"env": {
"DATABASE_URI": "postgresql://<user>:<password>@<host>:5432/<dbname>"
}
}
}
}Requires Docker to be installed and running.
Step-by-step guides: Add to Claude Desktop · Add to Cursor · Add to Windsurf
Before you start
- A reachable PostgreSQL database and a connection string in the form postgresql://user:password@host:5432/dbname
- Python 3.12+ with the uv or pipx package manager, OR Docker if you prefer the container image
- Recommended Postgres extensions for full functionality: pg_stat_statements (query stats) and hypopg (hypothetical indexes for tuning)
- An MCP-capable client (Claude Desktop, Cursor, Windsurf, etc.)
About Postgres MCP Pro
Postgres MCP Pro (by Crystal DBA) is an open-source MCP server that gives AI agents deep, performance-aware access to any PostgreSQL database — not just a generic SQL pipe. Beyond reading and writing data, it does index tuning, validates EXPLAIN plans, surfaces slow queries, and runs comprehensive database health checks.
It connects to a standard Postgres instance via a DATABASE_URI connection string and runs as the database user you provide, so its permissions are whatever that role allows. It supports two access modes: unrestricted for development (full read/write to data and schema) and restricted for production (read-only transactions with resource/time limits).
The standout feature is principled index tuning: it uses a greedy search over candidate indexes and simulates their impact with the hypopg extension (hypothetical indexes) and pg_stat_statements query stats — recommending indexes without actually creating them. It is Python-only (distributed on PyPI and as a Docker image), and supports both stdio and SSE transports.
Tools & capabilities (9)
list_schemasList all schemas in the database
list_objectsList tables, views, sequences, and extensions within a schema
get_object_detailsGet columns, constraints, and indexes for a table/view/object
execute_sqlRun SQL; read-only when the server is in restricted mode
explain_queryReturn the execution plan, optionally simulating hypothetical indexes
get_top_queriesReport the slowest/most resource-intensive queries via pg_stat_statements
analyze_workload_indexesRecommend indexes for the overall workload using greedy search + hypopg
analyze_query_indexesRecommend indexes for a specific set of SQL queries (up to 10)
analyze_db_healthRun health checks: cache hit rates, connections, vacuum, index bloat, replication, constraints, sequence limits
When to use it
- Use it when a query is slow and you want the agent to propose and validate the right index via EXPLAIN and hypothetical-index simulation
- Use it when you want a workload-wide index tuning pass instead of guessing at single indexes
- Use it when you need a database health checkup — bloat, cache hit ratio, vacuum status, replication lag, invalid constraints
- Use it when you want a read-only, resource-capped agent connection that is safe to point at production
- Use it when you want an agent to explore an unfamiliar schema (schemas, tables, constraints, indexes)
- Use it when you need ad-hoc SQL execution from your AI client during development
Quick setup
- 1Install via pipx install postgres-mcp, uv pip install postgres-mcp, or docker pull crystaldba/postgres-mcp
- 2(Recommended) Enable the pg_stat_statements and hypopg extensions in your database
- 3Add the server to your MCP client config, setting DATABASE_URI to your connection string
- 4Choose an access mode with --access-mode restricted (production) or unrestricted (development)
- 5Restart the client, then verify by asking the agent to list schemas or run analyze_db_health
Security notes
The DATABASE_URI contains full Postgres credentials, so store it securely and prefer a least-privilege role. Use --access-mode=restricted (read-only) unless the agent genuinely needs write/DDL access.
Postgres MCP Pro FAQ
Is there an npm package?
No. Postgres MCP Pro is Python-only, distributed on PyPI (pipx/uv) and as a Docker image. There is no Node/npm package.
How do I make it safe for production?
Run with --access-mode restricted, which limits operations to read-only transactions and applies resource/time limits, and connect with a least-privilege database role.
Why do I need pg_stat_statements and hypopg?
pg_stat_statements powers slow-query analysis, and hypopg lets the server simulate indexes to test their impact without creating them. Without them, tuning and top-query features are limited.
Does it actually create indexes for me?
No — index tuning is advisory. It simulates candidate indexes with hypopg and recommends them; you decide whether to apply the DDL.
Which transports does it support?
Both stdio (default, for a single client) and SSE via the --transport flag, which lets multiple clients share one running server.
Alternatives to Postgres MCP Pro
Compare all alternatives →Google's official MCP server with prebuilt BigQuery tools, querying datasets via Application Default Credentials.
Official Supabase server: manage tables, run SQL, branches, configs and edge functions from your AI client.
Manage serverless Postgres on Neon with natural language: projects, branches, migrations, and SQL.
Compare Postgres MCP Pro with: