postgres-mcp
A production-ready MCP server for PostgreSQL — built for Claude Desktop, Claude Code, and any MCP-compatible AI agent.
README
postgres-mcp
A production-ready MCP server for PostgreSQL — built for Claude Desktop, Claude Code, and any MCP-compatible AI agent.
Extends crystaldba/postgres-mcp with:
- Aurora IAM auth — connect to AWS Aurora Postgres without embedding passwords
- Playbook mode — chain diagnostic tools into named runbooks Claude executes end-to-end
- Pre-packaged Claude Desktop config — one paste and you're connected
- rajivonai brand config — opinionated defaults that pair with pg-advisor and easy-pg-lab
Claude → postgres-mcp → your Postgres (local, RDS, or Aurora)
What this MCP server can do
| Tool exposed to Claude | What it does |
|---|---|
query |
Execute a read-only SQL query and return results |
explain |
Run EXPLAIN (ANALYZE, BUFFERS) and parse the plan |
schema |
Describe tables, columns, indexes, constraints in a database |
health_check |
Run a battery of health checks (vacuum, connections, cache hit ratio, replication) |
index_advisor |
Suggest indexes using cost-based simulation (no writes needed) |
playbook |
Execute a named diagnostic playbook end-to-end |
What it does NOT do by default:
- No INSERT / UPDATE / DELETE / DDL (read-only mode is the default)
- No cross-database access (scoped to the configured database)
- No credential storage (uses env vars or IAM)
You can enable write access with --allow-writes — but for production, read-only is recommended.
What crystaldba/postgres-mcp already provides (and we inherit)
This project builds on crystaldba/postgres-mcp. Credit to the crystaldba team for:
- Real cost-based index simulation using the Anytime Algorithm
- EXPLAIN plan analysis and bottleneck identification
- Built-in health checks (buffer cache, vacuum, sequences, replication)
- Configurable read/write access controls
We do not fork or modify their core engine — we wrap it and add the layers described above. If a feature request belongs in the core, we'll upstream it.
Install
pip install postgres-mcp
# or from source:
git clone https://github.com/rajivonai/postgres-mcp && cd postgres-mcp
pip install -e .
Requires Python 3.11+.
Quick start
Standard Postgres (local or RDS password auth)
postgres-mcp serve \
--host localhost \
--port 5432 \
--user postgres \
--dbname mydb
Or via connection string:
postgres-mcp serve --url "postgresql://user:pass@host:5432/mydb"
Aurora Postgres with IAM auth (no password needed)
postgres-mcp serve \
--aurora-host my-cluster.cluster-xxxx.us-east-1.rds.amazonaws.com \
--aurora-region us-east-1 \
--aurora-user myuser \
--dbname mydb
Requires the AmazonRDSReadOnlyAccess IAM policy (or equivalent) on the calling role.
Claude Desktop setup
Add this to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"postgres": {
"command": "postgres-mcp",
"args": [
"serve",
"--url", "postgresql://postgres:postgres@localhost:5432/mydb"
]
}
}
}
For Aurora (uses AWS profile default):
{
"mcpServers": {
"postgres-aurora": {
"command": "postgres-mcp",
"args": [
"serve",
"--aurora-host", "my-cluster.cluster-xxxx.us-east-1.rds.amazonaws.com",
"--aurora-region", "us-east-1",
"--aurora-user", "myuser",
"--dbname", "mydb"
]
}
}
}
Restart Claude Desktop after editing.
Claude Code setup
# Add to your project's .claude/mcp.json
{
"servers": {
"postgres": {
"command": "postgres-mcp",
"args": ["serve", "--url", "${PG_URL}"]
}
}
}
Or run inline:
claude --mcp-server "postgres-mcp serve --url $PG_URL"
Playbooks
Playbooks are named diagnostic sequences — Claude executes a structured workflow rather than ad-hoc tool calls. Run them from the CLI:
postgres-mcp playbook slow-query --url "$PG_URL" --threshold-ms 500
postgres-mcp playbook pre-deploy --url "$PG_URL"
postgres-mcp playbook health --url "$PG_URL"
postgres-mcp playbook replica-lag --url "$PG_URL"
Or ask Claude directly (once the MCP server is running):
"Run the slow-query playbook on my database"
Available playbooks
| Playbook | What Claude does |
|---|---|
health |
Full cluster health check: vacuum, indexes, connections, config, replication |
slow-query |
Find queries over threshold, EXPLAIN the worst ones, recommend indexes |
pre-deploy |
Check for lock-heavy migrations, connection headroom, replication lag — safe to deploy? |
replica-lag |
Diagnose replication lag: network vs apply vs long query on replica |
bloat |
Estimate table and index bloat, rank by waste, recommend VACUUM or pg_repack |
Security model
| Mode | What's allowed | Recommended for |
|---|---|---|
--read-only (default) |
SELECT, EXPLAIN, pg_stat_* views | Production |
--allow-writes |
+ INSERT, UPDATE, DELETE | Dev/lab only |
--allow-ddl |
+ CREATE, ALTER, DROP | Lab with caution |
The server never executes statements outside the configured access level. All tool calls are logged to stderr.
Part of the rajivonai polyglot database toolkit
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.