mcp_server_postgres
The PostgreSQL Model Context Protocol (PG-MCP) Server is designed to provide a comprehensive API for AI agents to interact with PostgreSQL databases. It enhances database management with robust connection handling, schema discovery, and query analysis tools while incorporating support for PostgreSQL extensions.
PostgreSQL Model Context Protocol (PG-MCP) Server
Overview
PG-MCP is a server implementation of the Model Context Protocol for PostgreSQL databases. It provides AI agents with an API to discover, connect to, query, and understand PostgreSQL databases. The server extends a reference Postgres MCP implementation with several enhancements:
- Full server implementation with SSE transport
- Supports multiple database connections
- Exposes rich catalog information
- Provides detailed context for PostgreSQL extensions
- Includes tools for analyzing query execution plans
Features
- Connection Management: Secure connection IDs, connection pooling, and tool support for connecting and disconnecting databases.
- Query Tools: Execute read-only SQL queries and analyze execution plans.
- Schema Discovery: Explore schemas, tables, columns, constraints, and indexes.
- Data Access: Sample data with pagination and approximate row counts.
- Extension Context: Built-in knowledge for extensions like PostGIS and pgvector.
Installation
Requires Python 3.13+ and PostgreSQL. Can be installed via Docker or manually.
Usage
Includes test scripts for functionality verification and provides example prompts for AI agents.
Architecture
Built on Model Context Protocol, FastMCP, asyncpg, and YAML.
Security Considerations
- Read-only mode by default
- Connection details are secured
- Credentials only sent once during initial connection
Contributing
Contributions are welcome in adding new extensions, schema resources, and optimization suggestions.