postgres-mcp

neverinfamous/postgres-mcp

3.3

If you are the rightful owner of postgres-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

Postgres MCP Pro is an open source Model Context Protocol (MCP) server designed to support AI agents throughout the development process, offering features like index tuning, explain plans, health checks, and safe SQL execution.

Tools
9
Resources
0
Prompts
0

PostgreSQL MCP Server - Version 1.1.1

Last Updated October 9, 2025 - Production/Stable v1.1.1

Enterprise-grade PostgreSQL MCP server with enhanced security, comprehensive testing, AI-native database operations, intelligent meta-awareness, and guided workflows.

Docker Pulls License: MIT Version Status PyPI CodeQL


๐Ÿ” AI-Powered Documentation Search โ†’

Can't find what you're looking for? Use our AI-powered search interface to search both PostgreSQL and SQLite MCP Server documentation:

  • ๐Ÿค– Natural Language Queries - Ask questions in plain English
  • โšก Instant Results - AI-enhanced answers with source attribution
  • ๐Ÿ“š Comprehensive Coverage - Searches all 63 PostgreSQL tools + 73 SQLite tools
  • ๐ŸŽฏ Smart Context - Understands technical questions and provides relevant examples

โ†’ Try AI Search Now

Example queries: "How do I optimize PostgreSQL query performance?", "What PostGIS features are available?", "How do I use pgvector for semantic search?"


๐Ÿ“š Complete Documentation - Visit the Wiki โ†’

For detailed documentation, examples, and guides, visit our comprehensive wiki:


๐Ÿš€ Quick Overview

63 specialized MCP tools + 10 intelligent resources + 10 guided prompts for PostgreSQL operations:

MCP Tools (63)

  • Core Database (9): Schema management, SQL execution, health monitoring
  • JSON Operations (11): JSONB operations, validation, security scanning
  • Text Processing (5): Similarity search, full-text search, fuzzy matching
  • Statistical Analysis (8): Descriptive stats, correlation, regression, time series
  • Performance Intelligence (6): Query optimization, index tuning, workload analysis
  • Vector/Semantic Search (8): Embeddings, similarity search, clustering
  • Geospatial (7): Distance calculation, spatial queries, GIS operations
  • Backup & Recovery (4): Backup planning, restore validation, scheduling
  • Monitoring & Alerting (5): Real-time monitoring, capacity planning, alerting

MCP Resources (10) - Database Meta-Awareness

  • database://schema: Complete schema with tables, columns, indexes
  • database://capabilities: Server capabilities and installed extensions
  • database://performance: Query performance metrics from pg_stat_statements
  • database://health: Comprehensive health status
  • database://extensions: Installed extensions with versions
  • database://indexes: Index usage statistics and recommendations
  • database://connections: Active connections and pool status
  • database://replication: Replication status and lag
  • database://vacuum: Vacuum status and transaction ID wraparound
  • database://locks: Current lock information
  • database://statistics: Table statistics quality

MCP Prompts (10) - Guided Workflows

  • optimize_query: Step-by-step query optimization
  • index_tuning: Comprehensive index analysis
  • database_health_check: Full health assessment
  • setup_pgvector: Complete pgvector setup guide
  • json_operations: JSONB best practices
  • performance_baseline: Establish performance baselines
  • backup_strategy: Design backup strategy
  • setup_postgis: PostGIS setup and usage
  • explain_analyze_workflow: Deep dive into EXPLAIN plans
  • extension_setup: Extension installation guide

Enhanced with pg_stat_statements, hypopg, pgvector, and PostGIS extensions.


๐Ÿ“‹ Prerequisites

  1. PostgreSQL Database (version 13-18)
  2. Environment Variable: DATABASE_URI="postgresql://user:pass@host:5432/db"
  3. MCP Client: Claude Desktop, Cursor, or compatible client

See Installation Guide for detailed setup instructions.


๐Ÿš€ Quick Start

Docker (Recommended)

docker pull neverinfamous/postgres-mcp:latest

docker run -i --rm \
  -e DATABASE_URI="postgresql://user:pass@localhost:5432/db" \
  neverinfamous/postgres-mcp:latest \
  --access-mode=restricted

Python Installation

pip install postgres-mcp-enhanced
postgres-mcp --access-mode=restricted

From Source

git clone https://github.com/neverinfamous/postgres-mcp.git
cd postgres-mcp
uv sync
uv run pytest -v

๐Ÿ“– See Full Installation Guide โ†’


๐Ÿ›ก๏ธ Security-First Design

Zero known vulnerabilities - Comprehensive security audit passed:

  • โœ… SQL injection prevention with parameter binding
  • โœ… 20+ security test cases covering all attack vectors
  • โœ… Dual security modes (restricted/unrestricted)
  • โœ… Advanced query validation
  • โœ… CodeQL security scanning passing
  • โœ… Pyright strict mode - 2,000+ type issues resolved, 100% type-safe codebase

Security Modes:

  • Restricted (Production): Read-only, query validation, resource limits
  • Unrestricted (Development): Full access with parameter binding protection

