Skip to content
MCP server

pgleash

Postgres proxy that stops AI agents from running destructive or out-of-scope SQL

Runs locally

pgleash 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, API, Self-hosted
Runs
Locally
What it can do
Read-only
Access
Needs a secret key or token
Version
0.1.1

Similar MCP servers

Install

Add with the CLI

Run in a terminal

claude mcp add pgleash --env PGLEASH_UPSTREAM='<PGLEASH_UPSTREAM>' -- npx -y pgleash

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": {
    "pgleash": {
      "command": "npx",
      "args": [
        "-y",
        "pgleash"
      ],
      "env": {
        "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
      }
    }
  }
}

Claude Code setup guide

Add to claude_desktop_config.json

{
  "mcpServers": {
    "pgleash": {
      "command": "npx",
      "args": [
        "-y",
        "pgleash"
      ],
      "env": {
        "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
      }
    }
  }
}

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

Claude Desktop setup guide

Add to ~/.cursor/mcp.json

{
  "mcpServers": {
    "pgleash": {
      "command": "npx",
      "args": [
        "-y",
        "pgleash"
      ],
      "env": {
        "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
      }
    }
  }
}

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

Cursor setup guide

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

{
  "mcpServers": {
    "pgleash": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "pgleash"
      ],
      "env": {
        "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
      }
    }
  }
}

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 pgleash --env PGLEASH_UPSTREAM='<PGLEASH_UPSTREAM>' -- npx -y pgleash

Or add to config.toml

Add to ~/.codex/config.toml

[mcp_servers.pgleash]
command = "npx"
args = ["-y", "pgleash"]
env = { PGLEASH_UPSTREAM = "<PGLEASH_UPSTREAM>" }

Codex setup guide

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

{
  "mcpServers": {
    "pgleash": {
      "command": "npx",
      "args": [
        "-y",
        "pgleash"
      ],
      "env": {
        "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
      }
    }
  }
}
  • Gemini CLI and Antigravity

    Gemini CLI

    Add to ~/.gemini/settings.json

    {
      "mcpServers": {
        "pgleash": {
          "command": "npx",
          "args": [
            "-y",
            "pgleash"
          ],
          "env": {
            "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
          }
        }
      }
    }

    Or run: gemini mcp add -s user -e PGLEASH_UPSTREAM='<PGLEASH_UPSTREAM>' pgleash npx -- -y pgleash

    Antigravity

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

    {
      "mcpServers": {
        "pgleash": {
          "command": "npx",
          "args": [
            "-y",
            "pgleash"
          ],
          "env": {
            "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
          }
        }
      }
    }

    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": {
        "pgleash": {
          "command": "npx",
          "args": [
            "-y",
            "pgleash"
          ],
          "env": {
            "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
          }
        }
      }
    }

    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": {
        "pgleash": {
          "command": "npx",
          "args": [
            "-y",
            "pgleash"
          ],
          "env": {
            "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
          }
        }
      }
    }

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

    Cline setup guide

  • Zed

    Add to Zed settings.json

    {
      "context_servers": {
        "pgleash": {
          "command": "npx",
          "args": [
            "-y",
            "pgleash"
          ],
          "env": {
            "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
          }
        }
      }
    }

    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": {
        "pgleash": {
          "command": "npx",
          "args": [
            "-y",
            "pgleash"
          ],
          "env": {
            "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
          }
        }
      }
    }

    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": {
        "pgleash": {
          "command": "npx",
          "args": [
            "-y",
            "pgleash"
          ],
          "env": {
            "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
          }
        }
      }
    }

    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": {
        "pgleash": {
          "command": "npx",
          "args": [
            "-y",
            "pgleash"
          ],
          "env": {
            "PGLEASH_UPSTREAM": "<PGLEASH_UPSTREAM>"
          }
        }
      }
    }

    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

  • PGLEASH_UPSTREAMConnection string of the real database, ideally a least-privilege roleRequired

About pgleash

pgleash sits between an agent and a Postgres database and parses each statement with Postgres's own parser before it reaches the server. Reads pass through, while statements such as DROP, TRUNCATE, unbounded DELETE, and writes hidden inside CTEs or EXPLAIN ANALYZE are stopped. The agent connects with a pgleash token and never receives the real database credentials.

Beyond statement types, it can block specific tables, columns and functions, cap the number of rows returned, enforce a statement timeout, and write an audit log of every query with the rule that blocked it. It runs as a standalone proxy that psql and common Postgres drivers can connect to, or as an MCP server exposing query, list_tables and describe_table tools.

It suits developers who want coding agents to query production-like data without holding the real connection string. Its authors describe it as a guardrail rather than a sandbox, so it is best paired with a least-privilege database role.

Tools this server provides (3)

Taken from the project documentation; the running server may differ.

From the tool list in its README, going by the names, all 3 tools only read data.

From the server's own tool labels and tool names; not verified by us.

queryName suggests: reads
Runs a SQL query through the pgleash rules.
list_tablesName suggests: reads
Lists tables available through the proxy.
describe_tableName suggests: reads
Describes the columns of a table.

What it does

Read-only by default
Only reads, EXPLAIN, SHOW and transaction control are allowed, and the session cannot be switched back to writable.
Parser-based statement checks
Each statement is parsed with Postgres's own parser, so writes hidden in CTEs or EXPLAIN ANALYZE are caught.
Guarded write mode
An optional mode allows INSERT and filtered UPDATE or DELETE while keeping DDL and TRUNCATE blocked.
Denied tables and columns
Named tables and columns can be off-limits, and denied columns are returned as NULL in results.
Row cap and timeouts
Results are capped at 1,000 rows by default and statements have a 10 second timeout.
Audit log
Every query, allowed or blocked, is written as a JSON line with the matching rule.
Offline policy check
A check command applies the same rules to a query string without connecting to a database.

Good for

  • Letting a coding agent explore a development database without risking destructive writes
  • Preventing an agent from reading sensitive columns such as email or password hashes
  • Auditing which queries an AI agent ran against a database
  • Testing SQL policy rules in CI or agent hooks before deployment
  • Giving an MCP client read access to Postgres tables with row limits

Pricing

Open source

Free and MIT licensed; run locally via npm.

pgleash FAQ

Does pgleash need a database to check queries?

No. The pgleash check command runs the same policy on a query string without connecting to a database.

Can the agent see the real database credentials?

No. The agent connects with a pgleash token, while the upstream connection string stays with the proxy.

What happens when a query is blocked?

The client gets a normal Postgres error that states the reason and includes a hint.

Which MCP tools does pgleash expose?

In MCP mode it provides query, list_tables and describe_table.

Is pgleash free?

Yes. pgleash is open source, so you can use and self-host it for free.

How do I add pgleash to Claude Code?

Run this command in your terminal: claude mcp add pgleash --env PGLEASH_UPSTREAM='<PGLEASH_UPSTREAM>' -- npx -y pgleash

What are the best alternatives to pgleash?

The closest alternatives to pgleash are Pgmoat, Pg Readonly MCP, Postgres Secured (Aegis Zero-Trust), pgbrake and Lokra.

Where this comes from

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

How AIPoweredBot checks servers