The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the Postgres MCP listing page.
MCP server for PostgreSQL database operations. Works with Claude Code, Claude Desktop, Cursor, and any MCP-compatible client.
This repository contains both TypeScript and Python implementations:
| Version | Directory | Status | MCP protocol | Installation |
|---|---|---|---|---|
| TypeScript | /typescript | ✅ Recommended (Smithery) | 2026-07-28 (SDK v2) | npm install -g @javiagui/postgresql-mcp |
| Python | /python | ✅ Stable | 2026-07-28 (SDK v2) | pipx install postgresql-mcp |
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 Node.js 20+; the Python package requires Python 3.10+.
Full Installation Guide - Includes database permissions setup, remote connections, and troubleshooting.
| Variable | Required | Default | Description |
|---|---|---|---|
POSTGRES_HOST | localhost | Database host | |
POSTGRES_PORT | 5432 | Database port | |
POSTGRES_USER | ✅ | Database user | |
POSTGRES_PASSWORD | ✅ | Database password | |
POSTGRES_DB | ✅ | Database name | |
POSTGRES_SSLMODE | prefer | SSL mode | |
ALLOW_WRITE_OPERATIONS | false | Enable INSERT/UPDATE/DELETE | |
QUERY_TIMEOUT | 30 | Query timeout (seconds) | |
MAX_ROWS | 1000 | Maximum rows returned |
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:
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.
Add to ~/.cursor/mcp.json:
Every tool below except list_databases accepts an optional database argument
naming a configured connection — see Multiple databases.
| Tool | Description |
|---|---|
query | Execute read-only SQL queries against the database |
execute | Execute write operations (INSERT/UPDATE/DELETE) when enabled |
explain_query | Get EXPLAIN plan for query optimization |
| Tool | Description |
|---|---|
list_schemas | List all schemas in the database |
list_tables | List tables in a specific schema |
describe_table | Get table structure (columns, types, constraints) |
list_views | List views in a schema |
describe_view | Get view definition and columns |
list_functions | List functions and procedures |
| Tool | Description |
|---|---|
table_stats | Get table statistics (row count, size, bloat) |
list_indexes | List indexes for a table |
list_constraints | List constraints (PK, FK, UNIQUE, CHECK) |
| Tool | Description |
|---|---|
get_database_info | Get database version and connection info |
search_columns | Search for columns by name across all tables |
list_databases | List the configured connections by alias, with host, database, write permission and which is the default. Never returns credentials. |
Guided workflows that help Claude assist you effectively:
| Prompt | Description |
|---|---|
explore_database | Comprehensive database exploration and overview |
query_builder | Help building efficient queries for a table |
performance_analysis | Analyze table performance and suggest optimizations |
data_dictionary | Generate documentation for a schema |
Browsable database structure:
| Resource URI | Description |
|---|---|
postgres://schemas | List all schemas |
postgres://schemas/{schema}/tables | Tables in a schema |
postgres://schemas/{schema}/tables/{table} | Table details |
postgres://database | Database connection info |
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_TIMEOUTEnsure your database user has SELECT permissions:
Built by Javier Aguilar - AI Agent Architect specializing in multi-agent orchestration and MCP development.
MIT