PostgreSQL MCP Server
MCP server for PostgreSQL database operations. Works with Claude Code, Claude Desktop, Cursor, and any MCP-compatible client.
Power your agent
การติดตั้งจากผู้เผยแพร่ ไม่ใช่เอนด์พอยต์ของ PlugMCP
URL แบบรีโมตหรือคำสั่งบนเครื่องของคุณ? การติดตั้งสองแบบต่างกันอย่างไร
รันบน PlugMCP
A new server you create. It is not this listing's official endpoint. Use the publisher install when you want their URL and their credentials.
เปิดThis repository contains both TypeScript and Python implementations:
Note: The TypeScript version is used for Smithery deployments. Both versions provide identical functionality.
Protocol compatibility: both servers speak the
2026-07-28revision and are dual-era — clients that still open with the 2025-erainitializehandshake are served exactly as before, so no client needs upgrading. The TypeScript package requires patched Node.js 22.23.4 or 24.22.1; the Python package requires Python 3.11+ (CI uses patched 3.11.17 and 3.12.15).
# Install globally
npm install -g @javiagui/postgresql-mcp
# Or run directly with npx
npx @javiagui/postgresql-mcp
# Install
pipx install postgresql-mcp
# Configure Claude Code
claude mcp add postgres -s user \
-e POSTGRES_HOST=localhost \
-e POSTGRES_USER=your_user \
-e POSTGRES_PASSWORD=your_password \
-e POSTGRES_DB=your_database \
-- postgresql-mcp
Full Installation Guide - Includes database permissions setup, remote connections, and troubleshooting.
Most real work touches more than one database. Instead of editing this config and restarting your client every time, declare several connections and pick one per call by alias:
POSTGRES_CONNECTIONS='[
{"alias":"local","host":"localhost","user":"me","password":"…","database":"app","allowWrite":true},
{"alias":"staging","url":"postgresql://reader:…@staging.example.com:5432/app"},
{"alias":"analytics","url":"postgresql://reader:…@warehouse:6543/metrics?sslmode=require","default":true}
]'
list_databases returns the configured aliases with host, database name,
write permission and which is the default. Credentials are never returned.database argument naming an alias.
Omit it and you get the default connection — so an existing single-database
setup keeps working with no changes at all.allowWrite is per connection, falling back to ALLOW_WRITE_OPERATIONS.
A production replica stays read-only while a local database allows writes.default: true marks the connection used when database is omitted;
otherwise it is the first one declared. At most one connection may be marked
default.host, port, user,
password, database, sslmode) or a url DSN — and discrete fields
override the DSN, so you can reuse a URL and change one part of it.POSTGRES_CONNECTIONS and the plain POSTGRES_* variables are mutually
exclusive. When the first is set the others are ignored, so there is never a
question about which one won.
Credentials only ever come from the environment. The
databaseargument names an alias; there is deliberately no way to pass a host, user, password or connection string as a tool argument, because that would put secrets into the conversation. A test enforces this.
# TypeScript version
claude mcp add postgres -s user \
-e POSTGRES_HOST=localhost \
-e POSTGRES_USER=your_user \
-e POSTGRES_PASSWORD=your_password \
-e POSTGRES_DB=your_database \
-- npx @javiagui/postgresql-mcp
# Python version
claude mcp add postgres -s user \
-e POSTGRES_HOST=localhost \
-e POSTGRES_USER=your_user \
-e POSTGRES_PASSWORD=your_password \
-e POSTGRES_DB=your_database \
-- postgresql-mcp
Add to ~/.cursor/mcp.json:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["@javiagui/postgresql-mcp"],
"env": {
"POSTGRES_HOST": "localhost",
"POSTGRES_PORT": "5432",
"POSTGRES_USER": "your_user",
"POSTGRES_PASSWORD": "your_password",
"POSTGRES_DB": "your_database"
}
}
}
}
Every tool below except list_databases accepts an optional database argument
naming a configured connection — see Multiple databases.
Guided workflows that help Claude assist you effectively:
Browsable database structure:
Once configured, ask Claude to:
Schema Exploration:
Querying:
Performance Analysis:
Documentation:
This MCP server implements multiple security layers:
Write operations (INSERT, UPDATE, DELETE) are blocked unless explicitly enabled via ALLOW_WRITE_OPERATIONS=true.
MAX_ROWS (default: 1000)QUERY_TIMEOUTcd typescript
npm install
npm run build
npm run dev # Watch mode
cd python
uv sync
uv run pytest -v --cov=postgres_mcp
# Python unit tests (no database required)
cd python
uv run pytest tests/test_security.py tests/test_settings.py -v
# Integration tests (requires PostgreSQL)
docker-compose up -d
uv run pytest tests/test_integration.py -v
# Verify PostgreSQL is running
pg_isready -h localhost -p 5432
# Test connection with psql
psql -h localhost -U your_user -d your_database
Ensure your database user has SELECT permissions:
GRANT SELECT ON ALL TABLES IN SCHEMA public TO your_user;
# Check server status
claude mcp get postgres
# Test server directly
postgresql-mcp # Should wait for MCP messages
Built by Javier Aguilar - AI Agent Architect specializing in multi-agent orchestration and MCP development.
MIT
The only postgress MCP server I have been able to connect to my docker postgres
เครื่องมือ
ยังไม่มีรายการเครื่องมือ เซิร์ฟเวอร์แบบรีโมตจะได้รายการหลังการตรวจสอบสถานะครั้งแรก
FAQ
คัดลอกคอนฟิก stdio สำหรับ Cursor, Claude Desktop, Claude Code หรือ VS Code ได้ในหน้านี้ คอนฟิกนี้ใช้การติดตั้งของผู้เผยแพร่ ไม่ใช่พร็อกซีของ PlugMCP
ระเบียนนี้ไม่ได้ระบุตัวแปรสภาพแวดล้อมที่จำเป็น
Postgres ทำงานแบบโลคัลผ่าน stdio
ตรวจสอบล่าสุดเมื่อ 2026-10-28 The only postgress MCP server I have been able to connect to my docker postgres