# devopam/MCPg [Verified owner] [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/devopam/MCPg  
**GitHub Stars:** 14  
**Views:** 24  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/devopam-mcpg

## Description
Production-grade PostgreSQL MCP server with 100+ tools for catalog introspection, AST-validated safe query execution, index tuning, natural-language SQL, pgvector/TimescaleDB/AGE integrations, and HTTP/stdio transports.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "mcpg": {
    "command": "uvx",
    "args": ["mcpg"],
    "env": {
      "MCPG_DATABASE_URL": ""
    }
  }
}
```

**Requires environment variables:** `MCPG_DATABASE_URL` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What devopam/MCPg MCP server does

devopam/MCPg exposes PostgreSQL through the Model Context Protocol. Its 279 tools cover catalog introspection, SQL execution, natural-language-to-SQL workflows, structural comparisons, hybrid search, graph queries, data movement, health checks, index analysis, EXPLAIN inspection, locks, vacuum operations, dumps, replicas, and migrations.

The server is designed for both database consumers and operators. It uses psycopg3 rather than an ORM and can work with PostgreSQL-native system views. Where available, it can use pgvector, TimescaleDB, PostGIS, Apache AGE, and pg_stat_statements; unsupported extensions are handled through graceful degradation.

## How it works

MCPg can communicate over stdio or HTTP/SSE. The hosted demo endpoint at `https://devopam-mcpg-demo.hf.space/mcp` exposes read tools against throwaway data; production deployments should run the server alongside the target database.

Read-only access is the default. User-provided SQL is parsed and checked against an AST allowlist before execution, while capabilities such as DDL, shell access, and `LISTEN/NOTIFY` require explicit enablement. MCP tool annotations expose read-only and open-world hints based on these gates, allowing clients to distinguish operations that can be approved automatically from those requiring review.

Production-oriented controls include connection pooling, per-request `SET ROLE` handling, read-replica routing with degraded-host detection, dedicated connections for server-side cursors, rate limiting, statement and lock timeouts, audit records with credential redaction, and PostgreSQL TLS enforcement at startup. HTTP deployments also expose Prometheus metrics for tool-call counts and durations.

## Setup and configuration

Install the Python package from PyPI with `pip install mcpg`, or use `uv tool install mcpg`. Source development uses `uv sync`. A container image is available at `ghcr.io/devopam/mcpg:latest`, and the image accepts the database connection through `MCPG_DATABASE_URL`.

A stdio client configuration runs `uvx mcpg` and passes `MCPG_DATABASE_URL`, for example:

```json
{
  "mcpServers": {
    "mcpg": {
      "command": "uvx",
      "args": ["mcpg"],
      "env": {
        "MCPG_DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
      }
    }
  }
}
```

Claude Desktop users can install the `.mcpb` bundle from the latest GitHub release. The bundle prompts for the PostgreSQL URL and access mode, storing the URL in the operating system keychain. The default access mode remains read-only.

## Tools and capabilities

- Inspect PostgreSQL catalogs and system views.
- Execute AST-validated SQL and generate SQL from natural-language requests.
- Analyze queries, indexes, locks, vacuum activity, health, and replicas.
- Work with vector, time-series, spatial, and graph data when the relevant extensions are available.
- Compare database structures and support dumps, migrations, cursors, and data movement.
- Expose tool-call metrics and structured audit events over production deployments.

## Limitations and notes

Write-oriented features are gated rather than enabled by default. Extension-specific operations depend on the corresponding PostgreSQL extension being available. The live demo is read-only and uses disposable data, so it is suitable for trying the MCP interface rather than accessing an application database. PostgreSQL compatibility is listed for versions 14 through 19, with PostgreSQL 19 identified as experimental in the project’s test matrix.

_Full upstream README: https://allmcps.com/mcp/devopam-mcpg/readme_

