================== /// 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.
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 details about a specific database object, such as a table’s columns, constraints, and indexes.
execute_sql
Executes SQL statements on the database, honoring read-only limitations when in restricted mode.
explain_query
Retrieves the execution plan for a SQL query and can simulate plans with hypothetical indexes.
get_top_queries
Reports the slowest SQL queries based on execution time using pg_stat_statements data.
analyze_workload_indexes
Analyzes the overall workload to find heavy queries and recommends optimal indexes.
analyze_query_indexes
Analyzes up to 10 provided SQL queries and recommends optimal indexes for them.
analyze_db_health
Performs comprehensive health checks covering cache hit rates, connections, constraints, index health, sequence limits, and vacuum status.
Installation
pip install postgres-mcp # pulls the latest release from PyPI
git clone https://github.com/crystaldba/postgres-mcp.git
cd postgres-mcp
pip install -e .
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
mcp serve --config mcp.yml # or simply `mcp serve` if you rely on env-vars
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
pip install -U postgres-mcp # upgrades to the latest version