Skip to content
MCP server

pgbrake

Local Postgres guard for AI agents that holds risky SQL for approval and can undo writes

Runs locally

pgbrake is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.

Pricing
Open source
Platforms
CLI, Self-hosted, Linux
Runs
Locally
Access
Needs a secret key or token
Version
0.3.0
Listing updated

Similar MCP servers

Install

You install MCP servers on a computer. Send yourself the link.

Add with the CLI

Run in a terminal

claude mcp add pgbrake --env PGBRAKE_DSN='<PGBRAKE_DSN>' -- uvx pgbrake

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

Or share it with your project

Add to .mcp.json

{
  "mcpServers": {
    "pgbrake": {
      "command": "uvx",
      "args": [
        "pgbrake"
      ],
      "env": {
        "PGBRAKE_DSN": "<PGBRAKE_DSN>"
      }
    }
  }
}

Claude Code setup guide

Add to claude_desktop_config.json

{
  "mcpServers": {
    "pgbrake": {
      "command": "uvx",
      "args": [
        "pgbrake"
      ],
      "env": {
        "PGBRAKE_DSN": "<PGBRAKE_DSN>"
      }
    }
  }
}

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

Claude Desktop setup guide

Add to ~/.cursor/mcp.json

{
  "mcpServers": {
    "pgbrake": {
      "command": "uvx",
      "args": [
        "pgbrake"
      ],
      "env": {
        "PGBRAKE_DSN": "<PGBRAKE_DSN>"
      }
    }
  }
}

Use .cursor/mcp.json in a project to share it with the project.

Cursor setup guide

Add to ~/.copilot/mcp-config.json

{
  "mcpServers": {
    "pgbrake": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "pgbrake"
      ],
      "env": {
        "PGBRAKE_DSN": "<PGBRAKE_DSN>"
      }
    }
  }
}

Or put the same entry in .mcp.json at your workspace root to share it.

VS Code setup guide

Add with the CLI

Run in a terminal

codex mcp add pgbrake --env PGBRAKE_DSN='<PGBRAKE_DSN>' -- uvx pgbrake

Or add to config.toml

Add to ~/.codex/config.toml

[mcp_servers.pgbrake]
command = "uvx"
args = ["pgbrake"]
env = { PGBRAKE_DSN = "<PGBRAKE_DSN>" }

Codex setup guide

Add to your client's MCP settings (most use this shape)

{
  "mcpServers": {
    "pgbrake": {
      "command": "uvx",
      "args": [
        "pgbrake"
      ],
      "env": {
        "PGBRAKE_DSN": "<PGBRAKE_DSN>"
      }
    }
  }
}
  • Gemini CLI and Antigravity

    Gemini CLI

    Add to ~/.gemini/settings.json

    {
      "mcpServers": {
        "pgbrake": {
          "command": "uvx",
          "args": [
            "pgbrake"
          ],
          "env": {
            "PGBRAKE_DSN": "<PGBRAKE_DSN>"
          }
        }
      }
    }

    Or run: gemini mcp add -s user -e PGBRAKE_DSN='<PGBRAKE_DSN>' pgbrake uvx -- pgbrake

    Antigravity

    Add to ~/.gemini/config/mcp_config.json

    {
      "mcpServers": {
        "pgbrake": {
          "command": "uvx",
          "args": [
            "pgbrake"
          ],
          "env": {
            "PGBRAKE_DSN": "<PGBRAKE_DSN>"
          }
        }
      }
    }

    Use .agents/mcp_config.json to add it to one workspace only.

    Gemini CLI and Antigravity setup guide

  • Devin Desktop (formerly Windsurf)

    Add to ~/.config/devin/mcp_config.json

    {
      "mcpServers": {
        "pgbrake": {
          "command": "uvx",
          "args": [
            "pgbrake"
          ],
          "env": {
            "PGBRAKE_DSN": "<PGBRAKE_DSN>"
          }
        }
      }
    }

    On Windows the file is %APPDATA%\devin\mcp_config.json. Use .devin/mcp_config.json to share it with a project.

    Devin Desktop setup guide

  • Cline

    Add to cline_mcp_settings.json

    {
      "mcpServers": {
        "pgbrake": {
          "command": "uvx",
          "args": [
            "pgbrake"
          ],
          "env": {
            "PGBRAKE_DSN": "<PGBRAKE_DSN>"
          }
        }
      }
    }

    Open it from the MCP Servers icon → Configure → Configure MCP Servers.

    Cline setup guide

  • Zed

    Add to Zed settings.json

    {
      "context_servers": {
        "pgbrake": {
          "command": "uvx",
          "args": [
            "pgbrake"
          ],
          "env": {
            "PGBRAKE_DSN": "<PGBRAKE_DSN>"
          }
        }
      }
    }

    Open it with zed: open settings file. Merge context_servers into the settings you already have.

    Zed setup guide

  • JetBrains AI Assistant and Junie

    AI Assistant

    Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add

    {
      "mcpServers": {
        "pgbrake": {
          "command": "uvx",
          "args": [
            "pgbrake"
          ],
          "env": {
            "PGBRAKE_DSN": "<PGBRAKE_DSN>"
          }
        }
      }
    }

    The AI Assistant docs only show command and args. If the env block is ignored, use Junie for this server.

    Junie

    Add to ~/.junie/mcp/mcp.json

    {
      "mcpServers": {
        "pgbrake": {
          "command": "uvx",
          "args": [
            "pgbrake"
          ],
          "env": {
            "PGBRAKE_DSN": "<PGBRAKE_DSN>"
          }
        }
      }
    }

    Use .junie/mcp/mcp.json to share it with a project.

    JetBrains AI Assistant and Junie setup guide

  • Kiro

    Add to ~/.kiro/settings/mcp.json

    {
      "mcpServers": {
        "pgbrake": {
          "command": "uvx",
          "args": [
            "pgbrake"
          ],
          "env": {
            "PGBRAKE_DSN": "<PGBRAKE_DSN>"
          }
        }
      }
    }

    Use .kiro/settings/mcp.json to add it to one workspace only.

    Kiro setup guide

