PostgreSQL Model Context Protocol (PG-MCP) Server
by stuzero
PG-MCP is a server implementation of the Model Context Protocol for PostgreSQL databases, providing a comprehensive API for AI agents. It enhances the reference implementation with features like multi-database support, rich catalog information, and extension context.
Last updated: N/A
What is PostgreSQL Model Context Protocol (PG-MCP) Server?
PG-MCP is a server implementation of the Model Context Protocol (MCP) for PostgreSQL databases. It provides a comprehensive API for AI agents to discover, connect to, query, and understand PostgreSQL databases through MCP's resource-oriented architecture.
How to use PostgreSQL Model Context Protocol (PG-MCP) Server?
To use PG-MCP, you can either use Docker or manual installation. After installation, you can connect to the server using a connection string and interact with it using the provided tools like pg_query
and pg_explain
. The server exposes schema resources via pgmcp://{conn_id}/schemas
and related endpoints, allowing AI agents to explore the database structure.
Key features of PostgreSQL Model Context Protocol (PG-MCP) Server
Full Server Implementation with SSE transport
Multi-database Support
Rich Catalog Information (table/column descriptions)
Extension Context (PostGIS, pgvector)
Query Explanation (execution plan analysis)
Robust Connection Management (connection pooling, secure connection IDs)
Use cases of PostgreSQL Model Context Protocol (PG-MCP) Server
Enabling AI agents to understand and interact with PostgreSQL databases
Providing a standardized interface for querying and exploring database schemas
Facilitating natural language to SQL conversion
Analyzing query execution plans for optimization
FAQ from PostgreSQL Model Context Protocol (PG-MCP) Server
What is MCP?
What is MCP?
MCP stands for Model Context Protocol, a standard for providing context about data models to AI agents.
What PostgreSQL versions are supported?
What PostgreSQL versions are supported?
The README doesn't specify particular versions, but it requires Python 3.13+ and PostgreSQL databases, implying support for recent versions.
How do I add context for other PostgreSQL extensions?
How do I add context for other PostgreSQL extensions?
Additional extensions can be added via YAML config files.
Is the server read-only?
Is the server read-only?
The server runs in read-only mode by default, enforced via transaction settings.
How secure are the database connections?
How secure are the database connections?
Connection details are never exposed in resource URLs, only opaque connection IDs are used. Database credentials only need to be sent once during the initial connection.