MCP Postgres
MCP server giving AI clients safe, governed access to PostgreSQL schemas and queries
MCP Postgres is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.
- Pricing
- Open source
- Platforms
- CLI, Self-hosted
- Runs
- Locally
- What it can do
- Can delete data (2 tools)
- Access
- Needs a secret key or token
Similar MCP servers
Install
Add with the CLI
Run in a terminal
claude mcp add mcp-postgres --env POSTGRES_URL='<POSTGRES_URL>' -- npx -y @dockndevai/mcp-postgresAdd --scope user to use it in every project, or --scope project to share it in .mcp.json.
Or share it with your project
Add to .mcp.json
{
"mcpServers": {
"mcp-postgres": {
"command": "npx",
"args": [
"-y",
"@dockndevai/mcp-postgres"
],
"env": {
"POSTGRES_URL": "<POSTGRES_URL>"
}
}
}
}Add to claude_desktop_config.json
{
"mcpServers": {
"mcp-postgres": {
"command": "npx",
"args": [
"-y",
"@dockndevai/mcp-postgres"
],
"env": {
"POSTGRES_URL": "<POSTGRES_URL>"
}
}
}
}Settings → Developer → Edit Config, then quit and reopen Claude Desktop.
Add to ~/.cursor/mcp.json
{
"mcpServers": {
"mcp-postgres": {
"command": "npx",
"args": [
"-y",
"@dockndevai/mcp-postgres"
],
"env": {
"POSTGRES_URL": "<POSTGRES_URL>"
}
}
}
}Use .cursor/mcp.json in a project to share it with the project.
Add to ~/.copilot/mcp-config.json
{
"mcpServers": {
"mcp-postgres": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@dockndevai/mcp-postgres"
],
"env": {
"POSTGRES_URL": "<POSTGRES_URL>"
}
}
}
}Or put the same entry in .mcp.json at your workspace root to share it.
Add with the CLI
Run in a terminal
codex mcp add mcp-postgres --env POSTGRES_URL='<POSTGRES_URL>' -- npx -y @dockndevai/mcp-postgresOr add to config.toml
Add to ~/.codex/config.toml
[mcp_servers.mcp-postgres]
command = "npx"
args = ["-y", "@dockndevai/mcp-postgres"]
env = { POSTGRES_URL = "<POSTGRES_URL>" }Add to your client's MCP settings (most use this shape)
{
"mcpServers": {
"mcp-postgres": {
"command": "npx",
"args": [
"-y",
"@dockndevai/mcp-postgres"
],
"env": {
"POSTGRES_URL": "<POSTGRES_URL>"
}
}
}
}Gemini CLI and Antigravity
Gemini CLI
Add to ~/.gemini/settings.json
{ "mcpServers": { "mcp-postgres": { "command": "npx", "args": [ "-y", "@dockndevai/mcp-postgres" ], "env": { "POSTGRES_URL": "<POSTGRES_URL>" } } } }Or run: gemini mcp add -s user -e POSTGRES_URL='<POSTGRES_URL>' mcp-postgres npx -- -y @dockndevai/mcp-postgres
Antigravity
Add to ~/.gemini/config/mcp_config.json
{ "mcpServers": { "mcp-postgres": { "command": "npx", "args": [ "-y", "@dockndevai/mcp-postgres" ], "env": { "POSTGRES_URL": "<POSTGRES_URL>" } } } }Use .agents/mcp_config.json to add it to one workspace only.
Devin Desktop (formerly Windsurf)
Add to ~/.config/devin/mcp_config.json
{ "mcpServers": { "mcp-postgres": { "command": "npx", "args": [ "-y", "@dockndevai/mcp-postgres" ], "env": { "POSTGRES_URL": "<POSTGRES_URL>" } } } }On Windows the file is %APPDATA%\devin\mcp_config.json. Use .devin/mcp_config.json to share it with a project.
Cline
Add to cline_mcp_settings.json
{ "mcpServers": { "mcp-postgres": { "command": "npx", "args": [ "-y", "@dockndevai/mcp-postgres" ], "env": { "POSTGRES_URL": "<POSTGRES_URL>" } } } }Open it from the MCP Servers icon → Configure → Configure MCP Servers.
Zed
Add to Zed settings.json
{ "context_servers": { "mcp-postgres": { "command": "npx", "args": [ "-y", "@dockndevai/mcp-postgres" ], "env": { "POSTGRES_URL": "<POSTGRES_URL>" } } } }Open it with zed: open settings file. Merge context_servers into the settings you already have.
JetBrains AI Assistant and Junie
AI Assistant
Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add
{ "mcpServers": { "mcp-postgres": { "command": "npx", "args": [ "-y", "@dockndevai/mcp-postgres" ], "env": { "POSTGRES_URL": "<POSTGRES_URL>" } } } }The AI Assistant docs only show command and args. If the env block is ignored, use Junie for this server.
Junie
Add to ~/.junie/mcp/mcp.json
{ "mcpServers": { "mcp-postgres": { "command": "npx", "args": [ "-y", "@dockndevai/mcp-postgres" ], "env": { "POSTGRES_URL": "<POSTGRES_URL>" } } } }Use .junie/mcp/mcp.json to share it with a project.
Kiro
Add to ~/.kiro/settings/mcp.json
{ "mcpServers": { "mcp-postgres": { "command": "npx", "args": [ "-y", "@dockndevai/mcp-postgres" ], "env": { "POSTGRES_URL": "<POSTGRES_URL>" } } } }Use .kiro/settings/mcp.json to add it to one workspace only.
Using several servers? Build one config file with the MCP config generator.
Configuration
POSTGRES_URLlibpq connection string, e.g. postgresql://user:pass@host:5432/db (or use PGHOST/PGUSER/PGPASSWORD/PGDATABASE).RequiredPOSTGRES_MODEAccess mode: read-only | read-write | admin.POSTGRES_SCHEMA_ALLOWLISTComma-separated schemas the agent may touch (empty = all).
About MCP Postgres
Connects an MCP-capable AI client to any PostgreSQL 13+ database so it can browse schemas, run read queries, inspect query plans and check live activity. It starts in read-only mode and every read runs inside a transaction that is always rolled back.
Writes are opt-in. Teams can enable inserts and updates, and an admin mode adds deletes, drops and session termination, with each destructive action requiring a human approval bound to the exact arguments. Access can be narrowed to an allowlist of schemas, superuser connections are refused, and a row cap limits how much any single change can touch.
It suits developers and data teams who want an assistant to investigate slow queries, explore unfamiliar databases or make small data fixes without handing it an unrestricted connection string.
Tools this server provides (21)
Taken from the project documentation; the running server may differ.
From the tool list in its README, going by the names, 2 of 21 tools delete data and 6 change data; 2 names don't say.
From the server's own tool labels and tool names; not verified by us.
- get_server_infoName suggests: reads
- Server information.
- list_schemasName suggests: reads
- Lists schemas.
- list_tablesName suggests: reads
- Lists tables and views with sizes and row estimates.
- describe_tableName suggests: reads
- Describes columns, constraints and indexes.
- select_rows
- Structured schema-scoped row selection.
- run_queryName suggests: changes
- Runs one read-only SQL statement with parameters.
- explain_queryName suggests: reads
- Returns JSON query plans.
- list_active_queriesName suggests: reads
- Lists active sessions and waits.
- get_database_statsName suggests: reads
- Connection, cache and deadlock statistics.
- get_top_queriesName suggests: reads
- Top statements from pg_stat_statements.
- list_rolesName suggests: reads
- Lists database roles.
- list_extensionsName suggests: reads
- Lists installed extensions.
- insert_rowsName suggests: changes
- Parameterized row inserts.
- update_rowsName suggests: changes
- Parameterized row updates with a required filter.
- create_indexName suggests: changes
- Creates an index concurrently.
- analyze_tableName suggests: reads
- Runs ANALYZE on a table.
- cancel_queryName suggests: changes
- Cancels a running query.
- delete_rowsName suggests: deletes
- Deletes rows (admin mode, delete permission required).
- drop_tableName suggests: deletes
- Drops a table (admin mode, delete permission required).
- terminate_backend
- Terminates a database session (admin mode, delete permission required).
- execute_sqlName suggests: changes
- Runs raw SQL (admin mode, raw SQL opt-in required).
What it does
- Schema exploration
- Lists schemas, tables and views with sizes and row estimates, and describes columns, constraints and indexes with scan counts.
- Structured and free-form queries
- Offers schema-scoped row selection without SQL, plus a parameterized single read statement for custom queries.
- Query plan tuning
- Returns JSON execution plans, lists top statements from pg_stat_statements and can build indexes concurrently.
- Live diagnostics
- Shows active sessions and waits, connection and cache statistics, roles and extensions, and can cancel a runaway query.
- Layered access modes
- Read-only, read-write and admin modes register only the tools allowed at each level.
- Guarded changes
- Writes are capped by affected-row limits, require a non-empty filter for updates and deletes, and can be previewed in dry-run mode.
- Secret redaction and audit
- Masks values in password and token-like columns and writes a JSON audit line for each guarded operation.
Good for
- Finding the largest tables and indexes that are never scanned
- Explaining why a query is slow and suggesting an index
- Checking what is running and whether anything is waiting on a lock
- Exploring an unfamiliar database schema through an AI assistant
- Making a controlled update to a single record with human approval
Pricing
Open source
Free and MIT licensed.
More servers for the same service
MCP Postgres FAQ
Which database versions does MCP Postgres support?
It talks SQL to any PostgreSQL 13 or newer database.
Is MCP Postgres safe to point at a production database?
It starts read-only, refuses superuser connections and runs reads in rolled-back read-only transactions. Using a dedicated least-privilege role is recommended.
How is MCP Postgres installed?
It is published on npm and runs on demand with npx, with configuration snippets for Claude Desktop, Claude Code, Cursor, Windsurf, Codex CLI and VS Code.
Does MCP Postgres work with Kubernetes-hosted Percona PostgreSQL?
That workload is covered by a separate server, mcp-percona-pg. This one connects to any PostgreSQL database over SQL.
Is MCP Postgres free?
Yes. MCP Postgres is open source, so you can use and self-host it for free.
How do I add MCP Postgres to Claude Code?
Run this command in your terminal: claude mcp add mcp-postgres --env POSTGRES_URL='<POSTGRES_URL>' -- npx -y @dockndevai/mcp-postgres
What are the best alternatives to MCP Postgres?
The closest alternatives to MCP Postgres are Postgres MCP, Postgres, PostgreSQL MCP Server, Postgres Schema MCP and PostgreSQL MCP Server.
Where this comes from
- Description: written from the project's README and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.