PostgREST MCP Server
OFFICIAL SERVERQuery and change rows in a Supabase project or any PostgREST API through its REST endpoints
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
Opens the app, which asks before it adds the server. Then replace each <NAME> in its settings with your value.
It needs POSTGRES_CONNECTION_STRING. Replace each <NAME> with your value.
claude mcp add postgresql -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> -- npx -y @henkey/postgres-mcp-server --connection-string '<POSTGRES_CONNECTION_STRING>'{
"mcpServers": {
"postgresql": {
"command": "npx",
"args": [
"-y",
"@henkey/postgres-mcp-server",
"--connection-string",
"<POSTGRES_CONNECTION_STRING>"
],
"env": {
"POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
}
}
}
}{
"mcpServers": {
"postgresql": {
"command": "npx",
"args": [
"-y",
"@henkey/postgres-mcp-server",
"--connection-string",
"<POSTGRES_CONNECTION_STRING>"
],
"env": {
"POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
}
}
}
}{
"servers": {
"postgresql": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@henkey/postgres-mcp-server",
"--connection-string",
"<POSTGRES_CONNECTION_STRING>"
],
"env": {
"POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
}
}
}
}[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 mcp add --scope user -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> postgresql npx -- -y @henkey/postgres-mcp-server --connection-string '<POSTGRES_CONNECTION_STRING>'Opens the app, which asks before it adds the server. Then replace each <NAME> in its settings with your value.
It needs POSTGRES_CONNECTION_STRING. Replace each <NAME> with your value.
claude mcp add postgresql -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> -- docker run -i --rm -e POSTGRES_CONNECTION_STRING henkey/postgres-mcp:latest{
"mcpServers": {
"postgresql": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"POSTGRES_CONNECTION_STRING",
"henkey/postgres-mcp:latest"
],
"env": {
"POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
}
}
}
}{
"mcpServers": {
"postgresql": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"POSTGRES_CONNECTION_STRING",
"henkey/postgres-mcp:latest"
],
"env": {
"POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
}
}
}
}{
"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>"
}
}
}
}[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 mcp add --scope user -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> postgresql docker -- run -i --rm -e POSTGRES_CONNECTION_STRING henkey/postgres-mcp:latestOpens the app, which asks before it adds the server. Then replace each <NAME> in its settings with your value.
It needs POSTGRES_CONNECTION_STRING. Replace each <NAME> with your value.
git clone https://github.com/HenkDz/postgresql-mcp-server.git
cd postgresql-mcp-server
npm install
npm run buildclaude mcp add postgresql -e POSTGRES_CONNECTION_STRING=<POSTGRES_CONNECTION_STRING> -- node '<ABSOLUTE_PATH_TO_CLONE>/build/index.js' --connection-string '<POSTGRES_CONNECTION_STRING>'{
"mcpServers": {
"postgresql": {
"command": "node",
"args": [
"<ABSOLUTE_PATH_TO_CLONE>/build/index.js",
"--connection-string",
"<POSTGRES_CONNECTION_STRING>"
],
"env": {
"POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
}
}
}
}{
"mcpServers": {
"postgresql": {
"command": "node",
"args": [
"<ABSOLUTE_PATH_TO_CLONE>/build/index.js",
"--connection-string",
"<POSTGRES_CONNECTION_STRING>"
],
"env": {
"POSTGRES_CONNECTION_STRING": "<POSTGRES_CONNECTION_STRING>"
}
}
}
}{
"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>"
}
}
}
}[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 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>'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.
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.
| Runtime | Node.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.
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).
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.
pg_analyze_databasepg_debug_databasepg_manage_schemapg_manage_functionspg_manage_triggerspg_manage_indexespg_manage_constraintspg_manage_rlspg_manage_userspg_manage_querypg_execute_querypg_execute_mutationpg_execute_sqlpg_manage_commentspg_export_table_datapg_import_table_datapg_copy_between_databasespg_monitor_database