๐Ÿ“– Security Best Practices โ†’


๐Ÿข Enterprise Features

๐Ÿ” Real-Time Monitoring

  • Database health monitoring (indexes, connections, vacuum, buffer cache)
  • Query performance tracking via pg_stat_statements
  • Capacity planning and growth forecasting
  • Replication lag monitoring

โšก Performance Optimization

  • AI-powered index tuning with DTA algorithms
  • Hypothetical index testing via hypopg (zero-risk)
  • Query plan analysis and optimization
  • Workload analysis and slow query detection

๐Ÿง  AI-Native Operations

  • Vector similarity search via pgvector
  • Geospatial operations via PostGIS
  • Semantic search and clustering
  • Natural language database interactions

๐Ÿ“– Explore All Features โ†’


๐Ÿ“Š Features Overview

MCP Tools (63)

Explore comprehensive documentation for each category:

CategoryToolsDocumentation
Core Database9Core Tools โ†’
JSON Operations11JSON Tools โ†’
Text Processing5Text Tools โ†’
Statistical Analysis8Stats Tools โ†’
Performance Intelligence6Performance โ†’
Vector/Semantic Search8Vector Search โ†’
Geospatial7GIS Tools โ†’
Backup & Recovery4Backup Tools โ†’
Monitoring & Alerting5Monitoring โ†’

MCP Resources (10) - NEW in v1.1.0! ๐ŸŽ‰

Resources provide real-time database meta-awareness - AI can access these automatically without explicit tool calls:

ResourcePurposeWhen to Use
database://schemaComplete database structureUnderstanding database layout before queries
database://capabilitiesServer features and extensionsChecking what operations are available
database://performanceQuery performance metricsIdentifying slow queries proactively
database://healthDatabase health statusProactive monitoring and issue detection
database://extensionsExtension inventoryVerifying required features are installed
database://indexesIndex usage statisticsFinding unused or missing indexes
database://connectionsConnection pool statusMonitoring connection utilization
database://replicationReplication lag and statusEnsuring replica consistency
database://vacuumVacuum and wraparound statusPreventing transaction ID exhaustion
database://locksLock contention informationDiagnosing deadlocks and blocking
database://statisticsStatistics qualityEnsuring accurate query planning

๐Ÿ’ก Key Benefit: Resources reduce token usage by providing cached context vs. repeated queries!

MCP Prompts (10) - NEW in v1.1.0! ๐ŸŽ‰

Prompts provide guided workflows for complex operations - step-by-step instructions with examples:

PromptPurposeUse Case
optimize_queryQuery optimization workflowAnalyzing and improving slow queries
index_tuningIndex analysis and recommendationsFinding unused/missing/duplicate indexes
database_health_checkComprehensive health assessmentRegular maintenance and monitoring
setup_pgvectorpgvector installation and setupImplementing semantic search
json_operationsJSONB best practicesOptimizing JSON queries and indexes
performance_baselineBaseline establishmentSetting up performance monitoring
backup_strategyBackup planning and designDesigning enterprise backup strategy
setup_postgisPostGIS installation and usageImplementing geospatial features
explain_analyze_workflowDeep plan analysisUnderstanding query execution
extension_setupExtension installation guideInstalling and configuring extensions

๐Ÿ’ก Key Benefit: Prompts guide users through complex multi-step operations with PostgreSQL best practices!

๐Ÿ“– View Complete Documentation โ†’


๐Ÿ”ง PostgreSQL Extensions

Required extensions for full functionality:

  • pg_stat_statements (built-in) - Query performance tracking
  • pg_trgm & fuzzystrmatch (built-in) - Text similarity
  • hypopg (optional) - Hypothetical index testing
  • pgvector (optional) - Vector similarity search
  • PostGIS (optional) - Geospatial operations

Quick Setup:

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;

๐Ÿ“– Extension Setup Guide โ†’


๐Ÿ†• Recent Updates

Version 1.1.0 Release ๐ŸŽ‰ (October 4, 2025)

  • ๐ŸŒŸ NEW: MCP Resources (10): Real-time database meta-awareness
    • Instant access to schema, capabilities, performance, health
    • Reduces token usage by providing cached context
    • AI can access database state without explicit queries
  • ๐ŸŒŸ NEW: MCP Prompts (10): Guided workflows for complex operations
    • Step-by-step query optimization workflow
    • Comprehensive index tuning guide
    • Complete database health assessment
    • pgvector and PostGIS setup guides
    • JSONB best practices and optimization
  • โœจ Intelligent Assistant: Transforms from tool collection to database expert
    • Proactive optimization suggestions
    • Context-aware recommendations
    • PostgreSQL-specific best practices
  • ๐Ÿ”’ Code Quality: Pyright strict mode compliance
    • Resolved 2,000+ type issues
    • 100% type-safe codebase
    • Enhanced reliability and maintainability
  • ๐Ÿ“ฆ Zero Breaking Changes: All existing tools work unchanged

