MCP server for AI agent PostgreSQL database interaction
Top 63.5% on sourcepulse
This project provides a PostgreSQL Model Context Protocol (PG-MCP) server, designed for AI agents to interact with PostgreSQL databases. It offers enhanced capabilities over the reference implementation, enabling AI agents to discover, connect, query, and understand database schemas and extensions, with a focus on read-only operations for safety.
How It Works
PG-MCP is built on the Model Context Protocol (MCP) and leverages FastMCP for its Python implementation. It uses asyncpg
for asynchronous PostgreSQL interaction and Server-Sent Events (SSE) for transport. The server exposes database resources like schemas, tables, and columns, and includes contextual information for extensions such as PostGIS and pgvector via YAML configuration. It also features a tool for analyzing query execution plans.
Quick Start & Requirements
docker-compose up -d
) or manually install dependencies (uv sync
), activate a virtual environment, and run the server (python -m server.app
).test.py
) and an example client (claude_cli.py
) for natural language to SQL conversion, requiring ANTHROPIC_API_KEY
and DATABASE_URL
environment variables.Highlighted Details
pg_explain
tool for analyzing query execution plans.Maintenance & Community
The project is maintained by stuzero. Contributions are welcome, with suggested areas for expansion including more extension contexts and schema introspection resources.
Licensing & Compatibility
The repository does not explicitly state a license in the provided README. Users should verify licensing for commercial or closed-source integration.
Limitations & Caveats
The server runs in read-only mode by default, enforced via transaction settings. While it aims for robust connection management, users should be aware of the security implications of exposing database credentials during the initial connection setup.
2 months ago
Inactive