PostgreSQL (hardened, read Only) logo

PostgreSQL (hardened, read Only)

Read-only PostgreSQL over MCP. Writes refused at the parsed SQL, plus a READ ONLY transaction.

Install PostgreSQL (hardened, read Only)

Pick your client, then add it in one click or paste the config.

STDIONode.js
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "postgresql-hardened-read-only": {
      "command": "npx",
      "args": [
        "-y",
        "--stdio",
        "postgres-mcp-hardened"
      ]
    }
  }
}

Settings → Developer → Edit Config, merge this into mcpServers, then fully quit and reopen Claude Desktop.

Claude Code command
claude mcp add --transport stdio postgresql-hardened-read-only -- npx -y --stdio postgres-mcp-hardened

Run in your terminal. Add --scope project to share it with your team through .mcp.json.

We couldn’t confirm it starts correctly

We ran the install command but it didn't respond within our test window — this can mean a slow first-time install rather than a real problem.

npx -y --stdio postgres-mcp-hardened

No response to initialize.

This is an experimental automated check and can have false negatives — missing environment variables, a slow cold install, etc. It doesn’t necessarily mean something’s wrong. Last checked .

Overview

Tools12

What PostgreSQL (hardened, read Only) lets your agent do. Expand a tool for its parameters.

Self-reported~36 tokens of context

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

17/17 checks healthy over the last 117d

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 12d ago via OSV.dev · postgres-mcp-hardened (npm)

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars3Stargazers on the source repository.
npm downloads1.6kPackage downloads in the last 30 days.
Last commit6d agoMost recent push to the default branch.
Install checkInconclusiveDidn't respond in our test window — often a slow first install.
Tools exposed12Callable tools this server registers over MCP.
Directory activity1 viewsConfig copies, upvotes, and views on AllMCPs.

From the project README

postgres-mcp-hardened

CI npm

A hardened, read-only Rust replacement for the deprecated @modelcontextprotocol/server-postgres: an MCP server that lets an AI agent query PostgreSQL with defence in depth.

Terminal: postgres-mcp-hardened --validate refuses pg_read_file and allows a plain SELECT

A drop-in Model Context Protocol server that lets an AI agent query PostgreSQL — read-only, enforced at the database level, with real SQL validation, timeouts, cost limits, OAuth 2.1, and an audit trail. Speaks Streamable HTTP and stdio, and negotiates the MCP revision: 2026-07-28 (current, and the default since upstream released it on 2026-08-03), 2025-11-25, and 2025-06-18 — what most shipping clients still speak today. A client asks for what it knows; it is not negotiated down.

Quickstart (60 seconds)

Add it to your MCP client (Claude Desktop, Cursor, Claude Code) — there is no Node runtime at run time, the npm package is a launcher that fetches the native binary for your platform and verifies its checksum before running it:

JSON Config
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "postgres-mcp-hardened", "--stdio"],
      "env": { "DATABASE_URL": "postgres://readonly_user:PASSWORD@localhost:5432/mydb" }
    }
  }
}

The connection string goes in env, not in args, on purpose: arguments show up in ps output and in shell history on a shared machine, and a database password does not belong there. Use a least-privilege read-only role (--print-setup-sql writes the statements). Other ways in: Install.

To try the whole thing against a real database first, docker compose -f examples/docker-compose.yml up -d brings up PostgreSQL with sample data and the server in front of it, connecting as a role that holds SELECT and nothing else.

Try to break it — one command, no database

The read-only guard has an offline mode. Hand it a statement and it says what it decided: no database, no configuration, nothing installed permanently.

Terminal
npx postgres-mcp-hardened --validate "/* comment */ DROP TABLE users"
# REJECT: non-read-only statement: Drop

npx postgres-mcp-hardened --validate "SELECT 1; DROP TABLE users"
# REJECT: multiple statements are forbidden

npx postgres-mcp-hardened --validate "WITH d AS (DELETE FROM t RETURNING *) SELECT * FROM d"
# REJECT: non-read-only statement: non-read-only query (CTE / SELECT INTO / FOR UPDATE)

npx postgres-mcp-hardened --validate "SELECT * FROM orders WHERE id = 1"
# ALLOW

If something that writes comes back ALLOW, that is the most valuable thing anyone can send us. It needs no working exploit and no write-up — one line of SQL and "this should not be allowed" is a complete report. Anything that gets past the guard goes through SECURITY.md; everything else is an ordinary issue, and the bar for opening one is this looks wrong to me, not I am certain.

The fuzzer is deterministic and prints its seed, so whatever it finds reproduces on a machine that has never seen yours — a million mutations take about a minute:

Terminal
npx postgres-mcp-hardened --fuzz 1000000
# fuzz: 1000000 iterations, seed 1592594996, slowest validation 8 ms
# RESULT: 0 invariant violations

Every bypass found so far lives in the MUST_REJECT corpus in src/validate.rs and runs on every commit, recorded with what it cost rather than tidied away. Yours would join them.

@modelcontextprotocol/server-postgres is deprecated on npm (last publish December 2024) and still sees hundreds of thousands of monthly downloads: 581,980 downloads in the 30 days to 28 November 2026 (npm). Credit where it is due: its approach is not naive — it wraps each query in BEGIN TRANSACTION READ ONLY and always ROLLBACKs, which is a real defence and one this server now adopts as well. Its entire defence is that one database-level read-only transaction, and that alone does not stop every write.

