PostgreSQL SSH MCP Server
Provides tools for executing SQL queries, listing schemas, tables, and databases, describing table structure, and getting database connection status and statistics.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL SSH MCP Server show me a list of all tables"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PostgreSQL SSH MCP Server
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
Related MCP server: @pilat/mcp-datalink
Architecture

Quick Start
Claude Desktop (STDIO)
Add to your Claude Desktop config:
Platform | Config Location |
macOS |
|
Windows |
|
{
"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-httpThen 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
Tool | Description |
| Execute SQL with parameterized queries. Results capped by |
| Get EXPLAIN plans in text, JSON, YAML, or XML format. Supports ANALYZE. |
Schema Tools
Tool | Description |
| List database schemas. Excludes system schemas by default. |
| List tables with row counts and sizes. Optionally include views. |
| Get columns, constraints, and indexes for a table. |
| List all databases with owner, encoding, and size. |
Admin Tools
Tool | Description |
| Get pool stats, tunnel state, and connection info. |
| Show active connections from |
| Find queries running longer than a threshold. |
| Get PostgreSQL server version. |
| Get database size and largest tables. |
| Get vacuum/analyze stats and scan counts for a table. |
Environment Variables
Database Connection
Variable | Required | Default | Description |
| Yes* | — | Full connection string (e.g., |
| Yes* | — | Database hostname |
| No |
| Database port |
| Yes* | — | Database name |
| Yes* | — | Database username |
| Yes* | — | Database password |
*Either DATABASE_URI or all individual connection variables are required.
SSL Configuration
Variable | Default | Description |
| Auto |
|
| — | Path to CA certificate bundle |
|
| Set |
SSH Tunnel
Variable | Required | Default | Description |
| No |
| Set |
| Yes* | — | SSH server hostname |
| No |
| SSH server port |
| Yes* | — | SSH username |
| Yes** | — | Path to private key file |
| No | — | Passphrase for encrypted keys |
| Yes** | — | SSH password (alternative to key) |
| No |
| Verify host key against known_hosts |
| No |
| Auto-add unknown hosts (when strict is enabled) |
| No |
| Custom known_hosts file |
| No |
| Keepalive interval in milliseconds |
| No |
| Max reconnect attempts ( |
*Required when SSH_ENABLED=true
**Either SSH_PRIVATE_KEY_PATH or SSH_PASSWORD is required
Query Behavior
Variable | Default | Description |
|
| Block data modifications. Set |
|
| Maximum rows returned per query |
|
| Query timeout in milliseconds |
|
| Maximum concurrent queries |
|
| Timeout for draining pool during reconnect |
HTTP Server (Streamable HTTP only)
Variable | Default | Description |
|
| HTTP server port |
|
| HTTP server bind address |
|
| Authentication mode: |
|
| Stateless mode (each request re-initializes) |
|
| Server instances for stateless mode |
|
| Session TTL for stateful mode |
|
| Session cleanup interval |
| — | Comma-separated allowed CORS origins ( |
| — | Comma-separated allowed Host headers |
OAuth (Auth0)
Variable | Required | Description |
| Yes* | Auth0 tenant domain (e.g., |
| Yes* | Auth0 API identifier / audience |
| No | URL to API documentation (RFC 9728) |
*Required when MCP_AUTH_MODE=oauth
Documentation
Guide | Description |
Claude Desktop and local development | |
HTTP server setup and configuration | |
Deploy to production with nginx and SSL | |
Complete Auth0 OAuth setup for ChatGPT |
Docker
STDIO Server
docker build --target runtime -t postgresql-mcp .
docker run -e DATABASE_URI="postgresql://..." postgresql-mcpHTTP Server
docker build --target runtime-http -t postgresql-mcp-http .
docker run -p 3000:3000 -e DATABASE_URI="postgresql://..." postgresql-mcp-httpDevelopment
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Type check
npm run typecheck
# Lint
npm run lintAvailable Tools
12 toolsdescribe_tableA
Describe a table (columns, constraints, indexes).
Inputs: table (required), schema. Returns: result
execute_queryB
Execute SQL with optional parameters. Results are capped by MAX_ROWS and include a truncated flag.
Inputs: sql (required), params. Returns: result
explain_queryB
Return an EXPLAIN plan for a query. ANALYZE executes the query.
Inputs: sql (required), analyze, format. Returns: result
get_connection_statusA
Get connection status, pool stats, and tunnel state.
Inputs: no named parameters. Returns: result
get_database_sizeB
Get database size and largest tables.
Inputs: limit. Returns: result
get_database_versionA
Get PostgreSQL server version.
Inputs: no named parameters. Returns: result
get_table_statsA
Get table statistics (rows, vacuum/analyze, scan counts).
Inputs: table (required), schema. Returns: result
list_active_connectionsB
List active connections from pg_stat_activity.
Inputs: includeIdle. Returns: result
list_databasesA
List databases with owner, encoding, and size.
Inputs: no named parameters. Returns: result
list_long_running_queriesC
List queries running longer than a threshold.
Inputs: minDurationSeconds. Returns: result
list_schemasA
List schemas (excludes system schemas by default).
Inputs: includeSystem. Returns: result
list_tablesA
List tables in a schema with estimated row counts and sizes.
Inputs: schema, includeViews. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 12 tools
Each tool has a clear, distinct purpose covering different aspects of PostgreSQL management: schema description, query execution, planning, connections, database info, stats, and monitoring. No overlaps or ambiguities.
All tool names follow a consistent verb_noun pattern with verbs like describe, execute, explain, get, and list. The naming is predictable and uniform.
With 12 tools, the server is well-scoped for its intended domain of PostgreSQL monitoring and management. Each tool earns its place without being excessive or sparse.
The tool set covers essential operations for database exploration and performance monitoring, including schema inspection, query execution, explain plans, and active query tracking. Minor gaps exist, such as lack of tools for modifying database objects or managing connections, but these are reasonable given the server's likely read-oriented purpose.
Maintenance
Related MCP Connectors
Hosted PostgreSQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
MCP server that lets your AI assistant build and deploy apps, hosting each one at a live URL.
Xata MCP server lets AI agents interact with your Xata projects, and Postgres database branches.
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceA universal database gateway MCP server that enables AI assistants to connect to and query multiple databases (PostgreSQL, MySQL, MariaDB, SQL Server, SQLite) with support for schema exploration, SQL execution, and secure connections via SSH tunnels.17 npm-
- AlicenseNot gradedqualityCmaintenanceMCP server for PostgreSQL, MySQL, and SQLite that gives AI assistants secure database access via the Model Context Protocol.56 npm5MIT
- FlicenseNot gradedqualityDmaintenanceA production-ready MCP server that connects AI assistants to any PostgreSQL database with 25 tools and role-based access control.-
- AlicenseAqualityDmaintenanceA production-grade MCP server that gives AI agents safe, authenticated access to a PostgreSQL database.3MIT