Kaiva Postgres MCP logo

Kaiva Postgres MCP

Read-only PostgreSQL MCP server. Drop-in replacement for the archived server-postgres.

Install Kaiva Postgres MCP

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": {
    "postgres-2": {
      "command": "npx",
      "args": [
        "-y",
        "@kaiva/postgres-mcp",
        "<database_url>"
      ]
    }
  }
}

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

Claude Code command
claude mcp add --transport stdio postgres-2 -- npx -y @kaiva/postgres-mcp '<database_url>'

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 @kaiva/postgres-mcp <database_url>

Process exited before answering 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

Tools3

What Kaiva Postgres MCP lets your agent do. Expand a tool for its parameters.

Self-reported~65 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.

11/11 checks healthy over the last 45d

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 12d ago via OSV.dev · @kaiva/postgres-mcp (npm)

Adoption & maintenance

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

GitHub stars1Stargazers on the source repository.
npm downloads1.1kPackage downloads in the last 30 days.
Last commit1mo agoMost recent push to the default branch.
Install checkInconclusiveDidn't respond in our test window — often a slow first install.
Tools exposed3Callable tools this server registers over MCP.

From the project README

Kaiva Postgres MCP

The Postgres MCP server that stays read-only. A drop-in replacement for the archived @modelcontextprotocol/server-postgres.

Switch in one line

Where your AI client starts the archived server today:

config.json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
    }
  }
}

change the package name:

json
      "args": ["-y", "@kaiva/postgres-mcp", "postgresql://localhost/mydb"]

In Claude Code:

Terminal
claude mcp add postgres -- npx -y @kaiva/postgres-mcp postgresql://localhost/mydb

The query tool, its sql input and the table schema resources are the same, so nothing else changes.

Other ways in, with DATABASE_URL set in your environment:

  • Claude Code plugin: /plugin install postgres-mcp --marketplace ai-kaiva/postgres-mcp
  • Gemini CLI extension: gemini extensions install https://github.com/ai-kaiva/postgres-mcp, then gemini extensions config kaiva-postgres-mcp to enter the database URL
  • Docker: docker run -i --rm -e DATABASE_URL ghcr.io/ai-kaiva/postgres-mcp once the image is published

Why switch

The archived server is no longer maintained: Anthropic archived it in 2025 as a reference example rather than production software, and npm marks it "Package no longer supported". It runs whatever text it is given inside BEGIN TRANSACTION READ ONLY, and that is not enough:

  • COMMIT; DROP SCHEMA public CASCADE ends the read-only transaction and drops the schema (reported by Datadog Security Labs in August 2025; the fix never reached npm, where 0.6.2 is still the latest version).
  • With a superuser login, which is what most local and Docker installs start with, one statement can run a shell command on the database server: PostgreSQL runs COPY ... TO PROGRAM inside a read-only transaction.

We checked both against version 0.6.2 on PostgreSQL 14: both ran. Kaiva Postgres MCP refuses both.

Archived 0.6.2Kaiva Postgres MCP
A second statement after COMMITRunsRefused: one statement per call, and PostgreSQL itself refuses a second
COPY ... TO PROGRAM, server file reads, dblinkRun, if the login allowsRefused
Time limitNone15 seconds per statement, 3 seconds waiting for a lock
Rows returnedAll of themThe first 1,000, and it says so
Superuser loginUsed as givenWarning on this machine; refused for a database on another machine unless you allow it
Tables listedpublic schema onlyEvery schema
Dates and timestampsTurned into JavaScript dates, which can shift a date to the day beforeExactly as PostgreSQL prints them
ErrorsReturned as protocol errorsReturned to the AI with what to fix
MaintainedNoYes

Tools

  • query: run one read-only SQL statement (SELECT, WITH, VALUES, TABLE, SHOW or EXPLAIN) and get the rows as JSON.
  • list_tables: the tables and views this login can read, with type, estimated row count and comment.
  • describe_table: one table's columns, primary key, unique and foreign keys, the tables that reference it, and its indexes.
  • database_health: the largest tables and indexes, indexes not used since statistics were last reset, the slowest queries (from pg_stat_statements, when it is installed, with their values replaced by placeholders and comments removed), the cache hit rate and the tables with the most dead rows. It runs only fixed SQL from this package, read-only and within the time limit of one query call, and lists only tables this login can read.

Resources: each table's columns, as the archived server listed them.

How read-only is enforced

On every call:

  1. The SQL is checked before it is sent: one statement, starting with SELECT, WITH, VALUES, TABLE, SHOW or EXPLAIN, calling no function that reaches past the transaction (dblink, server file functions, lo_import and lo_export, pg_terminate_backend, advisory locks, and functions that run SQL given to them as text).
  2. It runs alone, through PostgreSQL's extended query protocol, which refuses a second statement, inside a READ ONLY transaction with a statement time limit and a lock time limit.
  3. The transaction is always rolled back, and DISCARD ALL resets the session, so nothing a statement sets up outlives it.

