PostgreSQL MCP Server logo

PostgreSQL MCP Server

Inspect PostgreSQL schemas, run bounded queries, analyze indexes, and expose database metadata through MCP.

Install PostgreSQL MCP Server

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": {
    "postgresql-mcp-server-2": {
      "command": "uvx",
      "args": [
        "mdev-postgresql-mcp-server"
      ],
      "env": {
        "POSTGRES_HOST": "YOUR_VALUE_HERE",
        "POSTGRES_PORT": "YOUR_VALUE_HERE",
        "POSTGRES_USER": "YOUR_VALUE_HERE",
        "POSTGRES_DB": "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 POSTGRES_HOST=YOUR_VALUE_HERE --env POSTGRES_PORT=YOUR_VALUE_HERE --env POSTGRES_USER=YOUR_VALUE_HERE --env POSTGRES_DB=YOUR_VALUE_HERE --transport stdio postgresql-mcp-server-2 -- uvx mdev-postgresql-mcp-server

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

We couldn’t confirm it starts correctly

We hit an unexpected error while testing this listing automatically.

uvx mdev-postgresql-mcp-server

Rate limit exceeded, please try again later - you have reached the maximum number of concurrent E2B sandboxes (20). If you need more, please visit 'https://e2b.dev/docs/billing'

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

PostgreSQL MCP Server MCP server connects MCP-compatible clients to PostgreSQL for schema inspection, querying, and database analysis. It runs over stdio and uses environment variables for the database connection. Read queries run in read-only transactions with a configurable row limit, while a separate write tool can modify data or schema. Use it when an agent needs structured access to PostgreSQL metadata and explicitly controlled SQL execution.

Use cases

  • Inspect public PostgreSQL tables and schemas
  • Run bounded read-only SQL queries
  • Review PostgreSQL query plans
  • Analyze foreign keys and indexes
  • Preview table contents for agent workflows

Key features

  • Public table and schema discovery
  • Bounded read-only SQL execution
  • Single-statement write execution
  • Query plan inspection
  • Foreign-key and index analysis
  • PostgreSQL metadata resources

Tools10

What PostgreSQL MCP Server lets your agent do. Expand a tool for its parameters.

Self-reported~164 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.

12/12 checks healthy over the last 50d

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 5d ago via OSV.dev · mdev-postgresql-mcp-server (PyPI)

Adoption & maintenance

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

GitHub stars1Stargazers on the source repository.
Last commit6mo agoMost recent push to the default branch.
Install checkInconclusiveWe hit an unexpected error running the automated check.
Tools exposed10Callable tools this server registers over MCP.
Directory activity1 viewsConfig copies, upvotes, and views on AllMCPs.

How PostgreSQL MCP Server works

What PostgreSQL MCP Server MCP server does

PostgreSQL MCP Server MCP server exposes PostgreSQL inspection and query operations as MCP tools and resources. It is intended for MCP-compatible hosts such as Claude Desktop, Cursor, Windsurf, Cline, Claude Code, and VS Code. The server connects to one configured PostgreSQL database using host, port, user, database, and optional password settings.

Its read-only capabilities cover public table discovery, column and metadata inspection, bounded SQL queries, query plans, table previews, database summaries, foreign-key relationships, index details, and searches across public SQL routines or functions. It also provides two passive resources: one for public table names and another for a generated schema statement for a selected table.

How it works

The server uses the stdio MCP transport. When started, it reads its connection settings from the process environment and writes Python logs to stderr so protocol messages remain on stdout. Clients invoke the exposed tools through their normal MCP configuration.

postgresql_execute_read_query runs SQL inside PostgreSQL read-only transaction mode, limits the returned rows according to POSTGRES_READ_QUERY_LIMIT, and rolls the transaction back after execution. postgresql_explain_query returns PostgreSQL EXPLAIN output without directly running the target query. postgresql_preview_table returns no more than 10 rows.

A separate write operation accepts one statement from the supported INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, or TRUNCATE categories and commits it when the database user permits the operation. Because it can change data or schema, it should not be automatically approved by the MCP client.

Setup and configuration

PostgreSQL MCP Server MCP server requires Python 3.11 or newer and access to a PostgreSQL database. The published package can be launched with uvx mdev-postgresql-mcp-server. For local development, clone the repository, create a virtual environment, install the project with pip install -e ., and run python -m postgresql_mcp_server.server or the installed console script.

Set POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, and POSTGRES_DB for the connection. POSTGRES_PASSWORD is optional, while LOG_LEVEL defaults to INFO and POSTGRES_READ_QUERY_LIMIT defaults to 1000. The example configuration uses port 5432 and a local host. For shared or public deployments, use a dedicated PostgreSQL user with only the permissions required for the intended operations.

Do not commit environment files or client configurations containing credentials. A read-only role can be granted database connection access, schema usage, and SELECT privileges on the public schema. If write access is available, review generated SQL and require explicit approval before invoking the write tool.

Tools and capabilities

Available tools include:

  • postgresql_list_tables for public base tables.
  • postgresql_describe_table for table columns and metadata.
  • postgresql_execute_read_query for bounded read-only SQL.
  • postgresql_execute_write_query for one modifying SQL statement.
  • postgresql_explain_query for PostgreSQL query plans.
  • postgresql_get_database_summary for the database version and table count.
  • postgresql_get_relationships for foreign-key inspection.
  • postgresql_analyze_indexes for index information and sizes.
  • postgresql_preview_table for a ten-row table sample.
  • postgresql_search_sql_definitions for public routines and functions.

The postgres://list_tables resource exposes public table names, and postgres://schema/{table_name} provides generated schema information for a table.

Limitations and notes

The server focuses on PostgreSQL and the public schema. Read-query safety is bounded by transaction mode and the configured result limit, but SQL review and database permissions remain important. The write tool is destructive and is not restricted to read-only behavior. Without a configured database, only basic source syntax can be checked with Python compilation; database-backed behavior requires starting the server with valid connection settings.

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 PostgreSQL MCP Server

PostgreSQL MCP Server is an MCP server that connects MCP-compatible clients to PostgreSQL databases. Its main tools list tables, describe schemas, run bounded read-only queries, explain query plans, inspect relationships and indexes, preview rows, search SQL definitions, and optionally execute approved write statements.

Install it with `uvx mdev-postgresql-mcp-server`, or clone the repository, create a Python 3.11+ virtual environment, and run `pip install -e .`. Local execution is available through `python -m postgresql_mcp_server.server`.

Set `POSTGRES_HOST`, `POSTGRES_PORT`, `POSTGRES_USER`, and `POSTGRES_DB`. `POSTGRES_PASSWORD` is optional. `LOG_LEVEL` and `POSTGRES_READ_QUERY_LIMIT` are optional settings with defaults of `INFO` and `1000`.

Yes. Cursor is listed as an MCP-compatible client for this server. Configure it with the stdio command `uvx`, the argument `mdev-postgresql-mcp-server`, and the PostgreSQL connection variables.

No. Its read-query tool uses a read-only transaction and rolls back after execution, but a separate write tool accepts one INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, or TRUNCATE statement. Restrict database permissions and require explicit approval for writes.

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