PostgreSQL MCP Server is a production-ready enterprise-grade MCP server bringing comprehensive PostgreSQL operations to AI-native workflows. With 63 specialized tools, 10 intelligent resources for database meta-awareness, and 10 guided prompts for complex operations across 9 categories, zero known vulnerabilities, and support for advanced extensions like pgvector, PostGIS, and hypopg, this server transforms how developers interact with PostgreSQL databases through MCP clients like Claude Desktop and Cursor.
🏆 Enterprise-Grade Features
🛡️ Zero Known Vulnerabilities
- Comprehensive security audit passed
- 20+ security test cases
- SQL injection prevention
- Parameter binding protection
- CodeQL security scanning
🧠 AI-Native Operations
- pgvector for embeddings
- Semantic similarity search
- Vector clustering & analysis
- Natural language queries
- ML-ready architecture
⚡ Performance Intelligence
- AI-powered index tuning
- Hypothetical index testing
- Query plan optimization
- Workload analysis
- Slow query detection
🌍 Geospatial Operations
- PostGIS integration
- Distance calculations
- Spatial queries
- GIS operations
- Geographic analysis
🔮 Intelligent Meta-Awareness
- 10 real-time resources
- Automatic database context
- Schema intelligence
- Performance insights
- Proactive recommendations
🎯 Guided Workflows
- 10 expert prompts
- Step-by-step guidance
- PostgreSQL best practices
- Complex operation support
- Error prevention
🎛️ Tool Filtering
- Client-aware tool management
- Token savings up to 86%
- 9 configurable tool groups
- Windsurf/Cursor optimized
- Zero breaking changes
📊 Complete Tool Suite
PostgreSQL MCP Server provides 63 specialized tools across 9 comprehensive categories:
- Core Database Operations (9 tools) - Schema management and SQL execution
- JSON Operations (11 tools) - JSONB validation and transformation
- Text Processing (5 tools) - Using pg_trgm and fuzzystrmatch
- Statistical Analysis (8 tools) - Correlation and regression analysis
- Performance Intelligence (6 tools) - AI-powered optimization via hypopg
- Vector/Semantic Search (8 tools) - pgvector integration for AI workflows
- Geospatial Operations (7 tools) - PostGIS support for location data
- Backup & Recovery (4 tools) - Disaster recovery strategies
- Monitoring & Alerting (5 tools) - Real-time health checks
✨ Intelligent Database Assistant
PostgreSQL MCP Server transforms from a tool collection into an intelligent database expert with real-time meta-awareness and guided workflows:
🔮 MCP Resources (10) - Database Meta-Awareness
Real-time database context that AI can access automatically without explicit tool calls:
- database://schema - Complete database structure with tables, columns, indexes
- database://capabilities - Server features, extensions, pg_stat_statements status
- database://performance - Top queries, cache hit rates, slow query detection
- database://health - Connection pool, indexes, vacuum status
- database://extensions - pgvector, PostGIS, hypopg availability with versions
- database://indexes - Usage statistics, size, recommendations
- database://connections - Active connections and pool utilization
- database://replication - Replication lag and health monitoring
- database://vacuum - Bloat detection and transaction ID wraparound
- database://locks - Active locks and blocking query detection
Key Benefit: Resources reduce token usage by providing cached context instead of repeated queries, enabling AI to understand your database state proactively.
🎯 MCP Prompts (10) - Guided Workflows
Step-by-step workflows for complex database operations with PostgreSQL best practices:
- optimize_query - Complete query optimization workflow
- index_tuning - Comprehensive index analysis and recommendations
- database_health_check - Full health assessment with actionable insights
- setup_pgvector - Complete pgvector installation and configuration guide
- setup_postgis - Complete PostGIS setup and spatial query guide
- json_operations - JSONB best practices and optimization strategies
- performance_baseline - Establish performance monitoring baselines
- backup_strategy - Design enterprise backup and recovery strategies
- extension_setup - Step-by-step extension installation guide
- explain_analyze_workflow - Deep dive into query execution plans
Key Benefit: Prompts guide users through multi-step operations with PostgreSQL-specific best practices, reducing errors and improving outcomes.
🔄 Latest Updates (v1.2.0)
Version 1.2.0 introduces intelligent tool filtering to optimize the server for any MCP client:
- 🎛️ Tool Filtering System - New
POSTGRES_MCP_TOOL_FILTERenvironment variable controls which tools are exposed. Use-vector,-geoto disable extension-dependent tools, or-vector,-geo,-stats,-textfor Windsurf's 100-tool limit. - 💰 Token Savings (24-86%) - Reduce token overhead by filtering unused tool groups. Core-only configuration saves ~10,800 tokens per conversation, translating to $3.24 saved at GPT-4 pricing.
- 🎯 9 Tool Groups - Organize 63 tools into core, json, text, stats, performance, vector, geo, backup, and monitoring groups for flexible configuration.
- ✅ Client Compatibility - Stay under Windsurf's 100-tool hard limit and avoid Cursor's ~80 tool performance warnings while maintaining full functionality.
- 🔧 Flexible Syntax - Use
-groupto disable all tools in a group,-toolto disable specific tools, or+toolto re-enable after a group disable.
Backward Compatibility: v1.2.0 is a drop-in replacement with zero breaking changes. Without filtering, all 63 tools remain enabled.
🚀 Quick Start
Docker (Recommended)
Pull the latest image:
docker pull writenotenow/postgres-mcp-enhanced:latestRun with your database connection:
docker run -i --rm \
-e DATABASE_URI="postgresql://user:pass@localhost:5432/db" \
writenotenow/postgres-mcp-enhanced:latest \
--access-mode=restrictedPython Installation
pip install postgres-mcp-enhancedRun the server:
postgres-mcp --access-mode=restrictedFrom Source
git clone https://github.com/neverinfamous/postgres-mcp.git
cd postgres-mcp
uv sync
uv run pytest -v🔒 Security Features
Security is a top priority in PostgreSQL MCP Server. We've implemented comprehensive protection including SQL injection prevention through parameter binding, dual security modes for production and development, advanced query validation, 20+ security test cases, CodeQL scanning, and zero known vulnerabilities with a clean security audit.
For detailed security implementation examples and best practices, see our Security Best Practices Gist.
📖 MCP Configuration
Configure for Claude Desktop or Cursor by adding to your MCP settings file:
{
"mcpServers": {
"postgres": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "DATABASE_URI",
"-e", "POSTGRES_MCP_TOOL_FILTER",
"writenotenow/postgres-mcp-enhanced:latest",
"--access-mode=restricted"
],
"env": {
"DATABASE_URI": "postgresql://user:pass@localhost:5432/db",
"POSTGRES_MCP_TOOL_FILTER": "-vector,-geo"
}
}
}
}The POSTGRES_MCP_TOOL_FILTER is optional. Use -vector,-geo to disable extension-dependent tools, or -vector,-geo,-stats,-text for clients with tool limits like Windsurf.
💡 Use Cases & Expert Guides
PostgreSQL MCP Server excels in diverse scenarios including AI-native data operations with pgvector embeddings and semantic search, location-based services with PostGIS geospatial queries, performance engineering with automated index recommendations and query optimization, plus comprehensive data analytics with statistical analysis and time series processing.
Master PostgreSQL MCP operations with comprehensive expert guides:
🧠 Vector/Semantic Search with pgvector
AI-native embeddings and similarity search for intelligent applications.
- Embedding insertion and vector storage
- Similarity search with multiple distance metrics
- Vector clustering and analysis
- HNSW and IVFFlat index optimization
⚡ Performance Intelligence & Query Optimization
AI-powered index tuning and query plan optimization.
- Hypothetical index testing with hypopg
- Automated index recommendations
- Query plan analysis and optimization
- Workload analysis and bottleneck detection
🌍 Geospatial Operations with PostGIS
Location-based services and comprehensive GIS operations.
- Distance calculations and proximity search
- Spatial queries and geometry operations
- Coordinate system transformations
- GIST and BRIN spatial indexing
📊 JSON/JSONB Operations Masterclass
Advanced JSON data operations and validation.
- JSONB CRUD operations and modifications
- Schema validation and security scanning
- Path validation and extraction
- Aggregation and statistical analysis
📈 Enterprise Monitoring & Alerting
Real-time health checks and comprehensive observability.
- Real-time performance monitoring
- Capacity planning and resource analysis
- Alert threshold configuration
- Replication health monitoring
🎯 Complete Feature Showcase
Comprehensive demonstration of all 63 specialized tools.
- Core database operations and schema management
- Text processing and statistical analysis
- Backup & recovery strategies
- Complete API reference with examples
💡 Pro Tip: These expert guides include production-ready code examples and best practices. Start with the Complete Feature Showcase to understand the full scope, then dive into specialized guides for your specific use case.
📚 Resources
Find comprehensive documentation, source code, container images, and installation packages through our official channels: Documentation Wiki, GitHub Repository, Docker Hub, and PyPI Package.
🎯 What's Next
PostgreSQL MCP Server represents a major milestone in bringing enterprise-grade database operations to AI-native workflows. With 63 specialized tools, 10 intelligent resources for database meta-awareness, 10 guided prompts for complex operations, zero known vulnerabilities, and production-ready reliability, it's ready to transform how you work with PostgreSQL databases.
The intelligent assistant capabilities enable AI to understand your database context proactively, provide PostgreSQL-specific recommendations, and guide you through complex operations with best practices built in.
💡 Pro Tip: Start with restricted mode for production environments, explore the MCP Resources for instant database insights, use MCP Prompts for guided workflows, and leverage the 63 specialized tools to streamline your database operations.
🔗 Related Resources
Explore our MCP Server Hub for additional tools including SQLite MCP Server and Memory Journal MCP.
🏆 Why PostgreSQL MCP Matters
PostgreSQL MCP delivers production-ready reliability with zero known vulnerabilities, intelligent database assistant with 10 real-time resources and 10 guided prompts, AI-native operations through pgvector support, performance intelligence with hypothetical index testing, geospatial capabilities via PostGIS, 63 specialized tools across 9 categories, intelligent tool filtering for client compatibility and token savings, and a security-first design with dual access modes. This represents the evolution from a powerful tool collection to a truly intelligent database expert.
