Postgres MCP logo

Postgres MCP

by crystaldba

Connects AI agents to Postgres for health checks, index tuning, query plans, schema-aware SQL, and controlled SQL execution.

Install Postgres MCP

Pick your client, then add it in one click or paste the config.

STDIOPython
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "crystaldba-postgres-mcp": {
      "command": "uvx",
      "args": [
        "postgres-mcp"
      ],
      "env": {
        "DATABASE_URI": "YOUR_VALUE_HERE"
      }
    }
  }
}

Settings → Developer → Edit Config, merge this into mcpServers, then fully quit and reopen Claude Desktop.

Values are written into the snippet above so you can paste it as is. They never leave your browser.

Install not yet sandbox-tested— we haven't run this command through our automated sandbox yet. Not a red flag; we're working through the catalog.

Overview

The crystaldba/postgres-mcp MCP server connects AI agents to PostgreSQL databases for development, testing, deployment, and operations. It provides database health analysis, index tuning, EXPLAIN plan review, hypothetical index analysis, schema-aware SQL generation, and configurable SQL execution. Run it over stdio for local MCP clients or SSE when multiple clients need to share a server. Reach for it when an agent needs database performance and maintenance context beyond a basic connection.

Use cases

  • Inspect database health before production changes
  • Tune indexes for a slow workload
  • Review EXPLAIN plans for inefficient queries
  • Generate SQL using live schema context
  • Restrict agent database access to read-only operations

Key features

  • PostgreSQL health checks
  • Workload-based index tuning
  • EXPLAIN plan and hypothetical index analysis
  • Schema-aware SQL generation
  • Restricted and unrestricted SQL access modes
  • stdio and SSE transports

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked Today

Recent health check succeeded.

30/30 checks healthy over the last 78d

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 10d ago via OSV.dev · postgres-mcp (PyPI)

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars3.4kStargazers on the source repository.
Last commit2mo agoMost recent push to the default branch.
Directory activity5 viewsConfig copies, upvotes, and views on AllMCPs.

How Postgres MCP works

What crystaldba/postgres-mcp does

The crystaldba/postgres-mcp MCP server gives AI agents access to PostgreSQL development and operations workflows. It is intended for work that spans application coding, testing, deployment, and ongoing database maintenance.

Its capabilities cover several areas:

  • Database health analysis, including index health, connection usage, buffer cache, vacuum status, sequence limits, and replication lag.
  • Index tuning across potential index choices for a workload.
  • Query-plan inspection through EXPLAIN plans and testing the possible effect of hypothetical indexes.
  • Schema-aware SQL generation based on information about the connected database.
  • SQL execution with configurable access controls.

These features make it suitable for investigating slow queries, reviewing database conditions, and helping an agent work with an existing PostgreSQL schema.

How it works

The crystaldba/postgres-mcp MCP server connects to a PostgreSQL database using a connection URI supplied through DATABASE_URI. An MCP client starts the process locally through the standard input/output transport, or connects to a server using Server-Sent Events (SSE). SSE can allow multiple MCP clients to use one running server, including clients connecting to a remote host.

Access behavior is selected with an access-mode option. Unrestricted mode permits read and write operations that can change data or schema, making it appropriate for development environments. Restricted mode uses read-only transactions and applies resource limits; the documented limit is execution time, making this mode suited to production use.

Setup and configuration

The crystaldba/postgres-mcp MCP server can run from Docker or Python. Docker is recommended in the project documentation because it includes the required dependencies and may avoid Python environment-specific problems. Python installations can use pipx or uv, and require Python 3.12 or newer.

For a local client configuration, provide the PostgreSQL connection URI as DATABASE_URI and select either --access-mode=unrestricted or --access-mode=restricted. Docker, uvx, pipx, and uv examples are provided by the project. The Docker setup also remaps a database hostname of localhost for connections from the container.

To use SSE, start the process with --transport=sse; the documented Docker example publishes port 8000. The project gives configuration guidance for Claude Desktop and notes that similar settings can be adapted for other MCP clients.

Tools and capabilities

The server exposes database-oriented MCP capabilities rather than general-purpose application tools. Health checks examine operational signals such as connections, caching, vacuum activity, sequences, replication lag, and indexes. Performance workflows combine query-plan review with index experimentation, while schema intelligence supplies database context for generated SQL.

SQL execution is governed by the selected access mode. This is important when connecting an agent to a production database: restricted mode limits the agent to read-only transactions, while unrestricted mode allows changes to data and schema.

Limitations and notes

A usable PostgreSQL connection and valid access credentials are required. The documented prerequisites are either Docker or Python 3.12 or later. The project verifies credentials using tools such as psql or a graphical PostgreSQL client before setup.

The README provides direct configuration instructions for Claude Desktop and adaptation guidance for other clients. It specifically mentions Cursor, Windsurf, Goose, and Qodo Gen, although only clients represented in the directory’s compatibility list are included here. The choice between stdio and SSE depends on whether the server is used locally by one client or shared by multiple clients.

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about Postgres MCP

crystaldba/postgres-mcp is an MCP server that connects AI agents to PostgreSQL databases. Its main tools cover database health checks, index tuning, EXPLAIN plan analysis, hypothetical index testing, schema-aware SQL generation, and controlled SQL execution through restricted or unrestricted access modes.

Install it with Docker, pipx, or uv. Docker uses the `crystaldba/postgres-mcp` image; Python users can run `pipx install postgres-mcp` or `uv pip install postgres-mcp`. Python installation requires version 3.12 or later.

Yes, crystaldba/postgres-mcp works with Cursor.

Use `--access-mode=restricted` instead of `--access-mode=unrestricted`. Restricted mode uses read-only transactions and applies resource limits, including an execution-time constraint documented by the project.

Yes, start it with `--transport=sse`. The documented Docker example publishes port 8000, allowing MCP clients to connect to a shared running server rather than starting a separate local stdio process.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewPostgres MCP AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/crystaldba-postgres-mcp?style=directory)](https://allmcps.com/mcp/crystaldba-postgres-mcp)
HTML Embed
<a href="https://allmcps.com/mcp/crystaldba-postgres-mcp"><img src="https://allmcps.com/api/badge/crystaldba-postgres-mcp?style=directory" alt="Postgres MCP on AllMCPs" /></a>