postgres-mcp  by crystaldba

MCP server for AI agents, enabling configurable read/write access and performance analysis

created 4 months ago
814 stars

Top 44.4% on sourcepulse

GitHubView on GitHub
Project Summary

Postgres MCP Pro is an open-source Model Context Protocol (MCP) server designed to assist developers and AI agents with PostgreSQL database management, performance analysis, and safe SQL execution. It offers features like database health checks, index tuning, query plan analysis, and schema intelligence, aiming to improve development workflows from coding to production tuning.

How It Works

Postgres MCP Pro leverages the MCP standard, exposing database functionality through tools rather than resources. It integrates with PostgreSQL extensions like pg_statements for query statistics and hypopg for simulating index impacts. For index tuning, it employs a greedy search strategy, similar to Microsoft's Anytime Algorithm, to find optimal index configurations by estimating performance gains and storage costs. Database health checks are adapted from PgHero, covering aspects like buffer cache hit rates, connection health, and vacuum status.

Quick Start & Requirements

  • Installation:
    • Docker: docker pull crystaldba/postgres-mcp
    • Python (with uv): uv pip install postgres-mcp
  • Prerequisites: PostgreSQL database access credentials, Docker or Python 3.12+.
  • Configuration: Requires editing client configuration files (e.g., Claude Desktop) with database URI and access mode (unrestricted or restricted).
  • Optional Extensions: pg_statements and hypopg for advanced features.
  • Docs: Overview, Demo, Quick Start

Highlighted Details

  • Index Tuning: Implements a sophisticated, greedy search strategy for index optimization, aiming for better solutions than simpler heuristics at the cost of longer runtime.
  • Protected SQL Execution: Offers restricted mode with read-only transactions and query execution time limits for safer production use.
  • Database Health Checks: Integrates checks from PgHero for index health, buffer cache, connections, vacuum, replication, constraints, and sequences.
  • Experimental LLM Index Tuning: Features an experimental mode using LLMs to propose index configurations, iterating based on performance predictions.

Maintenance & Community

Licensing & Compatibility

  • License: MIT License.
  • Compatibility: Suitable for commercial use and integration with closed-source applications.

Limitations & Caveats

  • Experimental LLM index tuning requires an OpenAI API key.
  • Protected SQL execution relies on pglast parsing and may be circumvented if unsafe stored procedure languages are enabled.
  • Testing currently focuses on PostgreSQL 15-17, with plans to support 13-17.
Health Check
Last commit

2 months ago

Responsiveness

Inactive

Pull Requests (30d)
3
Issues (30d)
6
Star History
663 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Omar Sanseviero Omar Sanseviero(DevRel at Google DeepMind), and
3 more.

postgresml by postgresml

0.3%
6k
Postgres extension for in-database ML/AI
created 3 years ago
updated 1 month ago
Feedback? Help us improve.