# MCP Postgres

> MCP Postgres is an open-source MCP server for databases. MCP server giving AI clients safe, governed access to PostgreSQL schemas and queries. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, Self-hosted
- **Repository:** https://github.com/dockndevai/mcp-postgres
- **MCP Registry name:** io.github.dockndevai/mcp-postgres
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-11-27

## About

Connects an MCP-capable AI client to any PostgreSQL 13+ database so it can browse schemas, run read queries, inspect query plans and check live activity. It starts in read-only mode and every read runs inside a transaction that is always rolled back.

Writes are opt-in. Teams can enable inserts and updates, and an admin mode adds deletes, drops and session termination, with each destructive action requiring a human approval bound to the exact arguments. Access can be narrowed to an allowlist of schemas, superuser connections are refused, and a row cap limits how much any single change can touch.

It suits developers and data teams who want an assistant to investigate slow queries, explore unfamiliar databases or make small data fixes without handing it an unrestricted connection string.

## Features

- **Schema exploration:** Lists schemas, tables and views with sizes and row estimates, and describes columns, constraints and indexes with scan counts.
- **Structured and free-form queries:** Offers schema-scoped row selection without SQL, plus a parameterized single read statement for custom queries.
- **Query plan tuning:** Returns JSON execution plans, lists top statements from pg_stat_statements and can build indexes concurrently.
- **Live diagnostics:** Shows active sessions and waits, connection and cache statistics, roles and extensions, and can cancel a runaway query.
- **Layered access modes:** Read-only, read-write and admin modes register only the tools allowed at each level.
- **Guarded changes:** Writes are capped by affected-row limits, require a non-empty filter for updates and deletes, and can be previewed in dry-run mode.
- **Secret redaction and audit:** Masks values in password and token-like columns and writes a JSON audit line for each guarded operation.

## Good for

- Finding the largest tables and indexes that are never scanned
- Explaining why a query is slow and suggesting an index
- Checking what is running and whether anything is waiting on a lock
- Exploring an unfamiliar database schema through an AI assistant
- Making a controlled update to a single record with human approval

## Install

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

```sh
claude mcp add mcp-postgres --env POSTGRES_URL='<POSTGRES_URL>' -- npx -y @dockndevai/mcp-postgres
```

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": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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 mcp-postgres --env POSTGRES_URL='<POSTGRES_URL>' -- npx -y @dockndevai/mcp-postgres
```

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

```toml
[mcp_servers.mcp-postgres]
command = "npx"
args = ["-y", "@dockndevai/mcp-postgres"]
env = { POSTGRES_URL = "<POSTGRES_URL>" }
```

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

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

Or run: gemini mcp add -s user -e POSTGRES_URL='<POSTGRES_URL>' mcp-postgres npx -- -y @dockndevai/mcp-postgres

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

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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

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

```json
{
  "mcpServers": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

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": {
    "mcp-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@dockndevai/mcp-postgres"
      ],
      "env": {
        "POSTGRES_URL": "<POSTGRES_URL>"
      }
    }
  }
}
```

## Tools

From the tool list in its README, going by the names, 2 of 21 tools delete data and 6 change data; 2 names don't say. From the server's own tool labels and tool names; not verified by us.

- `get_server_info` (name suggests: reads): Server information.
- `list_schemas` (name suggests: reads): Lists schemas.
- `list_tables` (name suggests: reads): Lists tables and views with sizes and row estimates.
- `describe_table` (name suggests: reads): Describes columns, constraints and indexes.
- `select_rows`: Structured schema-scoped row selection.
- `run_query` (name suggests: changes): Runs one read-only SQL statement with parameters.
- `explain_query` (name suggests: reads): Returns JSON query plans.
- `list_active_queries` (name suggests: reads): Lists active sessions and waits.
- `get_database_stats` (name suggests: reads): Connection, cache and deadlock statistics.
- `get_top_queries` (name suggests: reads): Top statements from pg_stat_statements.
- `list_roles` (name suggests: reads): Lists database roles.
- `list_extensions` (name suggests: reads): Lists installed extensions.
- `insert_rows` (name suggests: changes): Parameterized row inserts.
- `update_rows` (name suggests: changes): Parameterized row updates with a required filter.
- `create_index` (name suggests: changes): Creates an index concurrently.
- `analyze_table` (name suggests: reads): Runs ANALYZE on a table.
- `cancel_query` (name suggests: changes): Cancels a running query.
- `delete_rows` (name suggests: deletes): Deletes rows (admin mode, delete permission required).
- `drop_table` (name suggests: deletes): Drops a table (admin mode, delete permission required).
- `terminate_backend`: Terminates a database session (admin mode, delete permission required).
- `execute_sql` (name suggests: changes): Runs raw SQL (admin mode, raw SQL opt-in required).

## FAQ

### Which database versions does MCP Postgres support?

It talks SQL to any PostgreSQL 13 or newer database.

### Is MCP Postgres safe to point at a production database?

It starts read-only, refuses superuser connections and runs reads in rolled-back read-only transactions. Using a dedicated least-privilege role is recommended.

### How is MCP Postgres installed?

It is published on npm and runs on demand with npx, with configuration snippets for Claude Desktop, Claude Code, Cursor, Windsurf, Codex CLI and VS Code.

### Does MCP Postgres work with Kubernetes-hosted Percona PostgreSQL?

That workload is covered by a separate server, mcp-percona-pg. This one connects to any PostgreSQL database over SQL.

### Is MCP Postgres free?

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

### How do I add MCP Postgres to Claude Code?

Run this command in your terminal: claude mcp add mcp-postgres --env POSTGRES_URL='<POSTGRES_URL>' -- npx -y @dockndevai/mcp-postgres

### What are the best alternatives to MCP Postgres?

The closest alternatives to MCP Postgres are Postgres MCP, Postgres, PostgreSQL MCP Server, Postgres Schema MCP and PostgreSQL MCP Server.

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

- [Postgres MCP](https://ai-powered.com/mcp/postgres-mcp): Postgres MCP is an open-source MCP server for databases.
- [Postgres](https://ai-powered.com/mcp/postgres): Postgres is an open-source MCP server for databases.
- [PostgreSQL MCP Server](https://ai-powered.com/mcp/postgresql-mcp-server-2): PostgreSQL MCP Server is an open-source MCP server for databases.
- [Postgres Schema MCP](https://ai-powered.com/mcp/postgres-schema-mcp): Postgres Schema MCP is an open-source MCP server for databases.
- [PostgreSQL MCP Server](https://ai-powered.com/mcp/postgresql-mcp-server-4): PostgreSQL MCP Server is an open-source MCP server for databases.
- [Postgres MCP](https://ai-powered.com/mcp/postgres-mcp-2): Postgres MCP is an open-source MCP server for databases.
- [PostgreSQL MCP Server](https://ai-powered.com/mcp/postgresql-mcp-server-3): PostgreSQL MCP Server is an open-source MCP server for databases.
- [Postgres Scout MCP](https://ai-powered.com/mcp/postgres-scout-mcp): Postgres Scout MCP is an open-source MCP server for databases.

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