Only the first 1,000 rows are fetched from the database (one more is read, to know whether more exist), so a query over a large table returns quickly.

Use a login that can only read

The strongest guard is a login that cannot write. Run this once as an administrator, then put mcp_readonly in the connection URL:

sql
CREATE ROLE mcp_readonly LOGIN PASSWORD 'choose-a-password';
GRANT CONNECT ON DATABASE mydb TO mcp_readonly;
GRANT pg_read_all_data TO mcp_readonly;  -- PostgreSQL 14 and later
ALTER ROLE mcp_readonly SET default_transaction_read_only = on;

To see what a login can do:

Terminal
npx -y @kaiva/postgres-mcp postgresql://mcp_readonly:...@localhost/mydb --check

Options

OptionDefault
--max-rows <n>1000Rows returned per query, 1 to 10000
--timeout <seconds>15Time limit per statement, 1 to 300
--allow-superuseroffAllow a superuser login on a database on another machine. In Docker Compose the database is another container, so this applies there too; a read-only login is the better answer
--checkConnect once, report what the login can do, and exit

Give the connection URL as the first argument, or set DATABASE_URL. TLS settings go in the URL (sslmode, sslrootcert), as with psql.

What it does not protect

  • Anything the login can read, the AI can read: tables, views and foreign tables, and with a superuser the system catalogs too (pg_authid holds password hashes). Use a login that sees only the tables you mean to share.
  • The refused-function list is a second guard, not a sandbox. It sees the SQL the AI sends, not what a view, a foreign table (file_fdw) or a function already defined in your database does when it is read. With a superuser login such an object can still read a file on the database server. With a login that can only read, PostgreSQL itself refuses (checked: a view over pg_read_file reads the file as a superuser and is refused as a read-only login).
  • database_health lists only statements whose values PostgreSQL replaces with placeholders (SELECT, WITH, INSERT, UPDATE, DELETE, MERGE, VALUES, TABLE, but not SELECT ... INTO), removes their comments and shows any value left in them as $?. pg_stat_statements itself still holds other statements as typed, values included (checked on PostgreSQL 14: ALTER ROLE ... PASSWORD), and a superuser, or a login granted pg_read_all_stats, can read them through query. Use a login that can only read: it sees only its own statements there.
  • "This machine" means localhost, 127.x, ::1, a Unix socket, *.localhost and host.docker.internal (the Docker host). Anywhere else, Docker Compose service names and private network addresses included, a superuser is refused unless --allow-superuser is given.

In Claude.ai, ChatGPT or for your team

This package runs on your machine. To use the same database from Claude.ai or ChatGPT, or share it with your team behind sign-in, Kaiva Bridge serves it as a managed MCP server. In a project folder whose .env holds DATABASE_URL:

Terminal
npx @kaiva/bridge push mydb --db

Your database must be reachable from the internet. https://kaiv.ai/bridge?utm_source=postgres-mcp&utm_medium=readme

License

MIT

Reviews

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

Frequently Asked Questions about Kaiva Postgres MCP

Kaiva Postgres MCP is an MCP server that provides read-only access to PostgreSQL databases for AI clients. It is a drop-in replacement for the archived @modelcontextprotocol/server-postgres package, exposing compatible query, SQL input, and table-schema resources. It supports one-statement queries, enforces PostgreSQL read-only transactions, limits execution time, and returns at most 1,000 rows.

Replace @modelcontextprotocol/server-postgres with @kaiva/postgres-mcp in your MCP configuration while keeping the PostgreSQL connection URL and other settings unchanged. For example, use npx -y @kaiva/postgres-mcp postgresql://localhost/mydb. Claude Code can add it with claude mcp add postgres -- npx -y @kaiva/postgres-mcp postgresql://localhost/mydb.

Kaiva Postgres MCP executes one read-only SQL statement per call when it starts with SELECT, WITH, VALUES, TABLE, SHOW, or EXPLAIN. Each statement runs in a PostgreSQL READ ONLY transaction, has a 15-second statement limit and a 3-second lock-wait limit, and returns at most the first 1,000 rows.

Kaiva Postgres MCP provides query, list_tables, and describe_table tools. query returns rows as JSON; list_tables shows readable tables and views across schemas with their type, estimated row count, and comment; describe_table shows columns, keys, referencing tables, and indexes. Table-column resources are also available.

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 PreviewKaiva Postgres MCP AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/postgres-2?style=directory)](https://allmcps.com/mcp/postgres-2)
HTML Embed
<a href="https://allmcps.com/mcp/postgres-2"><img src="https://allmcps.com/api/badge/postgres-2?style=directory" alt="Kaiva Postgres MCP on AllMCPs" /></a>