This server stacks the layers instead:

  • AST validation (sqlparser) in front of the database: multi-statement input, DROP, writing CTEs and SELECT ... INTO are rejected before they are sent.
  • The read-only transaction and the rollback, as in the original, plus a denylist for the functions that write despite them.
  • Timeouts and cost limits: statement_timeout, idle_in_transaction_session_timeout and an EXPLAIN cost guard.
  • A start-up gate: no network listener when the role it was given can write.
  • Authentication and audit: OAuth 2.1, and a tamper-evident hash-chained audit log.
  • Prompt-injection handling: row data is wrapped trusted="false" with delimiter escaping.

The problem is that it is the only defence, and it is not complete:

  • A read-only transaction does not block every write, and a rollback does not undo everything it lets through. Two separate facts, and the second is the one that matters.

    gin_clean_pending_list() runs inside SET TRANSACTION READ ONLY and its work survives the rollback: an index with 25 pending pages has 0 after the transaction is rolled back. pg_backup_start() puts the session into backup state, survives DISCARD ALL, and with the default fast => false waits for a spread checkpoint while forcing full_page_writes on, which is a real cost on a busy server. pg_import_system_collations() also executes without raising SQLSTATE 25006, but be careful how much weight you put on it: that one IS undone by a rollback, so against a server that always rolls back it is a curiosity rather than a bypass.

    Reproduce it, but read the two preconditions first, because without them you will see a zero or an error and conclude we made this up. All three need superuser or ownership of the object. And the import only restores collations that are missing, so something has to be removed first:

    Dockerfile
    -- as superuser, and note these are three separate transactions: a statement that errors
    -- inside a block aborts the whole block, so they cannot be run as one.
    DELETE FROM pg_collation WHERE oid IN (SELECT oid FROM pg_collation ORDER BY oid DESC LIMIT 200);
    
    BEGIN READ ONLY;
      DELETE FROM pg_collation WHERE collname LIKE 'zu%';  -- ERROR: cannot execute DELETE ...
    ROLLBACK;
    
    BEGIN READ ONLY;
      SELECT pg_import_system_collations('pg_catalog');    -- 200, no error
    COMMIT;                                                -- and now the rows are there
    

    Both are writes, both are inside a read-only transaction, and one is refused while the other is not. That asymmetry is why this server does not treat the transaction as its only defence. It is also why the role matters more than any of this: every example above needs privileges a least-privilege reader does not have, and this server refuses to start as a network listener when the role it was given can write. What it cannot control is which connection string somebody pastes into a client config, and the usual answer is whichever one they already had.

  • No statement timeout, no cost guard, no row limit — one query can run until the server gives up.

  • No authentication, no audit trail, no handling of prompt injection through returned row data.

  • One source file of 143 lines, unmaintained since December 2024, no test suite.

This server keeps the rollback, adds AST validation in front of it, and adds the operational layers the original never had.

Status: pre-1.0

This is 0.1.x, and it is meant to be read that way. The first release was 0.1.0 on 9 August 2026. What it has been through, all of it recorded in CHANGELOG.md:

  • Six rounds of audit or outside review, each with its findings and the query that reproduced them: an external review of the tool surface and an independent reviewer (0.1.7); an outside review of a draft article, four reviewers, six bypasses (0.1.8, finished in 0.1.10); the maintainers' own audit of the released 0.1.10 (0.1.11); the maintainers' second audit of the released 0.1.11, with 618 live probes over PostgreSQL 13 to 18, and an independent review before the tag (0.1.12). An earlier independent review is written up in docs/AUDIT_2026-07-26.md.
  • A deterministic fuzzer that prints its seed (--fuzz, above), and a corpus of bypasses (MUST_REJECT) that runs on every commit.
  • Two published security advisories: GHSA-xjfm-h4wm-qmp6 (0.1.10) and GHSA-cxv3-jw58-9gr9 (0.1.11, fixed in 0.1.12). Both were found by us, in our own releases.

What it has not been through: nobody outside this project has run it against their own data. Wanted: deployments on real, read-only databases, and reports of whatever looks wrong — a bypass through SECURITY.md, anything else as an issue. Known limits are documented, not hidden, in THREAT_MODEL.md.

Latest release

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about PostgreSQL (hardened, read Only)

PostgreSQL (hardened, read-only) is an MCP server that lets AI agents query PostgreSQL while refusing writes during SQL validation and enforcing a READ ONLY transaction. It supports Streamable HTTP and stdio, with timeouts, cost limits, OAuth 2.1, an audit trail, and multiple MCP protocol revisions.

It blocks writes at two layers: parsed SQL validation refuses write statements, and the database connection uses a READ ONLY transaction. This provides defense in depth beyond relying only on PostgreSQL transaction settings.

It supports Streamable HTTP and stdio transports, and negotiates MCP revisions 2026-07-28, 2025-11-25, and 2025-06-18. A client requests the revision it understands rather than being automatically negotiated down.

Yes.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewPostgreSQL (hardened, read Only) AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/postgresql-hardened-read-only?style=directory)](https://allmcps.com/mcp/postgresql-hardened-read-only)
HTML Embed
<a href="https://allmcps.com/mcp/postgresql-hardened-read-only"><img src="https://allmcps.com/api/badge/postgresql-hardened-read-only?style=directory" alt="PostgreSQL (hardened, read Only) on AllMCPs" /></a>