# mcpg

MCP server with 254 PostgreSQL tools for queries, performance tuning, and ops. Read-only by default.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 14
- Author: devopam
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/devopam/MCPg
- Updated: 2026-10-19
- HTML: https://affpapa.org/en/nevibecode/mcp/mcpg

## What it 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.

## Requirements
- Needs: Python and uv (commands run via uvx)

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add mcpg -- uvx mcpg
```
uvx runs the command named after the package; if the README names another one, use uvx --from mcpg <command>

### Codex

**Platform CLI**
```bash
codex mcp add mcpg -- uvx mcpg
```
uvx runs the command named after the package; if the README names another one, use uvx --from mcpg <command>

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "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>

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "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>

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add mcpg uvx mcpg
```
uvx runs the command named after the package; if the README names another one, use uvx --from mcpg <command>

## When to use it
- 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
- Connect the `mcpg` server and show the schema for the `orders` table
- Use `mcpg` to build a SQL query: last 50 orders this month
- Run `EXPLAIN ANALYZE` on the query in `slow_query.sql` via `mcpg`

## Similar
- [World Monitor](https://affpapa.org/en/nevibecode/mcp/world-monitor.md) — MCP server · ★ 89408
- [Scrapling MCP Server](https://affpapa.org/en/nevibecode/mcp/scrapling-mcp-server.md) — MCP server · ★ 89433
- [MCP Toolbox for Databases](https://affpapa.org/en/nevibecode/mcp/googleapis-mcp-toolbox-for-databases.md) — MCP server · ★ 16717
- [PostHog MCP Server](https://affpapa.org/en/nevibecode/mcp/posthog-mcp-server.md) — MCP server · ★ 40409
- [dbx](https://affpapa.org/en/nevibecode/mcp/dbx.md) — MCP server · ★ 27669
- [Metabase](https://affpapa.org/en/nevibecode/mcp/metabase.md) — MCP server · ★ 49845

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
