Postgres MCP MCP Server

<h3>A Postgres MCP server with index tuning, explain plans, health checks, and safe sql execution.</h3>

Local serverstdioPython

What is the Postgres MCP MCP server?

What it actually does

Postgres MCP Pro does much more than wrap a database connection.

Its toolset

Everything the assistant can do here goes through one of these:

  • list_schemas — Lists all database schemas available in the PostgreSQL instance
  • list_objects — Lists database objects (tables, views, sequences, extensions) within a specified schema
  • get_object_details — Provides information about a specific database object, for example, a table's columns, constraints, and indexes
  • execute_sql — Executes SQL statements on the database, with read-only limitations when connected in restricted mode
  • explain_query — Gets the execution plan for a SQL query describing how PostgreSQL will process it and exposing the query planner's cost model. Can be invoked with
  • get_top_queries — Reports the slowest SQL queries based on total execution time using pg_stat_statements data
  • analyze_workload_indexes — Analyzes the database workload to identify resource-intensive queries, then recommends optimal indexes for them
  • analyze_query_indexes — Analyzes a list of specific SQL queries (up to 10) and recommends optimal indexes for them
  • analyze_db_health — Performs comprehensive health checks including: buffer cache hit rates, connection health, constraint validation, index health
  • Prerequisites — Before getting started, ensure you have: 1. Access credentials for your database. 2. Docker or Python 3.12 or higher
  • Installation — Choose one of the following methods to install Postgres MCP Pro:

Adding it to your client

Installation goes through your MCP client rather than a global install: point it at postgres-mcp on PyPI and it is fetched when the client starts. The copy-paste blocks for Claude Desktop, Claude Code and Cursor are further down this page.

Configuration

You will need one environment variable: DATABASE_URI. Keep credentials in your client's env block or a secrets manager rather than in a file you might commit.

Before getting started, ensure you have: 1. Access credentials for your database. 2. Docker or Python 3.12 or higher.

When to reach for it

Among the database access options, the useful question is rarely "what can it do" but "what does it cost you to run" — permissions, credentials, and how much of your context its toolset consumes. Postgres MCP's toolset — list_schemas, list_objects, get_object_details and 8 more — is a fair guide to whether it matches your workflow. It is maintained by crystaldba; worth a glance at recent repository activity before you build anything load-bearing on it.

This entry was verified against Postgres MCP's own documentation before publication; SyncDev keeps the directory reviewed rather than auto-generated.

Caveats

  • It runs with your machine's permissions. That is convenient and also the reason to think about what you point it at before you approve a tool call.
  • With 11 tools registered it takes up a noticeable share of the context window; turn it off in projects that never touch Postgres MCP.
  • MCP clients confirm each tool call by default. Leave that on until you have watched what the postgres mcp mcp server does with a few real requests.

Available tools

ToolWhat it does
list_schemasLists all database schemas available in the PostgreSQL instance.
list_objectsLists database objects (tables, views, sequences, extensions) within a specified schema.
get_object_detailsProvides information about a specific database object, for example, a table's columns, constraints, and indexes.
execute_sqlExecutes SQL statements on the database, with read-only limitations when connected in restricted mode.
explain_queryGets the execution plan for a SQL query describing how PostgreSQL will process it and exposing the query planner's cost model. Can be invoked with hypothetical indexes to simulate the behavior after adding indexes.
get_top_queriesReports the slowest SQL queries based on total execution time using pg_stat_statements data.
analyze_workload_indexesAnalyzes the database workload to identify resource-intensive queries, then recommends optimal indexes for them.
analyze_query_indexesAnalyzes a list of specific SQL queries (up to 10) and recommends optimal indexes for them.
analyze_db_healthPerforms comprehensive health checks including: buffer cache hit rates, connection health, constraint validation, index health (duplicate/unused/invalid), sequence limits, and vacuum health.
PrerequisitesBefore getting started, ensure you have: 1. Access credentials for your database. 2. Docker *or* Python 3.12 or higher.
InstallationChoose one of the following methods to install Postgres MCP Pro:

How to install the Postgres MCP MCP server

##### If you are using `pipx`

```json
{
  "mcpServers": {
    "postgres": {
      "command": "postgres-mcp",
      "args": [
        "--access-mode=unrestricted"
      ],
      "env": {
        "DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
      }
    }
  }
}

Configuration as documented by the project. Restart the client after saving.

Configuration

Before getting started, ensure you have: 1. Access credentials for your database. 2. Docker or Python 3.12 or higher.

VariableDescriptionRequired
DATABASE_URIConfiguration value read at startup.Optional

Example prompts to try

  • Use Postgres MCP to list schemas.
  • Use Postgres MCP to list objects.
  • Use Postgres MCP to get object details.

Frequently asked questions

It connects Postgres MCP to MCP-compatible AI assistants such as Claude and Cursor, exposing 11 tools (list_schemas, list_objects, get_object_details, and more) that the assistant can call on your behalf. Instead of copying data back and forth by hand, the assistant works with Postgres MCP directly.