Skip to content
MCP server

PostgreSQL MCP Server

Query PostgreSQL, inspect schemas and read EXPLAIN plans, read-only by default

Runs locallyStatus and history
Pricing
Open source
Platforms
CLI
Runs
Locally
Version
0.13.13
Listing updated
3 days ago

About PostgreSQL MCP Server

PostgreSQL MCP Server is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.

Writes are off unless you set ALLOW_WRITES=1, so an agent cannot silently drop tables; the connection string goes in a DATABASE_URL variable and the page recommends a least-privileged role. The site argues that Anthropic's reference Postgres server was archived and has a documented stacked-query injection, and presents this one as written from scratch.

Beyond parameterised SQL it covers schema and view introspection, EXPLAIN with actual timings, and diagnostics that otherwise need hand-written pg_catalog joins: top queries from pg_stat_statements, unused indexes, sequential-scan tables, locks with blocking and blocked PIDs, and extension checks such as pgvector.

The page shows chained jobs, for example inspecting locks and cancelling the blocker, or ranking slow queries and then explaining the worst. MIT, from Yaw Labs, on npm.

Install

Run in a terminal

claude mcp add postgres-mcp -- npx -y @yawlabs/postgres-mcp

Add to claude_desktop_config.json

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@yawlabs/postgres-mcp"
      ]
    }
  }
}
Install in CursorOpens Cursor, which asks you to confirm. Or add it by hand:

Add to ~/.cursor/mcp.json

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@yawlabs/postgres-mcp"
      ]
    }
  }
}
Install in VS CodeOpens VS Code, which asks you to confirm. Or add it by hand:

Add to .vscode/mcp.json

{
  "servers": {
    "postgres-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@yawlabs/postgres-mcp"
      ]
    }
  }
}

Add to ~/.codeium/windsurf/mcp_config.json

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@yawlabs/postgres-mcp"
      ]
    }
  }
}

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

{
  "mcpServers": {
    "postgres-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@yawlabs/postgres-mcp"
      ]
    }
  }
}

Tools this server provides (13)

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

pg_query
Run parameterised SQL.
pg_list_schemas
List schemas.
pg_list_tables
List tables.
pg_list_views
List views.
pg_list_functions
List functions.
pg_list_extensions
List installed extensions.
pg_describe_table
Describe a table with columns, keys, constraints and indexes.
pg_explain
Show the plan for a query.
pg_index_advisor
Suggest indexes.
pg_inspect_locks
Show blocked and blocking processes.
pg_seq_scan_tables
Find tables read with sequential scans.
pg_unused_indexes
List non-unique, non-primary indexes with low scan counts.
pg_top_queries
Show top queries from pg_stat_statements.

What it does

Read-only default
Writes require an explicit environment variable.
Schema introspection
Describes columns, keys, constraints and indexes.
Plans with timings
EXPLAIN with actual row counts and timing, plus index advice.
Performance diagnostics
Top queries, unused indexes and seq-scan tables.
Lock inspection
Shows blocked and blocking processes.
Extension checks
Reports whether extensions like pgvector are installed.

Good for

  • Describe a table and its indexes
  • Find why a query is slow
  • Triage a hung app by locks
  • Spot unused indexes before a cleanup
  • Run oncall health checks

Pricing

Open source

MIT licence

Prices change. Check yaw.sh before you buy.

PostgreSQL MCP Server FAQ

Can the agent change data?

Not by default; add ALLOW_WRITES=1 to allow it.

How do I connect?

Set DATABASE_URL in the MCP config env block.

On Windows?

Wrap the command in cmd /c.

Is PostgreSQL MCP Server free?

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

How do I add PostgreSQL MCP Server to Claude Code?

Run this command in your terminal: claude mcp add postgres-mcp -- npx -y @yawlabs/postgres-mcp

What are the best alternatives to PostgreSQL MCP Server?

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

Alternatives to PostgreSQL MCP Server

  1. REA

    MCP server

    CLI and MCP server that lets coding agents reverse engineer apps and binaries

    Runs locally
    • Open source
    • 464K GitHub stars
    • Developer tools
  2. Codebase Memory

    MCP server

    Local MCP server that builds a code knowledge graph for AI coding agents

    Runs locally
    • Open source
    • 48.7K GitHub stars
    • Knowledge and memory
  3. GitHub

    MCP server

    Official MCP server connecting AI assistants to GitHub repos, issues and workflows

    Not checked yet
    • Remote
    • Open source
    • 34.5K GitHub stars
    • Developer tools
  4. MCP toolkit giving coding agents symbol-level code retrieval and editing

    Runs locally
    • Open source
    • 31.5K GitHub stars
    • Developer tools
  5. XERJ

    MCP server

    Local search engine for AI agents with cited answers over your code and docs

    Runs locally
    • Open source
    • 19.2K GitHub stars
    • Knowledge and memory
  6. Ouroboros

    MCP server

    Spec-first layer that pins requirements and verifies results of AI coding agent work

    Runs locally
    • Open source
    • 6.4K GitHub stars
    • Developer tools