mcpg — Claude Code MCP server: PostgreSQL tools and install
MCP server with 254 PostgreSQL tools for queries, performance tuning, and ops. Read-only by default.
claude mcp add mcpg -- uvx mcpgWhat mcpg does
The server connects an agent to a PostgreSQL database through 254 tools. Built on psycopg3, it supports TimescaleDB, pgvector, PostGIS, Apache AGE, and pg_stat_statements when present in your database. Tools cover catalog introspection, natural-language SQL, hybrid search, graph queries, performance analysis, and migrations. Read-only mode is on by default; every SQL statement passes AST validation.
Install via pip install mcpg or uvx mcpg. For Docker, pull ghcr.io/devopam/mcpg:latest. The server runs over stdio and HTTP/SSE; HTTP mode exposes /metrics for Prometheus. Supports PostgreSQL 14–19 (beta), connection pooling, read-replica routing, multi-tenant mode via SET ROLE, and audit logs with credential redaction.
You need a PostgreSQL database and the MCPG_DATABASE_URL environment variable with the connection string. Without psycopg3 in the Python environment, pip won't start the server.
What it helps with
- write a SQL query from a natural-language description
- check index load and find bottlenecks via EXPLAIN
- get the schema of a table or the entire database catalog
- run hybrid search or graph queries on your data
- track locks, active queries, and replica health
Example prompts for the agent
- Connect the
mcpgserver and show the schema for theorderstable - Use
mcpgto build a SQL query: last 50 orders this month - Run
EXPLAIN ANALYZEon the query inslow_query.sqlviamcpg
How to install mcpg
Platform CLI
claude mcp add mcpg -- uvx mcpguvx runs the command named after the package; if the README names another one, use uvx --from mcpg <command>
Platform CLI
codex mcp add mcpg -- uvx mcpguvx runs the command named after the package; if the README names another one, use uvx --from mcpg <command>
Config file
{
"mcpServers": {
"mcpg": {
"command": "uvx",
"args": [
"mcpg"
]
}
}
}uvx runs the command named after the package; if the README names another one, use uvx --from mcpg <command>
Config file
{
"servers": {
"mcpg": {
"type": "stdio",
"command": "uvx",
"args": [
"mcpg"
]
}
}
}uvx runs the command named after the package; if the README names another one, use uvx --from mcpg <command>
Platform CLI
gemini mcp add mcpg uvx mcpguvx runs the command named after the package; if the README names another one, use uvx --from mcpg <command>
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about mcpg
How to install mcpg in Claude Code?
Run claude mcp add mcpg -- uvx mcpg in your terminal. Claude Code will add the server to config and start it via uvx.
What does mcpg do?
Connects an agent to PostgreSQL through 254 tools for queries, introspection, performance tuning, and operations. Read-only by default, every SQL statement is validated through AST.
Which PostgreSQL versions does mcpg support?
PostgreSQL 14, 15, 16, 17, 18 are tested in CI. Version 19 (beta) works experimentally.