mcp-registry/postgres-mcp

    ==================
      
       /// MCP ///
      /// POS ///
        
    ==================
        
    [server:online]
    [protocol:ready]

postgres-mcp

by crystaldba

Postgres MCP Pro – a Python-based Model Context Protocol (MCP) server that adds Postgres health checks, index tuning, explain-plan analysis and safe SQL execution for AI agents.

813
89
Open Source

01

list_schemas

Lists all database schemas available in the PostgreSQL instance.

02

list_objects

Lists database objects (tables, views, sequences, extensions) within a specified schema.

03

get_object_details

Provides details about a specific database object, such as a table’s columns, constraints, and indexes.

04

execute_sql

Executes SQL statements on the database, honoring read-only limitations when in restricted mode.

05

explain_query

Retrieves the execution plan for a SQL query and can simulate plans with hypothetical indexes.

06

get_top_queries

Reports the slowest SQL queries based on execution time using pg_stat_statements data.

07

analyze_workload_indexes

Analyzes the overall workload to find heavy queries and recommends optimal indexes.

08

analyze_query_indexes

Analyzes up to 10 provided SQL queries and recommends optimal indexes for them.

09

analyze_db_health

Performs comprehensive health checks covering cache hit rates, connections, constraints, index health, sequence limits, and vacuum status.

Installation

1. Prerequisites
• Python 3.9+ and a running PostgreSQL instance you can reach over the network.
• Make sure the Postgres role you will use has CONNECT, SELECT, INSERT, UPDATE, DELETE privileges on the target database.
2. Install the package (recommended)
pip install postgres-mcp # pulls the latest release from PyPI
– or build from source
git clone https://github.com/crystaldba/postgres-mcp.git cd postgres-mcp pip install -e .
3. Basic configuration
Export the connection details so MCP can open a session:
export PGHOST=localhost export PGPORT=5432 export PGUSER=my_role export PGPASSWORD=my_password export PGDATABASE=my_db # optional export MCP_PORT=8686 # TCP port MCP will listen on export MCP_ALLOW_WRITE=true # "false" to start in read-only mode
You can also create a YAML file (`mcp.yml`) instead of using env-vars.
4. Launch the server
mcp serve --config mcp.yml # or simply `mcp serve` if you rely on env-vars
The service now listens on http://localhost:8686 and exposes the MCP JSON end-points your AI agents can call.
5. Docker alternative (no Python required)
docker run -d --name postgres-mcp \ -e PGHOST=$PGHOST -e PGPORT=$PGPORT -e PGUSER=$PGUSER -e PGPASSWORD=$PGPASSWORD -e PGDATABASE=$PGDATABASE \ -p 8686:8686 crystaldba/postgres-mcp:latest
6. Updating
pip install -U postgres-mcp # upgrades to the latest version

Documentation

License: MIT License
Updated 7/30/2025

Table of Contents