Safe, audited PostgreSQL operations for AI agents: queries, migrations, EXPLAIN, containers
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
Let an AI assistant operate your PostgreSQL database β without letting it wreck anything.
Point Claude, Cursor, or VS Code at a database and ask questions in plain English. Your assistant gets 18 tools for inspecting schemas, running queries, diagnosing slow ones, and planning migrations. What it does not get is a way to quietly destroy your data.
Every number below is real output from the demo database in this repo β 1.2M rows, 114 MB.
You: I want to index
orders.status
Assistant: (calls
migration.plan)
Assistant: A plain index build blocks writes for roughly 4 seconds.
CONCURRENTLYis slower overall but keeps writes working. Which do you want?
The tool didn't return a raw plan for the model to interpret β it returned a verdict, a duration estimate with an honest confidence level, and the safer alternative.
query.explain works the same way. Instead of handing back JSON, it says things like:
You: clear out the orders table
Assistant: (calls
query.writewithDELETE FROM orders)
Where your client supports it, the approval prompt goes to you β not to the assistant. Nothing runs until a human answers, and the refusal is written to the audit log whether or not you approve.
That last part is the point. The assistant cannot approve its own dangerous action, because it is not the one being asked. Where a client can't show a prompt, it degrades to a single-use token bound to that exact statement β never to "allowed".
Most Postgres MCP servers are thin query wrappers: introspect and SELECT. None handle
migrations with lock-impact analysis, none diagnose performance from EXPLAIN and
pg_stat_statements, and none understand the container the database runs in. Agents
operating databases today are doing it blind, and without guardrails.
pgops-mcp is the operations brain: schema intelligence β guarded queries β migration
engine β performance diagnosis β environment awareness, with a safety architecture that
makes every action classifiable, confirmable, and auditable.
Native AI/ML Extension Support: Because pgops builds on core Postgres catalogs rather than brittle regex parsing, it inherits native support for custom types and extensions like pgvector. Tools like migration.plan and query.explain understand vector types (vector(384)) and hnsw indexes out of the box, with zero configuration.
New here? docs/GETTING_STARTED.md is a 15-minute guided tour that assumes no MCP knowledge.
| Group | Tools |
|---|---|
| Schema | schema.inspect |
| Queries | query.read, query.write (guarded), query.explain (parsed plan + verdict) |
| Performance | index.advise, db.health |
| Migrations | migration.plan (dry-run + lock analysis), migration.describe (plain English), migration.apply, migration.rollback, migration.history |
| Environment | env.topology, env.correlate, container.logs, container.stats |
| Gated | container.restart, container.exec |
* Not registered at all unless the server runs with --approval-mode, and even then
each call needs a confirmation token. container.exec additionally enforces a read-only
diagnostic command allowlist β it does not offer a shell. The Docker socket is
root-equivalent on the host, so the default is read-only access.
DELETE/UPDATE blocked| Primitive | What's here |
|---|---|
| Tools | 17 β schema, query, explain, advise, migrate, environment |
| Resources | pgops://schema, schema/summary, schema/{table}, health, migrations, audit/recent, config |
| Prompts | diagnose-slow-query, plan-safe-migration, incident-triage, review-index-health, explain-safety-model |
| Elicitation | Dangerous actions ask the user directly, not via the agent; confirmation tokens are the fallback |
| Sampling | migration.describe turns English into a plan using your model β this server ships no API key |
| Completions | Table-name autocomplete for pgops://schema/{table} |
| Progress / logging | Best-effort notifications during long operations |
stdio needs no auth β the server is a subprocess your client spawns, with no open port. HTTP does, so it refuses to start without a key:
The server holds only the public key, so it can verify tokens but never mint them.
Scopes (pgops:read / pgops:write / pgops:admin) map to the same danger tiers as the
guardrails, and a tool with no scope entry requires admin β deny by default. Binds
loopback unless you say otherwise.
pgops-mcp is an MCP server, not a Python library β nothing in it is meant to be
imported, and pgops.* carries no API-stability promise. You install it the way you
install any MCP server: point your client at it.
Claude Desktop / Cursor / VS Code:
uvx fetches and runs it in a throwaway environment β nothing to install first, and
nothing added to your own project's dependencies.
Or run the container, if you would rather not put a Python toolchain on the machine that talks to your database:
Two things the container changes: mount a volume at /var/lib/pgops or the audit log
dies with the container, and localhost inside a container is the container itself β
use host.docker.internal or a compose service name.
Check the connection before wiring a client to it:
Both paths install the same server and are listed together in the
MCP Registry entry β they fail for different
people. uvx needs nothing preinstalled but assumes the host may run Python; the
container assumes only Docker.
See SETUP.md for configuration, HTTP transport, agent tokens and troubleshooting, and CONTRIBUTING.md to run it from a source checkout.
Links are absolute so they resolve from the PyPI project page as well as from GitHub.
Using it
| Doc | What's in it |
|---|---|
| Getting started | First 15 minutes, no MCP knowledge assumed |
| Tool reference | All 18 tools: parameters, returns, error codes, scopes |
| Setup & configuration | Clients, HTTP auth, observability, troubleshooting |
| Environment variables | Every knob, documented |
| Security model | What it can do, what it refuses, known limits |
| Changelog | What changed per release |
How it works
| Doc | What's in it |
|---|---|
| Architecture | System design and trade-offs |
| System design | The safety pipeline, with diagrams |
| Decision records | Why each choice was made, and what it cost |
| Benchmarks | What is measured, and against what |
Contributing
| Doc | What's in it |
|---|---|
| Contributing | Source checkout, gates, release process |
| Module layout | What each module is for |
No reviews yet β be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/pgops)<a href="https://allmcps.com/mcp/pgops"><img src="https://allmcps.com/api/badge/pgops?style=directory" alt="Pgops on AllMCPs" /></a>