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

AI-generated 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.
Before you install
It needs a database connection string with write access to your Postgres, so scope that role carefully. Writes, DDL and deletes are executed against a real database; undo only covers rows changed through pgbrake, is not a backup, and cannot reverse TRUNCATE, DDL, upserts or MERGE. The free version keeps only the last 20 undoable changes. A paid Pro tier exists; license keys are verified offline.

Installation

In SourceWeft

  1. Open pgbrake in the dashboard and add it to a workspace.
  2. 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.

[pgbrake demo]

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 = 42pgbrake> 1 row affected; undo with change id chg_8e01b7d2
you$ pgbrake undo chg_8e01b7d2undid delete on "users": 1 row(s) restored

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/DELETE without WHERE, any write over the row limit (default 100), upserts and MERGE.
  • Never allowed: ALTER SYSTEM, role/database creation and drops, COPY ... PROGRAM, DO blocks.
  • 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

bash
pip install pgbrake      # or: uvx pgbrake serve

Claude Code:

bash
claude mcp add pgbrake --env PGBRAKE_DSN="postgresql://me@localhost/app" -- uvx pgbrake serve

Codex (~/.codex/config.toml):

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 youpgbrake approve <id>       # approve (interactive terminal only)pgbrake deny <id>pgbrake changes            # undoable changespgbrake undo <change-id>   # reverse onepgbrake log                # audit log

Settings (env)

VariableDefault
PGBRAKE_DSN—connection string (falls back to DATABASE_URL)
PGBRAKE_MAX_ROWS100writes touching more rows need approval
PGBRAKE_ALLOW_DDL0set 1 to let schema changes through (still logged)
PGBRAKE_READ_ONLY0set 1 to refuse every write
PGBRAKE_STATEMENT_TIMEOUT_MS15000
PGBRAKE_JOURNAL~/.pgbrake/journal.db

Limits

  • Undo covers rows changed through pgbrake. It is not a backup: keep real backups.
  • TRUNCATE, DDL, upserts and MERGE are 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 PreToolUse hook catches prisma migrate reset --force, drizzle-kit push --force, alembic downgrade base and friends, takes a pg_dump snapshot first (when PGBRAKE_DSN is set), checks pg_restore can read it, then asks you. If the snapshot fails, the command is blocked instead (override with PGBRAKE_ALLOW_NO_SNAPSHOT=1). Set PGBRAKE_VERIFY_RESTORE=1 to 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 (or PGBRAKE_DRILL_DSN pointing at a server where it has them) and takes about as long as a restore. Install with pgbrake 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_LICENSE

Keys are verified offline; pgbrake never phones home.

Source: README.md at commit da29fa1

Tools

0
SourceWeft has not started this package in its sandbox yet, so its tools are not known.

Version history

4
  1. v0.3.0LatestNov 7, 2026
  2. v0.2.1Nov 5, 2026
  3. v0.2.0Nov 1, 2026
  4. 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