postgres-mcp is a Rust stdio Model Context Protocol server for PostgreSQL.
It is designed for low-latency agent workflows, practical compatibility with
the Python postgres-mcp tool surface, and safe defaults around database
connectivity and SQL execution.
The default startup path is lazy: the process can initialize and advertise MCP tools without requiring immediate database network I/O. Database connectivity is validated on first use unless a stricter startup mode is configured.
- Stdio transport only; no HTTP listener is exposed.
- Lazy DB startup by default for spawn-per-request clients.
- Schema discovery, read-query, render, export, health, and advisor tools.
- Compatibility SQL surfaces remain available where needed.
- Mutating SQL is opt-in through
admin_sqland explicit configuration. execute_sqlis hidden from discovery by default to reduce accidental use.- TLS and
sslmodeparsing fail closed for ambiguous or downgrade-prone input. - Redaction-first telemetry avoids leaking raw database URIs, passwords, or SQL payloads.
Install Rust, make sure any companion toolkit crates required by Cargo.toml
are available at their configured local paths, then build:
cargo buildRun over stdio with a local development database:
DATABASE_URI='postgresql://user:pass@localhost:5432/app?sslmode=disable' \
cargo run -- --startup-db-connect=backgroundFor verified TLS, prefer sslmode=verify-full:
DATABASE_URI='postgresql://user:pass@db.example.com:5432/app?sslmode=verify-full' \
cargo run -- --startup-db-connect=backgroundSee Getting Started for client configuration, startup modes, and smoke checks.
- Getting Started: local setup, stdio launch, and first smoke checks.
- Tool Guide: public tool groups, recommended read paths, compatibility surfaces, and examples.
- Security Model: SQL safety, credential handling, TLS, telemetry, and extension boundaries.
- Build Helper MCP: optional preset-based validation for shared or remote runner environments.
- Release Checklist: public release validation and publication hygiene.
- Migration and Rollout Guide: guidance for moving
from Python
postgres-mcpto this Rust stdio server. - Compatibility Lifecycle: policy for compatibility aliases and deprecations.
- Payload v2 Contract: legacy compatibility
envelope details for
execute_sql. - Dependency Governance: dependency review and validation expectations.
- Negative Validation Pack: resilience checks for malformed inputs, retry pressure, and backpressure behavior.
- Security Policy: vulnerability reporting.
- Contributing: development and documentation workflow.
Schema and metadata:
list_schemaslist_objectsget_object_details
Structured read paths:
query_sqlquery_tuplesrender_sqlexport_sqldescribe_sql
Session and async compatibility:
session_opensession_statussession_closequery_startquery_start_and_waitquery_statusquery_cancel
Administrative and compatibility surfaces:
admin_sqlwhen explicitly enabled.execute_sqlwhen explicitly exposed.query_job_start,export_job_start,job_status, andjob_cancelas deprecated compatibility tools.
Advisor and health tools:
explain_queryget_top_queriesanalyze_db_healthanalyze_query_indexesanalyze_workload_indexes
Prefer query_sql, query_tuples, render_sql, and export_sql for new
agent-facing read workflows. Reserve execute_sql for compatibility or
advanced payload controls.
Database connection:
DATABASE_URI- Positional database URI argument
Access mode:
--access-mode restrictedis the default read-oriented mode.--access-mode unrestrictedallows unrestricted SQL execution for explicitly enabled administrative paths.--enable-admin-sqlorPOSTGRES_MCP_ENABLE_ADMIN_SQL=1exposesadmin_sql.--expose-execute-sqlorPOSTGRES_MCP_EXPOSE_EXECUTE_SQL=1exposesexecute_sqlin discovery.
Startup DB connection mode:
--startup-db-connect backgroundis the default lazy mode.--startup-db-connect warnprobes on startup and continues on failure.--startup-db-connect fail-fastexits when the startup DB probe fails.
TLS behavior:
sslmode=disableuses plain TCP.sslmode=requireis rejected unless--allow-insecure-tlsorPOSTGRES_MCP_ALLOW_INSECURE_TLS=1is set.sslmode=verify-caandsslmode=verify-fulluse native trust roots plus optionalsslrootcert=<path>.sslmode=prefer, duplicatesslmode, and duplicatesslrootcertvalues are rejected.
Metadata policy:
--metadata-policy-mode full|limited|denied--metadata-schema-allow <schema>repeatable--metadata-schema-deny <schema>repeatable
See Security Model for the safety posture behind these defaults.
For behavior changes, use the smallest validation that proves the change. When a Build Helper MCP runner is available, the documented presets provide an auditable execution surface:
postgres-mcp.test
postgres-mcp.build
postgres-mcp.deferred-tool-discovery-smoke
postgres-mcp.integration-matrix-check
Local fallback commands are documented in Build Helper MCP and Release Checklist. Documentation-only changes can usually be validated with:
git diff --checkLicensed under the Apache License, Version 2.0. See LICENSE.