pg-mcp-server
pg-mcp-server is hosted online, so all tools can be tested directly either in theInspector tabor in theOnline Client.
If you are the rightful owner of pg-mcp-server 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.
unknown
PG-MCP is a server implementation of the Model Context Protocol 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. This implementation builds upon and extends the reference Postgres MCP implementation with several key enhancements, including full server implementation, multi-database support, rich catalog information, extension context, query explanation, and robust connection management.
Features
- Connection Management: Efficient management of database connections with tools for connecting, disconnecting, and pooling.
- Query Tools: Includes tools like pg_query for executing read-only SQL queries and pg_explain for analyzing query execution plans.
- Schema Discovery Resources: Provides detailed schema information including schemas, tables, columns, constraints, and indexes.
- Data Access Resources: Allows sampling of table data with pagination and provides approximate row counts.
- Extension Context: Built-in contextual information for PostgreSQL extensions like PostGIS and pgvector.
Tools
connect
Register a database connection string and return its connection ID.
Args: connection_string: PostgreSQL connection string (required) ctx: Request context (injected by the framework)
Returns: Dictionary containing the connection ID
disconnect
Close a specific database connection and remove it from the pool.
Args: conn_id: Connection ID to disconnect (required) ctx: Request context (injected by the framework)
Returns: Dictionary indicating success status
pg_query
Execute a read-only SQL query against the PostgreSQL database.
Args: query: The SQL query to execute (must be read-only) conn_id: Connection ID previously obtained from the connect tool params: Parameters for the query (optional)
Returns: Query results as a list of dictionaries
pg_explain
Execute an EXPLAIN (FORMAT JSON) query to get PostgreSQL execution plan.
Args: query: The SQL query to analyze conn_id: Connection ID previously obtained from the connect tool params: Parameters for the query (optional)
Returns: Complete JSON-formatted execution plan
pg_metadata
Analyzes a SQL query and produces visualization metadata.
Args: conn_id: Connection ID previously obtained from the connect tool sql_query: The SQL query to analyze
Returns: JSON metadata about the query results structure