# pgbrake

> pgbrake is an open-source MCP server for databases. Local Postgres guard for AI agents that holds risky SQL for approval and can undo writes. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, Self-hosted, Linux, macOS, Windows
- **Repository:** https://github.com/lexang/pgbrake
- **MCP Registry name:** io.github.lexang/pgbrake
- **Categories:** [databases](https://ai-powered.com/categories/databases), [security](https://ai-powered.com/categories/security)
- **Listing updated:** 2026-11-23

## About

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.

## Features

- **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

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
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.

### Claude Code: Or share it with your project (.mcp.json)

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

### Claude Desktop (claude_desktop_config.json)

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

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

### Cursor (~/.cursor/mcp.json)

```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.

### VS Code (~/.copilot/mcp-config.json)

```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.

### Codex: Add with the CLI (Terminal)

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

### Codex: Or add to config.toml (~/.codex/config.toml)

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

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```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

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

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

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

### Devin Desktop (~/.config/devin/mcp_config.json)

```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.

### Cline (cline_mcp_settings.json)

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

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

### Zed (Zed settings.json)

```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.

### JetBrains AI Assistant and Junie: AI Assistant (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "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.

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

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

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

### Kiro (~/.kiro/settings/mcp.json)

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

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

### Other clients (your client's MCP settings (most use this shape))

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

## 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.

## Alternatives

- [REA](https://ai-powered.com/mcp/rea): REA is an open-source MCP server for developer tools.
- [MCP Toolbox for Databases](https://ai-powered.com/mcp/mcp-toolbox-for-databases-2): MCP Toolbox for Databases is an open-source MCP server for databases.
- [redamon](https://ai-powered.com/mcp/redamon): redamon is an open-source MCP server for ai models and llm tooling.
- [AiSOC](https://ai-powered.com/mcp/aisoc): AiSOC is an open-source MCP server for ai models and llm tooling.
- [Bernstein](https://ai-powered.com/mcp/bernstein): Bernstein is an open-source MCP server for developer tools.
- [SSH — policy-gated remote access](https://ai-powered.com/mcp/ssh-policy-gated-remote-access): SSH — policy-gated remote access is an open-source MCP server for security.
- [ClickHouse](https://ai-powered.com/mcp/clickhouse): ClickHouse is an open-source MCP server for databases.
- [postgres-mcp](https://ai-powered.com/mcp/postgres-mcp-4): postgres-mcp is an open-source MCP server for databases.

---
Source: https://ai-powered.com/mcp/pgbrake