Version 1.0.0 Release ๐ŸŽ‰ (October 3, 2025)

  • Production Ready: Enterprise-grade PostgreSQL MCP server
  • 63 Specialized Tools: Complete feature set across 9 categories
  • Zero Known Vulnerabilities: Comprehensive security audit passed
  • Type Safety: Pyright strict mode compliance
  • Multi-Platform: Windows, Linux, macOS (amd64, arm64)

Phase 5 Complete โœ… (October 3, 2025)

  • Backup & Recovery: 4 new tools for enterprise backup planning
  • Monitoring & Alerting: 5 new tools for real-time monitoring
  • All 63 Tools Ready: Complete Phase 5 implementation

Phase 4 Complete โœ… (October 3, 2025)

  • Vector Search: 8 tools with pgvector integration
  • Geospatial: 7 tools with PostGIS integration
  • Extension Support: pgvector v0.8.0, PostGIS v3.5.0

Phase 3 Complete โœ… (October 3, 2025)

  • Statistical Analysis: 8 advanced statistics tools
  • Performance Intelligence: 6 optimization tools

๐Ÿ“– Configuration

Claude Desktop

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "-e", "DATABASE_URI", 
               "neverinfamous/postgres-mcp:latest", "--access-mode=restricted"],
      "env": {
        "DATABASE_URI": "postgresql://user:pass@localhost:5432/db"
      }
    }
  }
}

Cursor IDE

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "postgres-mcp",
      "args": ["--access-mode=restricted"],
      "env": {
        "DATABASE_URI": "postgresql://user:pass@localhost:5432/db"
      }
    }
  }
}

๐Ÿ“– MCP Configuration Guide โ†’


๐Ÿ”ง Troubleshooting

Common Issues:

  • Connection Refused: Verify PostgreSQL is running with pg_isready
  • Extension Not Found: Install required extensions (see Extension Setup)
  • Permission Denied: Check database user permissions
  • MCP Server Not Found: Validate MCP client configuration

๐Ÿ“– Full Troubleshooting Guide โ†’


๐Ÿงช Testing

# Run all tests
uv run pytest -v

# Security tests
python security/run_security_test.py

# With coverage
uv run pytest --cov=src tests/

Test Results:

  • โœ… Security: 20/20 passed (100% protection)
  • โœ… SQL Injection: All vectors blocked
  • โœ… Integration: All operations validated
  • โœ… Type Safety: Pyright strict mode (2,000+ issues resolved)
  • โœ… Compatibility: PostgreSQL 13-18 supported

๐Ÿ† Why Choose This Server?

  • โœ… Zero Known Vulnerabilities - Comprehensive security audit passed
  • โœ… Pyright Strict Mode - 2,000+ type issues resolved, 100% type-safe codebase
  • โœ… Enterprise-Grade - Production-ready with advanced features
  • โœ… 63 Specialized Tools - Complete database operation coverage
  • โœ… 10 Intelligent Resources - Real-time database meta-awareness (NEW in v1.1.0!)
  • โœ… 10 Guided Prompts - Step-by-step workflows for complex operations (NEW in v1.1.0!)
  • โœ… AI Assistant Capabilities - Proactive optimization and recommendations
  • โœ… Real-Time Analytics - pg_stat_statements integration
  • โœ… AI-Native - Vector search, semantic operations, ML-ready
  • โœ… Active Maintenance - Regular updates and security patches
  • โœ… Comprehensive Documentation - 16-page wiki with examples

๐ŸŒŸ v1.1.0 Differentiation: Only PostgreSQL MCP server with intelligent meta-awareness and guided workflows!


๐Ÿ”— Links

GitHub Gists - Practical Examples:

  • Complete Feature Showcase - All 63 tools with comprehensive examples
  • Security Best Practices - SQL injection prevention and production security
  • Performance Intelligence - Query optimization and index tuning strategies
  • Vector/Semantic Search - pgvector integration and AI-native operations
  • Enterprise Monitoring - Real-time monitoring and alerting workflows
  • Geospatial Operations - PostGIS integration and spatial queries
  • JSON/JSONB Operations - Advanced JSONB operations and validation

๐Ÿ“ˆ Project Stats

  • Version 1.1.0 - Intelligent assistant release (October 4, 2025)
  • 63 MCP Tools across 9 categories
  • 10 MCP Resources - Database meta-awareness (NEW!)
  • 10 MCP Prompts - Guided workflows (NEW!)
  • 100% Type Safe - Pyright strict mode (2,000+ issues resolved)
  • Zero Known Vulnerabilities - Security audit passed
  • Zero Linter Errors - Clean codebase with comprehensive type checking
  • PostgreSQL 13-18 - Full compatibility
  • Multi-platform - Windows, Linux, macOS (amd64, arm64)
  • 7,500+ lines - 14 modules, comprehensive implementation

๐Ÿ“„ License & Security

  • License: MIT - see file
  • Security: Report vulnerabilities to admin@adamic.tech
  • Contributing: See

Enterprise-grade PostgreSQL MCP server with comprehensive security, real-time analytics, and AI-native operations.