mcp-postgres
v0.1.0PostgreSQL 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.
| Parameter | Type | Description |
|---|---|---|
includeSystem | boolean | Include pg_catalog / information_schema (default false) |
schema | string | Only 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.
| Parameter | Type | Description |
|---|---|---|
schema * | string | Schema name, e.g. public |
table * | string | Table 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.
| Parameter | Type | Description |
|---|---|---|
schema * | string | Schema name |
table * | string | Table or view name |
columns | array | Columns to return (default all) |
limit | integer | Max rows (capped at POSTGRES_MAX_ROWS) |
orderBy | array | Sort order, e.g. [{ "column": "created_at", "desc": true }] |
where | object | Equality 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.
| Parameter | Type | Description |
|---|---|---|
sql * | string | A single read statement, e.g. SELECT id, total FROM orders WHERE status = $1 |
params | array | Values 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.
| Parameter | Type | Description |
|---|---|---|
sql * | string | The statement to explain |
analyze | boolean | Run EXPLAIN ANALYZE, BUFFERS (read statements only; default false) |
params | array | Values 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).
| Parameter | Type | Description |
|---|---|---|
includeIdle | boolean | Include 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.
| Parameter | Type | Description |
|---|---|---|
limit | integer | How many (default 20) |
orderBy | string | Rank 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.