pgbrake
Provides a safety and undo layer for PostgreSQL databases used by AI agents: parses SQL, holds risky writes for human approval, logs all statements and decisions, and supports one-command undo of row changes made through the server.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
pgbrake
An undo button for your database when an AI agent is driving.
pgbrake is a local MCP server that sits between Claude Code / Codex / Cursor and your Postgres. Every write the agent makes gets a change id you can reverse with one command. Risky SQL waits for a human. Everything is logged. Nothing leaves your machine.

agent> DELETE FROM users WHERE created_at < '2025-01-01'
pgbrake> held: DELETE would touch 4,812 rows (limit 100) — approval apv_3f9c21aa
agent> DELETE FROM users WHERE id = 42
pgbrake> 1 row affected; undo with change id chg_8e01b7d2
you$ pgbrake undo chg_8e01b7d2
undid delete on "users": 1 row(s) restoredWhy
Claude Code checkpoints rewind files, not databases. Client-side permission prompts and hooks can be skipped or misfire for MCP calls, and a tool's own "destructive" label is just a hint. pgbrake enforces its rules inside the server, so they hold no matter which agent or client calls it.
Related MCP server: mcp-enterprise-starter
What it does (free, MIT)
Real SQL parsing (the Postgres parser via pglast), not regex.
Held for approval: DDL (
DROP,ALTER,TRUNCATE...),UPDATE/DELETEwithoutWHERE, any write over the row limit (default 100), upserts andMERGE.Never allowed:
ALTER SYSTEM, role/database creation and drops,COPY ... PROGRAM,DOblocks.One-command undo: before each
UPDATE/DELETE, the affected rows are saved locally; inserts are tracked by primary key. Undo refuses if the rows changed since, unless you--force.Approval only by a human: in the client's own prompt (MCP elicitation) or
pgbrake approve <id>in an interactive terminal. Approvals are one-shot, expire in 15 minutes, and are bound to the exact SQL.Audit log of every statement, decision and row count, in
~/.pgbrake/journal.db.Multi-statement calls run in one transaction: all or nothing.
Install
pip install pgbrake # or: uvx pgbrake serveClaude Code:
claude mcp add pgbrake --env PGBRAKE_DSN="postgresql://me@localhost/app" -- uvx pgbrake serveCodex (~/.codex/config.toml):
[mcp_servers.pgbrake]
command = "uvx"
args = ["pgbrake", "serve"]
env = { PGBRAKE_DSN = "postgresql://me@localhost/app" }Then remove any other database MCP / psql access from the agent, so pgbrake is the only way in.
In Claude Code, add "Bash(psql:*)" and "Bash(pgbrake approve:*)" to permissions.deny.
Commands
pgbrake pending # SQL waiting for you
pgbrake approve <id> # approve (interactive terminal only)
pgbrake deny <id>
pgbrake changes # undoable changes
pgbrake undo <change-id> # reverse one
pgbrake log # audit logSettings (env)
Variable | Default | |
| — | connection string (falls back to |
| 100 | writes touching more rows need approval |
| 0 | set 1 to let schema changes through (still logged) |
| 0 | set 1 to refuse every write |
| 15000 | |
|
|
Limits
Undo covers rows changed through pgbrake. It is not a backup: keep real backups.
TRUNCATE, DDL, upserts andMERGEare held for approval but cannot be undone.Updating a table with no primary key needs approval and cannot be undone.
The free version keeps the last 20 undoable changes.
Pro
$29 one-time for the first 100 licenses (then $39). No subscription. 14-day refund. Buy pgbrake Pro
Migration guard for agent terminal commands. A Claude Code
PreToolUsehook catchesprisma migrate reset --force,drizzle-kit push --force,alembic downgrade baseand friends, takes apg_dumpsnapshot first (whenPGBRAKE_DSNis set), checkspg_restorecan read it, then asks you. If the snapshot fails, the command is blocked instead (override withPGBRAKE_ALLOW_NO_SNAPSHOT=1). SetPGBRAKE_VERIFY_RESTORE=1to also restore the snapshot into a throwaway database and compare table counts before you're asked; if that restore fails, the command is blocked. The drill needs CREATEDB rights (orPGBRAKE_DRILL_DSNpointing at a server where it has them) and takes about as long as a restore. Install withpgbrake install-hook.Unlimited undo history (free keeps the last 20).
Audit export:
pgbrake log --export csv|json.
After paying you land on a page that shows your key. Activate it once:
pgbrake license <your-key> # or set PGBRAKE_LICENSEKeys are verified offline; pgbrake never phones home.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Related MCP Connectors
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Guard AI agents' PostgreSQL/MySQL access via MCP: SQL audit, auth, masking, write approval
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP server that gives an AI agent scoped, safe access to your Postgres databases with per-connection access control, row caps, timeouts, and defense-in-depth read-only enforcement.-
- AlicenseAqualityDmaintenanceA production-grade MCP server that gives AI agents safe, authenticated access to a PostgreSQL database.3MIT
- AlicenseAqualityDmaintenanceAn MCP server that enables AI agents to securely interact with PostgreSQL databases with least-privilege scopes, PII masking, and human approval for writes.4MIT
- AlicenseAqualityDmaintenanceA Postgres MCP server that enables AI agents to safely access production databases through deny-by-default YAML policies, PII masking, row limits, and required predicates. It also provides DBA capabilities like index tuning, health checks, and EXPLAIN plans, with support for multiple databases.10MIT