PostgreSQL MCP Server

PostgreSQL administration, querying and data changes from an MCP client over stdio

By Nour Eddine Hamaidi (individual) TypeScript Local · stdio Databases

59 popularity score ★ 204 ↓ 3.5k/wk

Connect your client

Local (npm)

Add in one click

Opens the app, which asks before it adds the server. Then replace each <NAME> in its settings with your value.

Or add it by command or config

It needs POSTGRES_CONNECTION_STRING. Replace each <NAME> with your value.

Claude CodeTerminal
claude mcp add postgresql -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> -- npx -y @henkey/postgres-mcp-server --connection-string '<POSTGRES_CONNECTION_STRING>'
Claude Desktopclaude_desktop_config.json
{
  "mcpServers": {
    "postgresql": {
      "command": "npx",
      "args": [
        "-y",
        "@henkey/postgres-mcp-server",
        "--connection-string",
        "<POSTGRES_CONNECTION_STRING>"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
Cursor~/.cursor/mcp.json
{
  "mcpServers": {
    "postgresql": {
      "command": "npx",
      "args": [
        "-y",
        "@henkey/postgres-mcp-server",
        "--connection-string",
        "<POSTGRES_CONNECTION_STRING>"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
VS Code.vscode/mcp.json
{
  "servers": {
    "postgresql": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@henkey/postgres-mcp-server",
        "--connection-string",
        "<POSTGRES_CONNECTION_STRING>"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
Codex~/.codex/config.toml
[mcp_servers.postgresql]
command = "npx"
args = ["-y", "@henkey/postgres-mcp-server", "--connection-string", "<POSTGRES_CONNECTION_STRING>"]

[mcp_servers.postgresql.env]
POSTGRES_CONNECTION_STRING = "<POSTGRES_CONNECTION_STRING>"
Gemini CLITerminal
gemini mcp add --scope user -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> postgresql npx -- -y @henkey/postgres-mcp-server --connection-string '<POSTGRES_CONNECTION_STRING>'
Local (container)

Add in one click

Opens the app, which asks before it adds the server. Then replace each <NAME> in its settings with your value.

Or add it by command or config

It needs POSTGRES_CONNECTION_STRING. Replace each <NAME> with your value.

Claude CodeTerminal
claude mcp add postgresql -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> -- docker run -i --rm -e POSTGRES_CONNECTION_STRING henkey/postgres-mcp:latest
Claude Desktopclaude_desktop_config.json
{
  "mcpServers": {
    "postgresql": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "POSTGRES_CONNECTION_STRING",
        "henkey/postgres-mcp:latest"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
Cursor~/.cursor/mcp.json
{
  "mcpServers": {
    "postgresql": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "POSTGRES_CONNECTION_STRING",
        "henkey/postgres-mcp:latest"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
VS Code.vscode/mcp.json
{
  "servers": {
    "postgresql": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "POSTGRES_CONNECTION_STRING",
        "henkey/postgres-mcp:latest"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
Codex~/.codex/config.toml
[mcp_servers.postgresql]
command = "docker"
args = ["run", "-i", "--rm", "-e", "POSTGRES_CONNECTION_STRING", "henkey/postgres-mcp:latest"]

[mcp_servers.postgresql.env]
POSTGRES_CONNECTION_STRING = "<POSTGRES_CONNECTION_STRING>"
Gemini CLITerminal
gemini mcp add --scope user -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> postgresql docker -- run -i --rm -e POSTGRES_CONNECTION_STRING henkey/postgres-mcp:latest
Local (from source)

Add in one click

Opens the app, which asks before it adds the server. Then replace each <NAME> in its settings with your value.

Or add it by command or config

It needs POSTGRES_CONNECTION_STRING. Replace each <NAME> with your value.

FirstTerminal
git clone https://github.com/HenkDz/postgresql-mcp-server.git
cd postgresql-mcp-server
npm install
npm run build
Claude CodeTerminal
claude mcp add postgresql -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> -- node '<ABSOLUTE_PATH_TO_CLONE>/build/index.js' --connection-string '<POSTGRES_CONNECTION_STRING>'
Claude Desktopclaude_desktop_config.json
{
  "mcpServers": {
    "postgresql": {
      "command": "node",
      "args": [
        "<ABSOLUTE_PATH_TO_CLONE>/build/index.js",
        "--connection-string",
        "<POSTGRES_CONNECTION_STRING>"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
Cursor~/.cursor/mcp.json
{
  "mcpServers": {
    "postgresql": {
      "command": "node",
      "args": [
        "<ABSOLUTE_PATH_TO_CLONE>/build/index.js",
        "--connection-string",
        "<POSTGRES_CONNECTION_STRING>"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
VS Code.vscode/mcp.json
{
  "servers": {
    "postgresql": {
      "type": "stdio",
      "command": "node",
      "args": [
        "<ABSOLUTE_PATH_TO_CLONE>/build/index.js",
        "--connection-string",
        "<POSTGRES_CONNECTION_STRING>"
      ],
      "env": {
        "POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
      }
    }
  }
}
Codex~/.codex/config.toml
[mcp_servers.postgresql]
command = "node"
args = ["<ABSOLUTE_PATH_TO_CLONE>/build/index.js", "--connection-string", "<POSTGRES_CONNECTION_STRING>"]

[mcp_servers.postgresql.env]
POSTGRES_CONNECTION_STRING = "<POSTGRES_CONNECTION_STRING>"
Gemini CLITerminal
gemini mcp add --scope user -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> postgresql node -- '<ABSOLUTE_PATH_TO_CLONE>/build/index.js' --connection-string '<POSTGRES_CONNECTION_STRING>'

Settings 1

POSTGRES_CONNECTION_STRING Required: PostgreSQL connection URL (postgresql://user:pass@host:5432/db); the --connection-string flag overrides it.

In a container, a setting goes in with -e NAME=value after docker run.

What it does

PostgreSQL MCP Server is a community-built stdio server that connects an MCP client to a PostgreSQL database and exposes most of the day-to-day work of a database administrator as tools. Rather than one tool per action, it groups related actions into a few broad tools that take an `operation` argument: one for schema (tables, columns, ENUMs), one each for indexes, constraints, functions, triggers, row-level security policies, users and grants, and one for query performance (EXPLAIN plans, slow queries, statistics).

Alongside those it has three tools for working with rows: a SELECT/CTE-only query tool with count and exists modes, a mutation tool for INSERT, UPDATE, DELETE and UPSERT with parameterised values, and a tool that runs any SQL, optionally inside a transaction. It can also export a table to a JSON or CSV file, load such a file into a table, copy data between two databases, report on database health and configuration, help debug connection, lock and performance issues, and set or read comments on database objects.

The published npm release, 1.0.7, registers 18 tools in its entry file (build/index.js), although the README on npm says 17. A tools config file passed with `--tools-config` can narrow the list to the tools named in its `enabledTools` array; 1.0.7 reads only the flag, not the `POSTGRES_TOOLS_CONFIG` variable the README shows. In 1.0.7 every tool also accepts its own `connectionString` argument, which takes precedence over the server-level `--connection-string` flag and the `POSTGRES_CONNECTION_STRING` variable.

The GitHub README now describes a 2.0.0 line with a read-only default, `--security-mode` levels, an `--allow-destructive` switch and a workspace directory for file tools. That version is not on npm yet: the latest published release is 1.0.7, and the README itself points to 1.0.7 for the line without breaking changes.

What it needs

RuntimeNode.js 18+orDocker

Node.js 18 or newer for npx (or Docker for the henkey/postgres-mcp image), and network access to a PostgreSQL server with a role whose rights match what you want the tools to do. The connection string is given with `--connection-string` or `POSTGRES_CONNECTION_STRING`. Running from source needs git and npm to clone and build.

Limits

Version 1.0.7, the one npm installs, has none of the safeguards the GitHub README describes for 2.0.0 (read-only mode, security levels, destructive-operation opt-in, connection allowlist, audit log): those exist only in unreleased code. In 1.0.7 the query tool adds a LIMIT only when you pass `limit`, so an unbounded SELECT returns every row. The server starts without a connection string and only fails when a tool is called. The README's first Docker client config puts `-e POSTGRES_CONNECTION_STRING` after the image name, so Docker never passes the variable to the container; the form below puts it before the image. The tool count on the npm README (17) differs from the code (18).

Who it suits

Fits developers and DBAs who want an assistant to inspect and manage a PostgreSQL database they control, including schema changes, roles, RLS and data import/export, and who will limit what it can do through the PostgreSQL role they connect with. With 1.0.7 that role is the only real limit, so point it at a development database or a least-privilege user. If you only want read access, a read-only server such as read-only-local-postgres-mcp-server, which we also list, or the 2.0.0 line once it is released, is a narrower choice.

Tools 18

pg_analyze_database
Reports on configuration, performance or security of the database
pg_debug_database
Looks into connection, lock, performance or replication problems
pg_manage_schema
Reads schema details and creates or alters tables and ENUM types
pg_manage_functions
Lists, creates and drops stored functions
pg_manage_triggers
Lists, creates, drops, enables and disables triggers
pg_manage_indexes
Lists, creates, drops and rebuilds indexes and checks their usage
pg_manage_constraints
Lists, adds and removes foreign keys and other constraints
pg_manage_rls
Turns row-level security on or off and manages its policies
pg_manage_users
Creates, alters and drops roles and grants or revokes permissions
pg_manage_query
Shows EXPLAIN plans, slow queries and query statistics
pg_execute_query
Runs a SELECT or WITH query in select, count or exists mode
pg_execute_mutation
Inserts, updates, deletes or upserts rows with bound values
pg_execute_sql
Runs any SQL statement, optionally in a transaction
pg_manage_comments
Reads, sets and removes comments on database objects
pg_export_table_data
Writes a table's rows to a JSON or CSV file
pg_import_table_data
Loads rows from a JSON or CSV file into a table
pg_copy_between_databases
Copies table data from one database to another
pg_monitor_database
Returns live metrics such as connections, locks and table sizes

Similar servers