mcp-postgres

v0.1.0
io.github.dockndevai/mcp-postgres Checked 14 hours ago Published 9 days ago

PostgreSQL schema exploration, read-only SQL & governed changes for AI agents.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

get_server_info Server info

PostgreSQL version, current database and role, database size, uptime, and whether it is a replica.

list_schemas List schemas

List schemas with owner and relation count (filtered to POSTGRES_SCHEMA_ALLOWLIST when set).

list_tables List tables

List tables, views, and materialized views with estimated row counts and on-disk size.

ParameterTypeDescription
includeSystembooleanInclude pg_catalog / information_schema (default false)
schemastringOnly this schema (default: every allowed non-system schema)

describe_table Describe table

Columns (type, nullability, default), constraints, indexes (with scan counts), size, and estimated rows.

ParameterTypeDescription
schema *stringSchema name, e.g. public
table *stringTable or view name

select_rows Select rows

Read rows from one table with equality filters — no SQL needed, and held to the schema allowlist. Results are capped at POSTGRES_MAX_ROWS; secret-like columns are redacted.

ParameterTypeDescription
schema *stringSchema name
table *stringTable or view name
columnsarrayColumns to return (default all)
limitintegerMax rows (capped at POSTGRES_MAX_ROWS)
orderByarraySort order, e.g. [{ "column": "created_at", "desc": true }]
whereobjectEquality filters, e.g. { "status": "open", "deleted_at": null }

run_query Run read-only query

Run one SELECT / WITH / VALUES / TABLE / SHOW statement inside a READ ONLY transaction that is always rolled back. Use $1, $2 … placeholders with `params` for values. Results are capped at POSTGRES_MAX_ROWS. Refused while POSTGRES_SCHEMA_ALLOWLIST is set (free-form SQL can reach any schema) — use select_rows then.

ParameterTypeDescription
sql *stringA single read statement, e.g. SELECT id, total FROM orders WHERE status = $1
paramsarrayValues for $1, $2 … placeholders

explain_query Explain query plan

Show the planner's JSON plan for one statement (SELECT/WITH/VALUES/TABLE, or INSERT/UPDATE/DELETE/MERGE — not executed). `analyze: true` executes read statements inside a rolled-back READ ONLY transaction for real timings. Refused while POSTGRES_SCHEMA_ALLOWLIST is set.

ParameterTypeDescription
sql *stringThe statement to explain
analyzebooleanRun EXPLAIN ANALYZE, BUFFERS (read statements only; default false)
paramsarrayValues for $1, $2 … placeholders

list_active_queries Active queries

Sessions from pg_stat_activity: role, state, wait event, transaction/query age, and query text (inline secrets masked).

ParameterTypeDescription
includeIdlebooleanInclude idle sessions (default false)

get_database_stats Database stats

Connections by state, commits/rollbacks, deadlocks, temp usage, cache hit ratio, and key memory settings.

get_top_queries Top queries

Most expensive statements from pg_stat_statements (requires the extension), with inline secrets masked.

ParameterTypeDescription
limitintegerHow many (default 20)
orderBystringRank by (default total_time)

list_roles List roles

Roles with their attributes (superuser, login, replication, bypass RLS …) and memberships. Never returns passwords.

list_extensions List extensions

Installed extensions with their version, schema, and the newest available version.