Using several servers? Build one config file with the MCP config generator.

Configuration

  • PGBRAKE_DSNPostgres connection string, e.g. postgresql://me@localhost/appRequired

About pgbrake

pgbrake runs as a local stdio server between an agent such as Claude Code, Codex or Cursor and a Postgres database, and applies its rules inside the server so they hold whichever client calls it. SQL is parsed with the real Postgres parser through pglast rather than matched with regular expressions.

DDL, UPDATE or DELETE without a WHERE clause, upserts, MERGE and any write touching more than 100 rows (configurable) wait for a human. A few statements are never allowed, including ALTER SYSTEM, COPY ... PROGRAM and DO blocks. Approvals are one-shot, bound to the exact SQL and expire after 15 minutes. Before each UPDATE or DELETE the affected rows are saved locally, so a single command reverses the change unless the rows have moved on.

The README is clear on limits: undo is not a backup, TRUNCATE, DDL, upserts and MERGE cannot be undone, and the free version keeps the last 20 undoable changes. A paid Pro licence adds unlimited history, audit export and a migration guard.

What it does

SQL parsing
Statements are classified with the Postgres parser, not regex.
Approval queue
Risky SQL is held until a person approves it in the client or a terminal.
One-command undo
Rows touched by UPDATE and DELETE are saved so a change id can reverse them.
Audit journal
Every statement, decision and row count is logged to a local file.
Atomic multi-statement calls
Several statements in one call run in a single transaction.
Configurable limits
Row limit, DDL allowance, read-only mode and timeout are set by environment variables.

Good for

  • Let an agent work on a dev database with guardrails
  • Reverse a bad delete from an agent session
  • Review DDL before it runs
  • Keep an audit trail of agent SQL

Pricing

Open source

MIT-licensed core; Pro $29 one-time (then $39)

pgbrake FAQ

Is pgbrake free?

The core is free under the MIT licence. Pro is a one-time $29 for the first 100 licences, then $39.

Can every change be undone?

No. TRUNCATE, DDL, upserts, MERGE and updates on tables without a primary key cannot be undone.

Does data leave my machine?

The README says nothing leaves your machine, and licence keys are verified offline.

Who can approve held SQL?

Only a person, through the client's prompt or an interactive terminal command.

How do I install pgbrake?

Run pip install pgbrake or uvx pgbrake serve, and set PGBRAKE_DSN.

How do I add pgbrake to Claude Code?

Run this command in your terminal: claude mcp add pgbrake --env PGBRAKE_DSN='<PGBRAKE_DSN>' -- uvx pgbrake

What are the best alternatives to pgbrake?

The closest alternatives to pgbrake are REA, MCP Toolbox for Databases, redamon, AiSOC and Bernstein.

Where this comes from

  • Description: written from the project's README.
  • Install steps: from the official MCP Registry entry.

How AIPoweredBot checks servers