PostgreSQL MCP Server

Python MCP server for PostgreSQL database inspection and querying

Local serverstdioPython

What is the PostgreSQL MCP Server?

Python MCP server for PostgreSQL database inspection and querying

The short version

A Python Model Context Protocol (MCP) server for inspecting and querying PostgreSQL databases from MCP-compatible clients. It provides schema discovery, safe read-only query execution, query explanation, table previews, index analysis, relationship inspection, and PostgreSQL resources for table metadata.

  • List public tables and inspect table schemas
  • Execute read-only SQL in a PostgreSQL read-only transaction
  • Explain query plans without executing the target query directly
  • Preview table rows with a fixed limit
  • Inspect foreign-key relationships and indexes
  • Expose passive MCP resources for table lists and schema details

What it needs from you

  • Python 3.11+ - PostgreSQL database - MCP-compatible client such as Claude Desktop, Cursor, VS Code, or another MCP host

More MCP options

Compare MCP servers by category, or browse hosted MCP servers if you prefer an endpoint over a local process.

Maintainer setup documentation.

Recorded tools

Check the linked publisher documentation and your connected client's tool list. Names and availability can vary with the server version and account permissions.

ToolWhat it does
postgresql_list_tablesList public base tables
postgresql_describe_tableShow columns and metadata for a table
postgresql_execute_read_queryRun bounded SQL under read-only transaction mode
postgresql_execute_write_queryRun a single approved modifying SQL statement and commit
postgresql_explain_queryReturn PostgreSQL EXPLAIN output for a single query
postgresql_get_database_summaryReturn database version and table count
postgresql_get_relationshipsInspect foreign-key relationships
postgresql_analyze_indexesInspect indexes and sizes
postgresql_preview_tableReturn up to 10 rows from a table
postgresql_search_sql_definitionsSearch public SQL routines/functions

How to install the PostgreSQL MCP Server

{
  "mcpServers": {
    "postgresql-server": {
      "command": "uvx",
      "args": ["mdev-postgresql-mcp-server"],
      "env": {
        "POSTGRES_HOST": "your-value",
        "POSTGRES_PORT": "your-value",
        "POSTGRES_USER": "your-value",
        "POSTGRES_PASSWORD": "your-value",
        "POSTGRES_DB": "your-value"
      }
    }
  }
}

Add to claude_desktop_config.json, then restart Claude Desktop.

Configuration

  • Python 3.11+ - PostgreSQL database - MCP-compatible client such as Claude Desktop, Cursor, VS Code, or another MCP host
VariableDescriptionRequired
POSTGRES_HOSTEndpoint or connection string the server talks to.Optional
POSTGRES_PORTConfiguration value read at startup.Optional
POSTGRES_USERConfiguration value read at startup.Optional
POSTGRES_PASSWORDConfiguration value read at startup.Optional
POSTGRES_DBConfiguration value read at startup.Optional

Example prompts to try

  • “Use PostgreSQL to postgresql list tables.”
  • “Use PostgreSQL to postgresql describe table.”
  • “Use PostgreSQL to postgresql execute read query.”

Frequently asked questions

Python MCP server for PostgreSQL database inspection and querying Confirm the tools offered by your installed version in the connected client. Tool availability and permissions depend on the server and account configuration.