
pgbrake
io.github.lexang由 GitHub 账号 lexang 发布v0.3.0更新于 Nov 7, 2026
Postgres brake for AI agents: risky SQL waits for approval, UPDATE/DELETE get one-command undo.
概览
本地 MCP 服务器,在 AI 代理与 Postgres 之间加一道闸门:高风险 SQL 需人工批准,写入可用一条命令撤销。
- 可以做什么
- 让代理对 Postgres 执行 SQL,语句由真正的 Postgres 解析器解析
- 将高风险写入挂起等待人工批准:DDL、无 WHERE 的 UPDATE/DELETE、超过行数上限的写入、upsert 与 MERGE
- 直接拒绝 ALTER SYSTEM、角色或数据库的创建与删除、COPY PROGRAM、DO 块等语句
- 按变更 ID 撤销单条 UPDATE 或 DELETE,若数据已被改动则拒绝执行
- 在命令行查看待批准项、可撤销变更和完整审计日志
- 适用场景
- 当你允许 AI 编程代理写入真实的 Postgres 数据库并希望有安全网时使用:破坏性语句需批准、写入可回退、留有审计记录,且规则在服务器内部强制执行,而非依赖客户端提示。
- 运行要求
- 本地 Python 环境(pip 或 uvx),以 stdio 进程运行。需要 PGBRAKE_DSN 中的 Postgres 连接字符串(可回退到 DATABASE_URL)。可选设置控制行数上限、是否允许 DDL、只读模式、语句超时和日志位置。人工批准在客户端提示或交互式终端中完成。
安装
在 SourceWeft 中
- 打开 控制台中的 pgbrake,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
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.
来源:README.md,提交 da29fa1
工具
0版本历史
4- v0.3.0最新Nov 7, 2026
- v0.2.1Nov 5, 2026
- v0.2.0Nov 1, 2026
- v0.1.1Oct 29, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分