
pgmcp
io.github.pascalallenPublished by GitHub account pascalallenv1.1.0Updated Oct 24, 2026
Read-only Postgres ops/DBA diagnostics: slow queries, EXPLAIN, locks, index and table health.
Overview
Read-only PostgreSQL ops/DBA MCP server that lets an assistant diagnose slow queries, plans, locks, index and table health, connections and replication.
- What you can do
- Rank slow or expensive statements and explain why a given statement is slow, with plan tree and plan hash
- Inspect index and table health: unused, duplicate, invalid or bloated indexes, dead tuples, vacuum and analyze history
- Diagnose live problems: lock wait graphs and deadlocks, backends by state and wait event, standby lag and WAL-retaining slots
- Review server configuration against memory, autovacuum, WAL and connection heuristics with ok/review/warn verdicts
- Run one bounded read-only SELECT, EXPLAIN or SHOW with bind parameters, optionally disabled or restricted to named schemas
- Read overview and settings resources, and use a guided slow-query diagnosis prompt
- When to use it
- Useful when an assistant needs to help investigate a PostgreSQL incident or routine tuning: finding slow statements, reading execution plans, spotting blocking sessions, checking autovacuum or index bloat, or reviewing replication lag, without giving it write access.
- Requirements
- A local process (binary, .mcpb bundle for Claude Desktop, Go install, or the container image) or an HTTP deployment. Requires a PostgreSQL 13+ connection string in PGMCP_DATABASE_URL, ideally a dedicated read-only role. HTTP mode adds optional static API keys or JWT settings and should sit behind a TLS-terminating reverse proxy.
Installation
In SourceWeft
- Open pgmcp in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
pgmcp
[Go Reference] [GitHub go.mod Go version] [Go Report Card] [GitHub Workflow Status (with branch)] [GitHub] [GitHub code size in bytes]
pgmcp is a read-only PostgreSQL ops/DBA server for the Model Context Protocol, built on the official modelcontextprotocol/go-sdk. It answers the questions a DBA asks during an incident — which statements are slow, why this plan is slow, which indexes are dead weight, which tables autovacuum has fallen behind on, who is blocking whom, how far the standby is lagging — and it is read-only by construction rather than by convention: a dedicated database role that holds no write privilege, a BEGIN READ ONLY transaction with a statement timeout around every single statement, and a SQL parser guard that rejects anything that is not one SELECT/EXPLAIN/SHOW and every function that could mutate state from inside a read-only transaction. Tested against PostgreSQL 16; requires 13 or later.
Installation
Claude Desktop, one click: download pgmcp_<version>.mcpb from Releases and open it. Claude Desktop asks for a Postgres connection string, keeps it in the OS keychain, and launches the bundled binary itself — nothing on PATH, no config file to edit. One bundle covers macOS (universal) and Windows (x64).
Otherwise download a binary for your platform from Releases — darwin, linux and windows, amd64 and arm64, with checksums.
Or build from source with the Go CLI tool go:
Or run the released image, which is distroless, non-root and multi-arch:
pgmcp is listed in the MCP Registry as io.github.pascalallen/pgmcp.
Before you point it at anything, create the read-only role — see Database role. It is the layer that still holds if the other two have a bug.
Usage
One MCP surface, two transports. Which one you run is configuration, not a different build.
Claude Code, stdio — the client launches the binary and talks over stdin/stdout:
Claude Desktop, stdio — install the .mcpb bundle from Releases (see Installation), or write the same thing into claude_desktop_config.json by hand:
HTTP — Streamable HTTP behind a static bearer key, for a shared deployment. pgmcp speaks plain HTTP and never terminates TLS itself; run it on loopback behind a reverse proxy.
TLS termination, the proxy settings the streaming transport needs, JWT auth against an identity provider, and wiring pgmcp up as a claude.ai custom connector are all in docs/DEPLOYING.md.
Tools
Every tool is annotated readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, and returns a typed output schema.
query is the only tool that carries free-form SQL, and it is optional. --disable-query drops it from the catalogue entirely — a deployment that only needs the eight diagnostics tools can run without any ad hoc SQL surface at all. --query-schemas=public,app restricts it to named schemas instead — and bounds explain with it, since analyze=true executes the statement; read what that does and does not stop in docs/SECURITY.md.
Resources & prompt
Configuration
Every setting has a --flag and a PGMCP_<KEY> environment variable. Flags win over the environment, which wins over the default. Configuration errors exit 2 with every offending key named in one message; runtime failures exit 1.
The auth block applies to the HTTP transport only. Over stdio the operating system decides who the caller is: the parent process that launched the binary, and nobody else.
Security model
- Read-only three independent ways. A dedicated role with no write privilege (
pg_monitorplusSELECT, and deliberately notpg_signal_backend);BEGIN READ ONLYwithSET LOCAL statement_timeoutandlock_timeout = '2s'around every statement the adapter runs, always rolled back; and a parser-level guard, because a read-only transaction alone does not stoppg_terminate_backend,pg_read_file,pg_sleeporsetval. - The SQL guard is allow-list first. One top-level statement, and it must be a
SELECT,EXPLAINorSHOW; no nested write statement anywhere in the tree; noFOR UPDATE/FOR SHARElocking clause; noSELECT INTO; and no call to a denied function — file access, backup and WAL control, replication slots, advisory locks,dblink, sequence mutation, stats resets. - The schema allowlist is a guardrail, not a boundary.
--query-schemasmatches the schemas qualifying table references in the parsed statement, case-insensitively, and it bounds both tools that carry caller-supplied SQL —queryandexplain, soexplainwithanalyze=truecannot execute against a schema you excluded. A view, a set-returning function, or aSECURITY DEFINERfunction inside an allowed schema can still read outside it. Database privileges are the boundary; the allowlist just narrows the obvious path. - Authenticated, fail-closed, over HTTP. Static keys are compared in constant time against every stored hash without an early exit; JWTs are validated against a JWK set with asymmetric algorithms only (no
alg=none, no HMAC confusion) and a requirediss,audandexp, and the verifier holds no keys until the JWKS arrives, so it starts closed rather than open. RFC 9728 protected resource metadata advertises where to get a token. The server refuses to start on a non-loopback address with auth off. - Bounded. Per-principal rate limiting, a per-call timeout, a statement timeout and lock timeout inside the transaction, a row cap on the
querytool, a cap on a result's structured content, and a 1 MiB request body limit. - Nothing sensitive is logged. A tool call logs its name, duration, outcome and the caller's user id — never arguments, SQL text, result rows or error text. Parse failures come back as a fixed phrase rather than echoing the statement, and the DSN is redacted from connection errors.
The threat model, the full enumeration of the layers, and the limitations each one does not cover are in docs/SECURITY.md.
Testing
Run the test suite with the race detector and coverage:
Integration tests need a Postgres database and are skipped when PGMCP_TEST_DSN is unset. To run them against a scratch Postgres with pg_stat_statements preloaded:
Create and view a coverage profile:
Drive a running server through the official MCP conformance suite, or smoke it with the Inspector:
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Source: README.md at commit 09953f9
Tools
0Version history
1- v1.1.0LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts