pg-mcp
open sourceMCP server for PostgreSQL enabling LLMs and agents to inspect schemas and execute queries safely
Updated 2026-03-17
pg-mcp is a Model Context Protocol (MCP) server that bridges PostgreSQL databases and AI agents. It provides structured schema introspection, controlled query execution, and optimization tools via HTTP/SSE, making it ideal for solo builders deploying multi-tenant AI applications that need stateful database access.
Use Cases
- ·Autonomous AI agents that need to query production databases without direct SQL access
- ·Multi-tenant SaaS applications where agents operate on behalf of different database connections
- ·Building data-driven agents that optimize queries before execution using EXPLAIN
- ·Integrating pgvector or PostGIS extensions into agent workflows for semantic search or geospatial queries
- ·Solo founders deploying lean AI applications with persistent state across agent invocations
Key Points
- ·HTTP/SSE-based MCP server (not stdio) allows deployment on cloud platforms without subprocess constraints
- ·Multi-tenant architecture: supports multiple database connections and concurrent agents from a single server instance
- ·Built-in schema introspection with pg_catalog enrichment captures table structures, types, indexes, constraints, and documentation
- ·Read-only query execution with EXPLAIN tool helps agents understand performance implications before costly operations
- ·Extension plugin system (YAML-configured) provides native support for pgvector and postgis, extensible for other Postgres extensions
- ·Container-ready: spin up and agents connect immediately at http://localhost:8000/sse
Tags
mcppostgresdatabaseagent-toolshttp-sseschema-introspection
Do-Nothing Score
Find out how close you are to Ghost CEO.
Machine-Readable
This tool is available as structured JSON via the API.
GET /api/v1/tools/pg-mcp-postgres-model-context-protocol