# pgwarden

> pgwarden is an MCP server for databases. Postgres gateway where each person queries as their own database role. It runs as a hosted remote server, so there is nothing to install locally.

- **Kind:** MCP server
- **Platforms:** Self-hosted, API
- **Repository:** https://github.com/b0yko/pgwarden
- **MCP Registry name:** io.github.B0yko/pgwarden
- **Categories:** [databases](https://ai-powered.com/categories/databases), [security](https://ai-powered.com/categories/security)
- **Listing updated:** 2026-11-23

## About

pgwarden is an MCP gateway that lets Claude, ChatGPT, Cursor or any MCP client query Postgres as the person asking. Users sign in through your OIDC provider, and the gateway connects with their own Postgres role, so grants, row-level security and masking views decide what they can see.

Reads run in a read-only transaction with one statement per call, without any SQL parsing. Writes are proposed, checked with EXPLAIN, approved by a named person and run once. Every tool call, sign-in, approval and admin change is recorded in an append-only, hash-chained audit log.

It ships as a container image and needs Postgres 16+, a separate state database and an OIDC provider. A Docker Compose demo includes a mock identity provider and sample users with different access.

## Features

- **Per-person database roles:** Each user is mapped from your identity provider to their own Postgres login role.
- **Read-only by construction:** Queries run in a read-only transaction with a single statement per call.
- **Approved writes:** Writes wait for a named approver after an EXPLAIN check, and run once.
- **Masking and row-level security:** Postgres grants, RLS and masking views control what each person sees.
- **Hash-chained audit log:** Tool calls, sign-ins, approvals and admin changes are logged append-only.
- **OAuth 2.1 sign-in:** Clients connect with consent, PKCE and OIDC sign-in.

## Good for

- Give analysts AI access to Postgres without a shared credential
- Mask personal data for some users and not others
- Require approval before an AI-proposed write
- Keep an auditable record of AI database access
- Try the setup locally with the demo stack

## Install

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

```sh
claude mcp add pgwarden --env PGWARDEN_CONFIG='<PGWARDEN_CONFIG>' --env PGWARDEN_TARGET_DSN='<PGWARDEN_TARGET_DSN>' --env PGWARDEN_STATE_DSN='<PGWARDEN_STATE_DSN>' --env PGWARDEN_ROLE_SECRET_FILE='<PGWARDEN_ROLE_SECRET_FILE>' --env PGWARDEN_SIGNING_KEY_FILE='<PGWARDEN_SIGNING_KEY_FILE>' --env PGWARDEN_SESSION_SECRET_FILE='<PGWARDEN_SESSION_SECRET_FILE>' --env PGWARDEN_OIDC_CLIENT_SECRET_FILE='<PGWARDEN_OIDC_CLIENT_SECRET_FILE>' -- docker run -i --rm -e PGWARDEN_CONFIG -e PGWARDEN_TARGET_DSN -e PGWARDEN_STATE_DSN -e PGWARDEN_ROLE_SECRET_FILE -e PGWARDEN_SIGNING_KEY_FILE -e PGWARDEN_SESSION_SECRET_FILE -e PGWARDEN_OIDC_CLIENT_SECRET_FILE ghcr.io/b0yko/pgwarden:0.1.1
```

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": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "pgwarden": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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 pgwarden --env PGWARDEN_CONFIG='<PGWARDEN_CONFIG>' --env PGWARDEN_TARGET_DSN='<PGWARDEN_TARGET_DSN>' --env PGWARDEN_STATE_DSN='<PGWARDEN_STATE_DSN>' --env PGWARDEN_ROLE_SECRET_FILE='<PGWARDEN_ROLE_SECRET_FILE>' --env PGWARDEN_SIGNING_KEY_FILE='<PGWARDEN_SIGNING_KEY_FILE>' --env PGWARDEN_SESSION_SECRET_FILE='<PGWARDEN_SESSION_SECRET_FILE>' --env PGWARDEN_OIDC_CLIENT_SECRET_FILE='<PGWARDEN_OIDC_CLIENT_SECRET_FILE>' -- docker run -i --rm -e PGWARDEN_CONFIG -e PGWARDEN_TARGET_DSN -e PGWARDEN_STATE_DSN -e PGWARDEN_ROLE_SECRET_FILE -e PGWARDEN_SIGNING_KEY_FILE -e PGWARDEN_SESSION_SECRET_FILE -e PGWARDEN_OIDC_CLIENT_SECRET_FILE ghcr.io/b0yko/pgwarden:0.1.1
```

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

```toml
[mcp_servers.pgwarden]
command = "docker"
args = ["run", "-i", "--rm", "-e", "PGWARDEN_CONFIG", "-e", "PGWARDEN_TARGET_DSN", "-e", "PGWARDEN_STATE_DSN", "-e", "PGWARDEN_ROLE_SECRET_FILE", "-e", "PGWARDEN_SIGNING_KEY_FILE", "-e", "PGWARDEN_SESSION_SECRET_FILE", "-e", "PGWARDEN_OIDC_CLIENT_SECRET_FILE", "ghcr.io/b0yko/pgwarden:0.1.1"]
env = { PGWARDEN_CONFIG = "<PGWARDEN_CONFIG>", PGWARDEN_TARGET_DSN = "<PGWARDEN_TARGET_DSN>", PGWARDEN_STATE_DSN = "<PGWARDEN_STATE_DSN>", PGWARDEN_ROLE_SECRET_FILE = "<PGWARDEN_ROLE_SECRET_FILE>", PGWARDEN_SIGNING_KEY_FILE = "<PGWARDEN_SIGNING_KEY_FILE>", PGWARDEN_SESSION_SECRET_FILE = "<PGWARDEN_SESSION_SECRET_FILE>", PGWARDEN_OIDC_CLIENT_SECRET_FILE = "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>" }
```

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

```json
{
  "mcpServers": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

Or run: gemini mcp add -s user -e PGWARDEN_CONFIG='<PGWARDEN_CONFIG>' -e PGWARDEN_TARGET_DSN='<PGWARDEN_TARGET_DSN>' -e PGWARDEN_STATE_DSN='<PGWARDEN_STATE_DSN>' -e PGWARDEN_ROLE_SECRET_FILE='<PGWARDEN_ROLE_SECRET_FILE>' -e PGWARDEN_SIGNING_KEY_FILE='<PGWARDEN_SIGNING_KEY_FILE>' -e PGWARDEN_SESSION_SECRET_FILE='<PGWARDEN_SESSION_SECRET_FILE>' -e PGWARDEN_OIDC_CLIENT_SECRET_FILE='<PGWARDEN_OIDC_CLIENT_SECRET_FILE>' pgwarden docker -- run -i --rm -e PGWARDEN_CONFIG -e PGWARDEN_TARGET_DSN -e PGWARDEN_STATE_DSN -e PGWARDEN_ROLE_SECRET_FILE -e PGWARDEN_SIGNING_KEY_FILE -e PGWARDEN_SESSION_SECRET_FILE -e PGWARDEN_OIDC_CLIENT_SECRET_FILE ghcr.io/b0yko/pgwarden:0.1.1

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

```json
{
  "mcpServers": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

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": {
    "pgwarden": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PGWARDEN_CONFIG",
        "-e",
        "PGWARDEN_TARGET_DSN",
        "-e",
        "PGWARDEN_STATE_DSN",
        "-e",
        "PGWARDEN_ROLE_SECRET_FILE",
        "-e",
        "PGWARDEN_SIGNING_KEY_FILE",
        "-e",
        "PGWARDEN_SESSION_SECRET_FILE",
        "-e",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE",
        "ghcr.io/b0yko/pgwarden:0.1.1"
      ],
      "env": {
        "PGWARDEN_CONFIG": "<PGWARDEN_CONFIG>",
        "PGWARDEN_TARGET_DSN": "<PGWARDEN_TARGET_DSN>",
        "PGWARDEN_STATE_DSN": "<PGWARDEN_STATE_DSN>",
        "PGWARDEN_ROLE_SECRET_FILE": "<PGWARDEN_ROLE_SECRET_FILE>",
        "PGWARDEN_SIGNING_KEY_FILE": "<PGWARDEN_SIGNING_KEY_FILE>",
        "PGWARDEN_SESSION_SECRET_FILE": "<PGWARDEN_SESSION_SECRET_FILE>",
        "PGWARDEN_OIDC_CLIENT_SECRET_FILE": "<PGWARDEN_OIDC_CLIENT_SECRET_FILE>"
      }
    }
  }
}
```

## Tools

From the tool list in its README, going by the names, 3 of 4 tools read data; 1 name doesn't say. From the server's own tool labels and tool names; not verified by us.

- `whoami`: Show the identity and Postgres role in use
- `list_tables` (name suggests: reads): List tables available to the signed-in role
- `describe_table` (name suggests: reads): Describe a table
- `query` (name suggests: reads): Run a read-only query as the person's own role

## FAQ

### What does pgwarden need?

Postgres 16+, a state database and an OIDC provider; it runs from a container image.

### How does pgwarden keep reads safe?

Each query runs in a read-only transaction with one statement per call, and access is enforced by the database itself.

### How do writes work?

A write is proposed, checked with EXPLAIN, approved by a named person and then run once.

### Can I try pgwarden first?

Yes. A Docker Compose demo starts Postgres, a mock identity provider and the gateway locally.

### How do I add pgwarden to Claude Code?

Run this command in your terminal: claude mcp add pgwarden --env PGWARDEN_CONFIG='<PGWARDEN_CONFIG>' --env PGWARDEN_TARGET_DSN='<PGWARDEN_TARGET_DSN>' --env PGWARDEN_STATE_DSN='<PGWARDEN_STATE_DSN>' --env PGWARDEN_ROLE_SECRET_FILE='<PGWARDEN_ROLE_SECRET_FILE>' --env PGWARDEN_SIGNING_KEY_FILE='<PGWARDEN_SIGNING_KEY_FILE>' --env PGWARDEN_SESSION_SECRET_FILE='<PGWARDEN_SESSION_SECRET_FILE>' --env PGWARDEN_OIDC_CLIENT_SECRET_FILE='<PGWARDEN_OIDC_CLIENT_SECRET_FILE>' -- docker run -i --rm -e PGWARDEN_CONFIG -e PGWARDEN_TARGET_DSN -e PGWARDEN_STATE_DSN -e PGWARDEN_ROLE_SECRET_FILE -e PGWARDEN_SIGNING_KEY_FILE -e PGWARDEN_SESSION_SECRET_FILE -e PGWARDEN_OIDC_CLIENT_SECRET_FILE ghcr.io/b0yko/pgwarden:0.1.1

### What are the best alternatives to pgwarden?

The closest alternatives to pgwarden are Pgmoat, Db Gateway, Postgres Secured (Aegis Zero-Trust), Midplane and Warehouse MCP.

## Where this comes from

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

## Alternatives

- [Pgmoat](https://ai-powered.com/mcp/pgmoat): Pgmoat is an open-source MCP server for databases.
- [Db Gateway](https://ai-powered.com/mcp/db-gateway-3): Db Gateway is an open-source MCP server for databases.
- [Postgres Secured (Aegis Zero-Trust)](https://ai-powered.com/mcp/postgres-secured-aegis-zero-trust): Postgres Secured (Aegis Zero-Trust) is an open-source MCP server for databases.
- [Midplane](https://ai-powered.com/mcp/midplane): Midplane is an open-source MCP server for databases.
- [Warehouse MCP](https://ai-powered.com/mcp/warehouse-mcp-2): Warehouse MCP is an open-source MCP server for databases.
- [Pg Readonly MCP](https://ai-powered.com/mcp/pg-readonly-mcp): Pg Readonly MCP is an open-source MCP server for databases.
- [SQL MCP Server](https://ai-powered.com/mcp/sql-mcp-server): SQL MCP Server is an open-source MCP server for databases.
- [vaultgate](https://ai-powered.com/mcp/vaultgate): vaultgate is an open-source MCP server for security.

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