
pgbrake
io.github.lexangPublished by GitHub account lexangv0.3.0Updated Nov 7, 2026
Postgres brake for AI agents: risky SQL waits for approval, UPDATE/DELETE get one-command undo.
Overview
A local MCP server that puts a guard between an AI agent and Postgres: risky SQL waits for human approval and writes get one-command undo.
- What you can do
- Run SQL against Postgres through the agent, with statements parsed by the real Postgres parser
- Hold risky writes for human approval: DDL, UPDATE/DELETE without WHERE, writes over the row limit, upserts and MERGE
- Refuse outright dangerous statements such as ALTER SYSTEM, role or database creation and drops, COPY PROGRAM and DO blocks
- Undo a single UPDATE or DELETE by change id, with a refusal if the rows changed since
- Review pending approvals, undoable changes and a full audit log from the command line
- When to use it
- Use it when you let an AI coding agent write to a real Postgres database and want a safety net: approval for destructive statements, reversible writes and an audit trail, enforced inside the server rather than by client-side prompts.
- Requirements
- A local Python install (pip or uvx) running as a stdio process. A Postgres connection string in PGBRAKE_DSN (falls back to DATABASE_URL). Optional settings control the row limit, DDL allowance, read-only mode, statement timeout and journal location. Human approval happens in the client prompt or an interactive terminal.
Installation
In SourceWeft
- Open pgbrake 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
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.
Why
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.
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
Claude Code:
Codex (~/.codex/config.toml):
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
Settings (env)
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:
Keys are verified offline; pgbrake never phones home.
Source: README.md at commit da29fa1
Tools
0Version history
4- v0.3.0LatestNov 7, 2026
- v0.2.1Nov 5, 2026
- v0.2.0Nov 1, 2026
- v0.1.1Oct 29, 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
