MCPg
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
**A production-grade Model Context Protocol
server for PostgreSQL.** It lets AI agents safely inspect, query, operate, and
tune a Postgres database — 279 tools spanning catalog introspection,
query intelligence, natural-language SQL, structural diffs, hybrid search,
graph queries, data movement, live ops, and more.
> **Try it live:** point an MCP client — or the MCP Inspector — at the hosted, read-only demo endpoint https://devopam-mcpg-demo.hf.space/mcp. It serves read tools against throwaway demo data; for real use, run MCPg next to your own database (see Quick start).
📍 Listed On
- **Official MCP Registry**
- **mcp.so**
- **mcpservers.org**
- **Smithery**
- **Glama**
- **MCP ServerList**
---
| Aspect | MCPg |
|---------------------|-----------------------------------|
| Safety | Read-only default + AST validation |
| Transport | stdio + HTTP/SSE |
| Install | pip install mcpg |
| Postgres Versions | 14–19 |
| Key Differentiator | Production observability + multi-tenancy |
Why MCPg
- **Safe by default.** Read-only access mode. Every user-supplied SQL
statement parses through a validated AST allowlist before execution.
Names that reach PostgreSQL as SQL identifiers are encoded with
delimited-identifier quoting (see Identifier policy),
not rejected merely for containing hyphens or other legal characters.
Capabilities like DDL, shell, and LISTEN/NOTIFY are off until you
opt in. Every tool publishes MCP ToolAnnotations (readOnlyHint,
openWorldHint) derived from those same gates, so clients can
auto-approve reads and gate writes without guessing.
- **One server, broad surface.** Application data access (queries, search,
cursors, NL→SQL) *and* DBA-grade operations (health checks, index tuning,
EXPLAIN analysis, locks, vacuum, dumps, replicas, migrations) in a
single MCP server. Agents don't have to switch tools to switch tasks.
- **PostgreSQL-native everything.** No ORM, no abstraction tax — uses
psycopg3 directly, speaks every pg_* system view, integrates with
TimescaleDB, pgvector, PostGIS, Apache AGE, and pg_stat_statements
where they're available, and degrades gracefully when they aren't.
- **Production-shaped, not demo-shaped.** Connection pooling, per-request
SET ROLE multi-tenancy, read-replica routing with degraded-host
detection, server-side cursors with dedicated connections,
rate-limiting, audit trail with regex redaction, PG TLS enforcement
on startup, OIDC JWT bearer auth, per-session statement / lock
timeouts.
- **Observability built in.** Prometheus /metrics endpoint on the
HTTP transport surfaces mcpg_tool_calls_total{tool,status} +
mcpg_tool_duration_seconds. Every tool call records a structured
audit event with credential-redacted arguments.
- **Test-driven, multi-version.** 2,500+ unit tests plus an integration
suite that runs against a real PostgreSQL container in CI — matrix
covers PG **14, 15, 16, 17, 18** on every push, plus PG **19 (beta)**
as an experimental (non-blocking) entry tracked under issue #120.
---
Install
From PyPI (recommended)
Verify:
Docker
Pull the pre-built image from the GitHub Container Registry (published
on every tagged release — :latest tracks the newest, or pin a version
like :0.6.5):
On **Windows PowerShell** replace the trailing \ with a backtick
(or put the command on one line); the installation
guide has ready-to-copy
Linux/macOS, PowerShell, and Command Prompt blocks.
Or build it yourself from source:
Multi-stage image: runtime stage drops the build toolchain, runs as
uid=10001 / gid=10001 with nologin shell, application files
root-owned and read-only to the runtime user.
From source (developers)
uv sync creates a venv with all runtime + dev dependencies and exposes
the mcpg console script.
More detail in the Installation Guide.
---
Quick start
**One-click installs:**
— setup for Windsurf, JetBrains, Zed, Cline, Antigravity, Qwen Code, Perplexity,
ChatGPT, Copilot Studio, Continue, and HTTP
clients in the integrations guide.
One-click install in Claude Desktop (.mcpb)
Download mcpg- .mcpb from the
latest release and
double-click it (or drag it into Claude Desktop's Settings →
Extensions). You'll be prompted for your PostgreSQL connection URL —
stored in the OS keychain — and an access mode (defaults to
read-only). That's the whole install: the bundle is ~2 kB and the
host resolves the pinned mcpg release from PyPI for your platform.
Or wire it up manually (stdio transport)
Drop this into your claude_desktop_config.json (macOS:
~/Library/Application Support/Claude/claude_desktop_config.json;