Postgres MCP Server

PostgreSQL MCP server - query, schema introspection, explain, and health checks for AI assistants

Local serverstdioGo

What is the Postgres MCP Server?

PostgreSQL MCP server - query, schema introspection, explain, and health checks for AI assistants

What you get

One click adds this to your local Yaw MCP config so it's available in every Yaw Terminal session. Or install manually below.

  • Role-based access as the primary control — - the recommended posture is to use a least-privileged postgres role in DATABASE_URL (e.g. one with GRANT pg_read_all_data); postgres itself then enforces the boundary, no env var needed. See Configuring access
  • Parameterized queries — - pg_query takes a params array for $1, $2, etc. No string-interpolated SQL in our code path
  • Written from scratch, actively maintained — - not a fork of the deprecated code. Unit + integration tests (npm test, npm run test:integration) run against a real Postgres; releases cut via release.sh
  • Schema introspection built in — - pg_list_schemas, pg_list_tables, pg_describe_table return columns, primary keys, foreign keys, and indexes without the agent having to remember pg_catalog joins
  • EXPLAIN as a first-class tool — - text or JSON format, with optional ANALYZE. ANALYZE for non-SELECT statements requires ALLOW_WRITES=1 and always rolls back, so the plan is real but the write doesn't persist
  • Perf diagnostics the deprecated server never had — - pg_top_queries (from pg_stat_statements), pg_seq_scan_tables, pg_unused_indexes, pg_table_bloat, pg_inspect_locks, pg_replication_status. Answer "why is this slow?" in one tool call

More MCP options

Compare MCP servers by category, or browse hosted MCP servers if you prefer an endpoint over a local process.

Maintainer setup documentation.

Recorded tools

Check the linked publisher documentation and your connected client's tool list. Names and availability can vary with the server version and account permissions.

ToolWhat it does
pg_readonlyRun a SQL statement guaranteed read-only - always inside BEGIN READ ONLY, regardless of ALLOW_WRITES. The recommended tool for read access; safe for hosts to auto-allow.
pg_queryRun a SQL query. Writes gated by the role in DATABASE_URL first, ALLOW_WRITES second. Supports parameterized queries via params. Result fields include dataTypeName (e.g. int4, jsonb) alongside dataTypeID.
pg_list_schemasList non-system schemas.
pg_list_tablesList tables (and optionally views) in a schema with estimated row counts. Paginated via limit/offset.
pg_describe_tableKind, columns, PK, outgoing FKs, incoming FKs (referenced_by), CHECK / UNIQUE / EXCLUDE constraints, indexes, and partition parent/children for a relation.
pg_list_viewsList views and materialized views in a schema, including their SQL definitions.
pg_list_functionsList functions, procedures, and aggregates in a schema with signatures and return types.
pg_list_extensionsList installed extensions (pgvector, postgis, pg_stat_statements, etc.) with versions.
pg_search_columnsFind columns by name pattern across all user schemas. Case-insensitive, supports SQL LIKE wildcards.
pg_explainEXPLAIN or EXPLAIN ANALYZE for a SQL statement. Text or JSON output. Optional hypothetical_indexes (requires the [HypoPG](https://github.com/HypoPG/hypopg) extension) lets you ask "what would the plan be with these index
pg_healthServer version, database size, connection count, active queries, table count.
pg_top_queriesTop N queries by total/mean execution time. Requires the pg_stat_statements extension.
pg_seq_scan_tablesTables with heavy sequential scans - missing-index candidates.
pg_unused_indexesNon-unique, non-primary indexes with low scan counts - drop candidates.

How to install the Postgres MCP Server

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@yawlabs/postgres-mcp@latest"],
      "env": {
        "DATABASE_URL": "postgres://user:password@host:5432/dbname"
      }
    }
  }
}

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

Configuration

VariableDescriptionRequired
DATABASE_URLEndpoint or connection string the server talks to.Yes
ALLOW_WRITESConfiguration value read at startup.Optional
POSTGRES_SSL_REJECT_UNAUTHORIZEDConfiguration value read at startup.Optional

Example prompts to try

  • “Use Postgres to pg readonly.”
  • “Use Postgres to pg query.”
  • “Use Postgres to pg list schemas.”

Frequently asked questions

PostgreSQL MCP server - query, schema introspection, explain, and health checks for AI assistants Confirm the tools offered by your installed version in the connected client. Tool availability and permissions depend on the server and account configuration.