# Mcpg

> Mcpg is an open-source MCP server for databases. PostgreSQL MCP server with 279 tools for queries, tuning and ops, read-only by default. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, self-hosted
- **Website:** https://devopam.github.io/MCPg/
- **Repository:** https://github.com/devopam/mcpg
- **MCP Registry name:** io.github.devopam/mcpg
- **Categories:** databases, developer tools
- **Listing updated:** 2026-11-14

## About

Safety is built into the parsing. Every SQL statement an agent supplies is checked against an AST allowlist before it runs, DDL, shell and LISTEN/NOTIFY stay off until opted in, and each tool publishes read-only and open-world annotations so clients can auto-approve reads and ask before writes.

The tool surface is unusually wide: catalog introspection, EXPLAIN analysis, index tuning, locks, vacuum, dumps, replicas, migrations, natural-language SQL, hybrid search and graph queries. It talks to Postgres through psycopg3 and uses TimescaleDB, pgvector, PostGIS, Apache AGE and pg_stat_statements when present.

For production use it offers connection pooling, per-request SET ROLE multi-tenancy, read-replica routing, rate limiting, redacted audit events, TLS enforcement, OIDC JWT auth and a Prometheus metrics endpoint on the HTTP transport. A read-only demo is hosted on Hugging Face Spaces.

## Features

- **AST-validated SQL:** Statements pass an allowlist before running.
- **Read-only default:** Writes, DDL and shell are opt-in.
- **DBA operations:** Health checks, index tuning, locks, vacuum and replicas.
- **Multi-tenancy:** Per-request SET ROLE and OIDC bearer auth.
- **Observability:** Prometheus metrics and redacted audit trail.
- **Extension support:** Works with pgvector, PostGIS, TimescaleDB and Apache AGE.

## Good for

- Let an agent inspect a schema safely
- Analyze a slow query with EXPLAIN
- Tune indexes with pg_stat_statements data
- Run read-only reporting against a replica

## Install

### Claude Code (Terminal)

```sh
claude mcp add mcpg -- uvx mcpg
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "mcpg": {
      "command": "uvx",
      "args": [
        "mcpg"
      ]
    }
  }
}
```

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

```json
{
  "mcpServers": {
    "mcpg": {
      "command": "uvx",
      "args": [
        "mcpg"
      ]
    }
  }
}
```

### VS Code (.vscode/mcp.json)

```json
{
  "servers": {
    "mcpg": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "mcpg"
      ]
    }
  }
}
```

### Windsurf (~/.codeium/windsurf/mcp_config.json)

```json
{
  "mcpServers": {
    "mcpg": {
      "command": "uvx",
      "args": [
        "mcpg"
      ]
    }
  }
}
```

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

```json
{
  "mcpServers": {
    "mcpg": {
      "command": "uvx",
      "args": [
        "mcpg"
      ]
    }
  }
}
```

## FAQ

### How do I install it?

pip install mcpg, or use the Docker image from ghcr.io.

### Which Postgres versions are covered?

14 to 19, with 19 tested as beta.

### Is it read-only?

Yes by default; write capabilities must be enabled.

### Can I try it first?

Yes, a hosted read-only demo runs against throwaway data.

### Is Mcpg free?

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

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

Run this command in your terminal: claude mcp add mcpg -- uvx mcpg

### What are the best alternatives to Mcpg?

The closest alternatives to Mcpg are REA, Codebase Memory, GitHub, Serena MCP: the IDE for your agent and XERJ.

## Alternatives

- [REA](https://ai-powered.com/mcp/rea): REA is an open-source MCP server for developer tools.
- [Codebase Memory](https://ai-powered.com/mcp/codebase-memory): Codebase Memory is an open-source MCP server for knowledge and memory.
- [GitHub](https://ai-powered.com/mcp/github-2): GitHub is an open-source MCP server for developer tools.
- [Serena MCP: the IDE for your agent](https://ai-powered.com/mcp/serena-mcp-the-ide-for-your-agent): Serena MCP: the IDE for your agent is an open-source MCP server for developer tools.
- [XERJ](https://ai-powered.com/mcp/xerj): XERJ is an open-source MCP server for knowledge and memory.
- [Ouroboros](https://ai-powered.com/mcp/ouroboros): Ouroboros is an open-source MCP server for developer tools.
- [Claude Code Ultimate Guide](https://ai-powered.com/mcp/claude-code-ultimate-guide): Claude Code Ultimate Guide is an open-source MCP server for ai models and llm tooling.
- [Concord MCP](https://ai-powered.com/mcp/concord-mcp): Concord MCP is a freemium MCP server for developer tools.

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