Back to MCP Servers
🧩

PostgreSQL MCP Server

API key required

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

To add PostgreSQL to Claude, run the install command below or copy the ready-made config for Claude Code, Claude Desktop, Cursor and VS Code further down. Restart your client after adding it and its tools show up in your next conversation. It needs 22 environment variables, listed below.

DatabaseCloudDevTools

Install

npx -y mcp-postgres-server@0.3.1

Environment variables

DATABASE_URLSet in your MCP config
PG_HOSTSet in your MCP config
PG_PORTSet in your MCP config
PG_USERSet in your MCP config
PG_PASSWORDSet in your MCP config
PG_DATABASESet in your MCP config
PG_ALLOW_WRITESet in your MCP config
PG_SSLMODESet in your MCP config
PG_SSL_CASet in your MCP config
PG_ENABLE_RUNTIME_CONNECTSet in your MCP config
PG_MAX_RESULT_BYTESSet in your MCP config
PG_STATEMENT_TIMEOUTSet in your MCP config
PG_CONNECT_TIMEOUTSet in your MCP config
PG_SSH_HOSTSet in your MCP config
PG_SSH_PORTSet in your MCP config
PG_SSH_USERSet in your MCP config
PG_SSH_PRIVATE_KEYSet in your MCP config
PG_SSH_PASSPHRASESet in your MCP config
PG_SSH_AGENTSet in your MCP config
PG_SSH_PASSWORDSet in your MCP config
PG_SSH_FINGERPRINTSet in your MCP config
PG_SSH_KEEPALIVE_INTERVALSet in your MCP config

Install with your client

Terminal
claude mcp add postgresql --env DATABASE_URL=<YOUR_DATABASE_URL> --env PG_HOST=<YOUR_PG_HOST> --env PG_PORT=<YOUR_PG_PORT> --env PG_USER=<YOUR_PG_USER> --env PG_PASSWORD=<YOUR_PG_PASSWORD> --env PG_DATABASE=<YOUR_PG_DATABASE> --env PG_ALLOW_WRITE=<YOUR_PG_ALLOW_WRITE> --env PG_SSLMODE=<YOUR_PG_SSLMODE> --env PG_SSL_CA=<YOUR_PG_SSL_CA> --env PG_ENABLE_RUNTIME_CONNECT=<YOUR_PG_ENABLE_RUNTIME_CONNECT> --env PG_MAX_RESULT_BYTES=<YOUR_PG_MAX_RESULT_BYTES> --env PG_STATEMENT_TIMEOUT=<YOUR_PG_STATEMENT_TIMEOUT> --env PG_CONNECT_TIMEOUT=<YOUR_PG_CONNECT_TIMEOUT> --env PG_SSH_HOST=<YOUR_PG_SSH_HOST> --env PG_SSH_PORT=<YOUR_PG_SSH_PORT> --env PG_SSH_USER=<YOUR_PG_SSH_USER> --env PG_SSH_PRIVATE_KEY=<YOUR_PG_SSH_PRIVATE_KEY> --env PG_SSH_PASSPHRASE=<YOUR_PG_SSH_PASSPHRASE> --env PG_SSH_AGENT=<YOUR_PG_SSH_AGENT> --env PG_SSH_PASSWORD=<YOUR_PG_SSH_PASSWORD> --env PG_SSH_FINGERPRINT=<YOUR_PG_SSH_FINGERPRINT> --env PG_SSH_KEEPALIVE_INTERVAL=<YOUR_PG_SSH_KEEPALIVE_INTERVAL> -- npx -y mcp-postgres-server@0.3.1

Run this in a terminal to add the server to Claude Code.

What this does

PostgreSQL exposes a set of tools to Claude over the Model Context Protocol. After you add it to claude_desktop_config.json (snippet above) and restart Claude Desktop, those tools become callable inside any conversation.

Requirements

This server needs the following environment variables to be set before it can run:

DATABASE_URL
PG_HOST
PG_PORT
PG_USER
PG_PASSWORD
PG_DATABASE
PG_ALLOW_WRITE
PG_SSLMODE
PG_SSL_CA
PG_ENABLE_RUNTIME_CONNECT
PG_MAX_RESULT_BYTES
PG_STATEMENT_TIMEOUT
PG_CONNECT_TIMEOUT
PG_SSH_HOST
PG_SSH_PORT
PG_SSH_USER
PG_SSH_PRIVATE_KEY
PG_SSH_PASSPHRASE
PG_SSH_AGENT
PG_SSH_PASSWORD
PG_SSH_FINGERPRINT
PG_SSH_KEEPALIVE_INTERVAL

Set these via the env object in your MCP config (see claude_desktop_config.json snippet above).

Frequently asked questions

How do I install PostgreSQL?

Run the Claude Code command in the install section to add PostgreSQL to Claude Code, or copy the ready-made config for your client from the install section on this page. Restart your client afterwards and the tools appear in your next conversation.

Which clients work with PostgreSQL?

This page carries setup and config for Claude Code, Claude Desktop, Cursor and VS Code. Any other MCP client that accepts a standard server config can connect to PostgreSQL as well.

Does PostgreSQL need an API key?

Yes. Before it can run, set these environment variables: DATABASE_URL, PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, PG_DATABASE, PG_ALLOW_WRITE, PG_SSLMODE, PG_SSL_CA, PG_ENABLE_RUNTIME_CONNECT, PG_MAX_RESULT_BYTES, PG_STATEMENT_TIMEOUT, PG_CONNECT_TIMEOUT, PG_SSH_HOST, PG_SSH_PORT, PG_SSH_USER, PG_SSH_PRIVATE_KEY, PG_SSH_PASSPHRASE, PG_SSH_AGENT, PG_SSH_PASSWORD, PG_SSH_FINGERPRINT, PG_SSH_KEEPALIVE_INTERVAL. They go in the env block of your MCP config.

Imported from the Official MCP Registry. The details above come from the registry entry; the maker can claim this listing to correct them, add docs, and see its traffic.

Is this your MCP server?

Claim this listing to see its traffic, fix details yourself, and skip the review queue on future updates.

Listed on clauderules.net

Add this badge to your README

Show visitors this server is listed in the ClaudeRules directory. The badge links straight to this listing.

Markdown
[![Listed on clauderules.net](https://clauderules.net/api/badge/io-github-antonorlov-mcp-postgres-server)](https://clauderules.net/mcp/io-github-antonorlov-mcp-postgres-server)
HTML
<a href="https://clauderules.net/mcp/io-github-antonorlov-mcp-postgres-server" target="_blank" rel="noopener noreferrer"><img src="https://clauderules.net/api/badge/io-github-antonorlov-mcp-postgres-server" alt="Listed on clauderules.net" /></a>