MCP Hub
Back to servers

postgresql-ssh-mcp

PostgreSQL MCP server with SSH tunneling for Claude Desktop and ChatGPT

Stars
2
Tools
12
Updated
Dec 28, 2025
Validated
Jan 9, 2026

PostgreSQL SSH MCP Server

npm version npm downloads license

A secure PostgreSQL MCP server with built-in SSH tunneling. Connect to databases through bastion hosts automatically — no manual ssh -L required.

Features

  • Dual Transport — STDIO for Claude Desktop, Streamable HTTP for ChatGPT
  • SSH Tunneling — Built-in tunnel with auto-reconnect and TOFU (trust on first use)
  • Read-Only by Default — Safe for production; enable writes explicitly
  • OAuth Support — Auth0 integration for secure ChatGPT connections
  • Connection Pooling — Efficient resource management with configurable limits

Architecture

Architecture


Quick Start

Claude Desktop (STDIO)

Add to your Claude Desktop config:

PlatformConfig Location
macOS~/Library/Application Support/Claude/claude_desktop_config.json
Windows%APPDATA%/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@zlash65/postgresql-ssh-mcp"],
      "env": {
        "DATABASE_URI": "postgresql://user:password@localhost:5432/mydb"
      }
    }
  }
}

ChatGPT (Streamable HTTP)

DATABASE_URI="postgresql://user:pass@localhost:5432/mydb" npx @zlash65/postgresql-ssh-mcp-http

Then configure ChatGPT to connect to https://your-subdomain.example.com/mcp.

Note: ChatGPT requires HTTPS. Use a tunnel (ngrok, Cloudflare Tunnel) for local testing.


Available Tools

Query Tools

ToolDescription
execute_queryExecute SQL with parameterized queries. Results capped by MAX_ROWS.
explain_queryGet EXPLAIN plans in text, JSON, YAML, or XML format. Supports ANALYZE.

Schema Tools

ToolDescription
list_schemasList database schemas. Excludes system schemas by default.
list_tablesList tables with row counts and sizes. Optionally include views.
describe_tableGet columns, constraints, and indexes for a table.
list_databasesList all databases with owner, encoding, and size.

Admin Tools

ToolDescription
get_connection_statusGet pool stats, tunnel state, and connection info.
list_active_connectionsShow active connections from pg_stat_activity.
list_long_running_queriesFind queries running longer than a threshold.
get_database_versionGet PostgreSQL server version.
get_database_sizeGet database size and largest tables.
get_table_statsGet vacuum/analyze stats and scan counts for a table.

Environment Variables

Database Connection

VariableRequiredDefaultDescription
DATABASE_URIYes*Full connection string (e.g., postgresql://user:pass@host:5432/db)
DATABASE_HOSTYes*Database hostname
DATABASE_PORTNo5432Database port
DATABASE_NAMEYes*Database name
DATABASE_USERYes*Database username
DATABASE_PASSWORDYes*Database password

*Either DATABASE_URI or all individual connection variables are required.

SSL Configuration

VariableDefaultDescription
DATABASE_SSLAutotrue or false. Auto-enabled for non-localhost.
DATABASE_SSL_CAPath to CA certificate bundle
DATABASE_SSL_REJECT_UNAUTHORIZEDtrueSet false to allow self-signed certificates

SSH Tunnel

VariableRequiredDefaultDescription
SSH_ENABLEDNofalseSet true to enable SSH tunneling
SSH_HOSTYes*SSH server hostname
SSH_PORTNo22SSH server port
SSH_USERYes*SSH username
SSH_PRIVATE_KEY_PATHYes**Path to private key file
SSH_PRIVATE_KEY_PASSPHRASENoPassphrase for encrypted keys
SSH_PASSWORDYes**SSH password (alternative to key)
SSH_STRICT_HOST_KEYNotrueVerify host key against known_hosts
SSH_TRUST_ON_FIRST_USENotrueAuto-add unknown hosts (when strict is enabled)
SSH_KNOWN_HOSTS_PATHNo~/.ssh/known_hostsCustom known_hosts file
SSH_KEEPALIVE_INTERVALNo10000Keepalive interval in milliseconds
SSH_MAX_RECONNECT_ATTEMPTSNo5Max reconnect attempts (-1 for unlimited)

*Required when SSH_ENABLED=true **Either SSH_PRIVATE_KEY_PATH or SSH_PASSWORD is required

Query Behavior

VariableDefaultDescription
READ_ONLYtrueBlock data modifications. Set false to allow writes.
MAX_ROWS1000Maximum rows returned per query
QUERY_TIMEOUT30000Query timeout in milliseconds
MAX_CONCURRENT_QUERIES10Maximum concurrent queries
POOL_DRAIN_TIMEOUT_MS5000Timeout for draining pool during reconnect

HTTP Server (Streamable HTTP only)

VariableDefaultDescription
PORT3000HTTP server port
MCP_HOST0.0.0.0HTTP server bind address
MCP_AUTH_MODEnoneAuthentication mode: none or oauth
MCP_STATELESStrueStateless mode (each request re-initializes)
MCP_SERVER_POOL_SIZE4Server instances for stateless mode
MCP_SESSION_TTL_MINUTES30Session TTL for stateful mode
MCP_SESSION_CLEANUP_INTERVAL_MS300000Session cleanup interval
MCP_ALLOWED_ORIGINSComma-separated allowed CORS origins (* for any)
MCP_ALLOWED_HOSTSComma-separated allowed Host headers

OAuth (Auth0)

VariableRequiredDescription
AUTH0_DOMAINYes*Auth0 tenant domain (e.g., tenant.us.auth0.com)
AUTH0_AUDIENCEYes*Auth0 API identifier / audience
MCP_RESOURCE_DOCUMENTATIONNoURL to API documentation (RFC 9728)

*Required when MCP_AUTH_MODE=oauth


Documentation

GuideDescription
STDIO SetupClaude Desktop and local development
Streamable HTTPHTTP server setup and configuration
Server SetupDeploy to production with nginx and SSL
ChatGPT SetupComplete Auth0 OAuth setup for ChatGPT

Docker

STDIO Server

docker build --target runtime -t postgresql-mcp .
docker run -e DATABASE_URI="postgresql://..." postgresql-mcp

HTTP Server

docker build --target runtime-http -t postgresql-mcp-http .
docker run -p 3000:3000 -e DATABASE_URI="postgresql://..." postgresql-mcp-http

Development

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Type check
npm run typecheck

# Lint
npm run lint

Reviews

No reviews yet

Sign in to write a review