HomeDatabases & Data › PostgreSQL

PostgreSQL

MCP server for PostgreSQL: local, Docker, RDS, Neon, Supabase, or behind an SSH bastion.

TypeScript CloudLocal macOSWindowsLinux
★ 23 stars Last pushed 2026-09-16 License: MIT

Topics: Databases

Connect

Review any command before running it. Package names and URLs come from the server's own registry entry.

Package (npm 0.3.1)

npx -y mcp-postgres-server@0.3.1

Or add to your MCP client config:

{
  "mcpServers": {
    "mcp-postgres-server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-postgres-server@0.3.1"
      ],
      "env": {
        "DATABASE_URL": "<YOUR_VALUE>",
        "PG_HOST": "<YOUR_VALUE>",
        "PG_PORT": "<YOUR_VALUE>",
        "PG_USER": "<YOUR_VALUE>",
        "PG_PASSWORD": "<YOUR_VALUE>",
        "PG_DATABASE": "<YOUR_VALUE>",
        "PG_ALLOW_WRITE": "<YOUR_VALUE>",
        "PG_SSLMODE": "<YOUR_VALUE>",
        "PG_SSL_CA": "<YOUR_VALUE>",
        "PG_ENABLE_RUNTIME_CONNECT": "<YOUR_VALUE>",
        "PG_MAX_RESULT_BYTES": "<YOUR_VALUE>",
        "PG_STATEMENT_TIMEOUT": "<YOUR_VALUE>",
        "PG_CONNECT_TIMEOUT": "<YOUR_VALUE>",
        "PG_SSH_HOST": "<YOUR_VALUE>",
        "PG_SSH_PORT": "<YOUR_VALUE>",
        "PG_SSH_USER": "<YOUR_VALUE>",
        "PG_SSH_PRIVATE_KEY": "<YOUR_VALUE>",
        "PG_SSH_PASSPHRASE": "<YOUR_VALUE>",
        "PG_SSH_AGENT": "<YOUR_VALUE>",
        "PG_SSH_PASSWORD": "<YOUR_VALUE>",
        "PG_SSH_FINGERPRINT": "<YOUR_VALUE>",
        "PG_SSH_KEEPALIVE_INTERVAL": "<YOUR_VALUE>"
      }
    }
  }
}
  • DATABASE_URL secret — Full connection string (preferred). Supports sslmode in the URL.
  • PG_HOST — Database host (fallback when DATABASE_URL is not set).
  • PG_PORT — Database port.
  • PG_USER — Database user.
  • PG_PASSWORD secret — Database password.
  • PG_DATABASE — Database name.
  • PG_ALLOW_WRITE — When true, execute performs writes and reads are sent directly. Off (default) is read-only: execute refuses writes and each read runs in a READ ONLY transaction.
  • PG_SSLMODE — TLS mode. require/allow/prefer encrypt without verifying the certificate; verify-ca/verify-full verify it (supply a CA via PG_SSL_CA). Unlike libpq, allow/prefer do not fall back to plaintext, so a server without TLS needs disable.
  • PG_SSL_CA — Path to a CA certificate file. Setting it by itself implies verify-full.
  • PG_ENABLE_RUNTIME_CONNECT — Register the connect_db tool (runtime credential switching).
  • PG_MAX_RESULT_BYTES — Byte budget for a query result sent to the model. Whole rows are kept while they fit; over the budget returnedRows < rowCount and truncated is true.
  • PG_STATEMENT_TIMEOUT — Statement timeout in milliseconds, applied to every session.
  • PG_CONNECT_TIMEOUT — Timeout in milliseconds for a single connect attempt (raise it for slow links or SSH tunnels).
  • PG_SSH_HOST — SSH bastion host. Setting it enables tunneling: the server reaches the database only through an SSH tunnel to this host. Needs the ssh2 optional dependency.
  • PG_SSH_PORT — SSH bastion port.
  • PG_SSH_USER — SSH username.
  • PG_SSH_PRIVATE_KEY — Path to a private key file. If unset, auth falls back like ssh: a running agent (SSH_AUTH_SOCK), then a default key (~/.ssh/id_ed25519, id_rsa, id_ecdsa).
  • PG_SSH_PASSPHRASE secret — Passphrase for the private key, if encrypted.
  • PG_SSH_AGENT — true to use the ambient agent (SSH_AUTH_SOCK), or an explicit socket path / Windows named pipe.
  • PG_SSH_PASSWORD secret — SSH login password. Opt-in; a key or agent takes precedence. Prefer keys, a bastion often disables password auth.
  • PG_SSH_FINGERPRINT — Pinned host-key fingerprint (SHA256:...). Host-key verification is mandatory and set only this way: without it the tunnel refuses to connect. Get it with ssh-keygen -lF host.
  • PG_SSH_KEEPALIVE_INTERVAL — SSH keepalive interval in ms; the tunnel drops after 3 unanswered keepalives, and the next call reconnects.

Related servers

Listed in punkpeye/awesome-mcp-servers (MIT)

Data from the Official MCP Registry