Postgres logo

Postgres

Query PostgreSQL, inspect schemas and tables, and review query plans through MCP with read-only defaults.

Install Postgres

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

STDIONode.js
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-pg-server"
      ],
      "env": {
        "DATABASE_URL": "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.

Claude Code command
claude mcp add --env DATABASE_URL=YOUR_VALUE_HERE --transport stdio postgres -- npx -y mcp-pg-server

Run in your terminal. Add --scope project to share it with your team through .mcp.json.

We couldn’t confirm it starts correctly

The install command installed and started the server, which then stopped for configuration (such as an API key) that our sandbox does not have — expected for servers that connect to your account.

npx -y mcp-pg-server

No response to initialize.

This is an experimental automated check and can have false negatives — missing environment variables, a slow cold install, etc. It doesn’t necessarily mean something’s wrong. Last checked .

Overview

The postgres MCP server lets AI assistants query PostgreSQL databases, inspect schemas and table metadata, and review execution plans. It runs with npx and connects through DATABASE_URL or a per-call connectionString override. Read-only mode permits SELECT, WITH, EXPLAIN, SHOW, and ANALYZE; enable writes only when needed. Use it for local or development databases when database exploration from an MCP client is more convenient than switching tools.

Use cases

  • Query development data from an AI assistant
  • Inspect tables and columns before writing SQL
  • Compare PostgreSQL query execution plans
  • List schemas in a local database
  • Check table row counts

Key features

  • PostgreSQL SQL queries with read-only defaults
  • Schema and table metadata inspection
  • Text-format EXPLAIN plans
  • Per-call connection overrides
  • Support for local and development databases

Tools5

What Postgres lets your agent do. Expand a tool for its parameters.

Self-reported~78 tokens of context

Security & health

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

ActiveLast checked

Recent health check succeeded.

17/17 checks healthy over the last 89d

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 5d ago via OSV.dev · mcp-pg-server (npm)

Adoption & maintenance

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

npm downloads186Package downloads in the last 30 days.
Last commit3mo agoMost recent push to the default branch.
Install checkRunsOur sandbox started it; it then asked for an API key or config.
Tools exposed5Callable tools this server registers over MCP.
Directory activity8 viewsConfig copies, upvotes, and views on AllMCPs.

How Postgres works

What postgres MCP server does

The postgres MCP server exposes PostgreSQL inspection and query operations to MCP-compatible AI clients. It can execute supported SQL and return results as a text table, list non-system schemas, inspect the tables within a schema, describe one table in detail, and produce PostgreSQL execution plans.

The tool set is oriented toward local development and database exploration. It supports questions such as which schemas exist, what columns a table contains, how many rows it has, or how PostgreSQL plans to run a query.

How it works

The package runs as an MCP process through npx mcp-pg-server. A client starts it with a PostgreSQL connection supplied in the DATABASE_URL environment variable. Individual tool calls may instead provide a connectionString, which overrides the environment-level connection for that call.

The query operation accepts SELECT, WITH, EXPLAIN, SHOW, and ANALYZE statements when read-only mode is active. The schema operation reports tables for a selected schema, using public by default, along with columns and approximate row counts. table_info provides column types, nullability or defaults, primary-key information, and an exact row count for one table.

The separate explain operation runs PostgreSQL EXPLAIN (FORMAT TEXT) and can optionally include ANALYZE. list_schemas returns non-system schemas.

Setup and configuration

Install requirements through the package runner and configure the client to launch npx with mcp-pg-server. Set DATABASE_URL to a PostgreSQL URL, for example a local database connection. The README provides configurations for Cursor, Claude Desktop, and VS Code.

A typical connection uses this environment variable:

  • DATABASE_URL: PostgreSQL connection URL used by default.

For one-off connections, pass connectionString in the relevant tool call instead of changing the process environment. This can be useful when an assistant needs to inspect a different database during a session.

Tools and capabilities

The postgres MCP server provides five tools:

  • query: Executes supported SQL and formats the result as text.
  • schema: Lists tables, columns, and approximate row counts for a schema.
  • table_info: Shows detailed metadata and an exact row count for one table.
  • explain: Returns a text execution plan, with optional ANALYZE.
  • list_schemas: Lists non-system schemas.

Read-only behavior is enabled by default. Setting readonly=false permits INSERT, UPDATE, DELETE, and DDL through the query path. That setting changes the safety boundary, so it should be used only when write access is intended.

Limitations and notes

This postgres MCP server is aimed at local and development PostgreSQL use rather than enterprise database administration. Read-only mode restricts query statements to SELECT, WITH, EXPLAIN, SHOW, and ANALYZE. Row counts are approximate in schema output but exact in table_info output. Query results are returned as text tables, and execution plans use PostgreSQL's text format.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

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

Frequently Asked Questions about Postgres

postgres is an MCP server that connects AI assistants to PostgreSQL databases through DATABASE_URL or a per-call connectionString. Its main tools query supported SQL, list schemas, inspect schema and table metadata, and run text-format EXPLAIN plans. Read-only mode is enabled by default, with writes available through configuration.

Run it with npx mcp-pg-server and provide a PostgreSQL URL through DATABASE_URL. Add that command and environment variable to your MCP client configuration. The README includes setup examples for Cursor, Claude Desktop, and VS Code.

Yes, postgres works with Cursor through its MCP configuration. Add an entry that launches npx with the mcp-pg-server argument and set DATABASE_URL to the PostgreSQL connection URL.

Set readonly=false to allow writes through the query tool. Without that setting, query accepts SELECT, WITH, EXPLAIN, SHOW, and ANALYZE only; enabling writes also permits INSERT, UPDATE, DELETE, and DDL.

Pass connectionString on the tool call to override DATABASE_URL for that request. This lets an individual operation use a different PostgreSQL connection without changing the server's default environment configuration.

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 AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/postgres?style=directory)](https://allmcps.com/mcp/postgres)
HTML Embed
<a href="https://allmcps.com/mcp/postgres"><img src="https://allmcps.com/api/badge/postgres?style=directory" alt="Postgres on AllMCPs" /></a>