
postgresql mcp
Postgres MCP Pro is a powerful Model Context Protocol (MCP) server for PostgreSQL, providing configurable read/write access, advanced performance analysis, index tuning, explain plans, and safe SQL execution for AI agents.
Overview
PostgreSQL MCP (commonly referred to as Postgres MCP Pro) is an open-source Model Context Protocol (MCP) server designed to give AI agents secure and intelligent access to PostgreSQL databases.
It goes far beyond basic query execution by offering configurable read-only or read/write modes, comprehensive performance diagnostics, automated index recommendations, and production-grade safety features. Built to support the full development lifecycle — from schema exploration and coding to testing, deployment, and ongoing maintenance.
Popular implementations include the original Anthropic reference (now deprecated/archived due to security considerations), community forks, and enhanced versions like Postgres MCP Pro by Crystal DBA.
Features
- Configurable Access Modes: Strict read-only transactions (prevents modifications) or controlled read/write with transaction safety.
- Schema & Data Exploration: List tables, inspect schemas, columns, indexes, constraints, and run natural language-powered queries.
- Performance Analysis: Health checks for buffer cache, vacuum status, replication lag, connection utilization, sequence limits, and more.
- Index Tuning & Explain Plans: Advanced index recommendation engine that tests thousands of combinations; support for hypothetical indexes and detailed query explain plans.
- Safe SQL Execution: Read-only wrappers, query validation, and safeguards against dangerous operations.
- AI-Agent Optimized: Tools designed for low token usage, clear output formatting, and seamless integration with Claude, Cursor, Gemini, and other MCP clients.
- Docker & Easy Deployment: Official Docker image for consistent, dependency-free runs.
- Extensible: Supports community Postgres, RDS, Aurora, and most PostgreSQL v12+ instances.
Use Cases
- AI-Assisted Database Development: Let your AI agent explore schemas, suggest optimal queries, or generate migrations in natural language.
- Performance Tuning: Ask "Analyze slow queries" or "Recommend indexes for this table" — receive actionable insights with explain plans.
- Production Monitoring: Run health checks, detect bloat, or monitor vacuum/autovacuum without manual SQL.
- Safe Data Analysis: Grant read-only access for reporting, analytics, or customer support agents without risking data integrity.
- Full Development Workflow: From initial project setup and testing to deployment and ongoing optimization — all driven by conversational AI.
Installation & Quick Start
Using Docker (Recommended)
Pull and run the official image:
docker run -p 8080:8080 crystaldba/postgres-mcp --connection-string "postgresql://user:pass@localhost:5432/mydb"
Python / uv Installation
uv pip install postgres-mcp
uv run postgres-mcp "postgresql://user:password@localhost:5432/dbname"
Configuration for Clients (Claude Desktop, Cursor, etc.)
Add to your MCP config (e.g., ~/.cursor/mcp.json or Claude settings) with the appropriate command/args pointing to the running server.
Full documentation, connection examples, and security best practices are available in the repository.
Security Notes
- Prefer read-only mode for untrusted agents.
- The original Anthropic reference implementation had a known SQL injection vulnerability (patched in forks and later versions).
- Always use connection strings with least-privilege users and consider network-level restrictions.
Links
- GitHub (Postgres MCP Pro): crystaldba/postgres-mcp
- Other notable implementations: pgEdge Postgres MCP, AWS Labs Aurora MCP, various community forks.
- Model Context Protocol: Official MCP specification.
Postgres MCP turns your database into a first-class tool for AI agents, making intelligent data interaction as simple as chatting with your assistant.