
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 分