原型 · 预览版:收录官方注册中心里的全部服务器,每 30 分钟同步一次。使用 Google 登录即可撰写评价。
PopNx MCP为使用 AI 的人准备的 MCP 服务器 · 用大白话讲清楚

sw-postgres-mcp

作者:jpka版本 0.3.1i★ 0i在你的电脑上运行
注册名称io.github.jpka/sw-postgres-mcp

安装方法

概览

作者提供的说明(英文原文)

Safe-write Postgres MCP server with preview-before-execute writes and rollback safety.

它能帮你做什么

我们还没有为它写通俗的介绍。下面是我们从注册中心读取到的事实。

  • 连接方式: 在你的电脑上运行
  • 传输方式: stdio
  • 分类: 数据库与数据集
  • 你需要填写:DATABASE_URL_READONLY, DATABASE_URL_WRITER

安装

选择你使用的 AI 应用,然后复制设置。

通过 2/2 项检查 · 在你的电脑上运行

第一步:你用哪个 AI?

选择你用的应用,步骤会显示在下方。

可连接 Claude,但需要先准备

需要 sw-postgres-mcp 的密钥(在开发者网站注册,可能收费) · 需要先在电脑上安装 Node.js(只需一次) · 仅限电脑上的 Claude 应用(Windows 或 Mac),网页和手机不可用

  1. 安装 Node.js

    只需一次,所有需要 Node.js 的服务器都能用

    打开 Node.js 下载页 ↗

  2. 注册并创建 sw-postgres-mcp 的密钥

    打开开发者网站,注册账户并创建 API 密钥,下一步要用。可能收费。

    获取密钥的方法见下方开发者的 README

  3. 打开电脑版 Claude 应用的设置文件

    SettingsDeveloperEdit Config

  4. 粘贴这些设置并保存文件

    {
      "mcpServers": {
        "sw-postgres": {
          "command": "npx",
          "args": [
            "-y",
            "sw-postgres-mcp"
          ],
          "env": {
            "DATABASE_URL_READONLY": "your-value",
            "DATABASE_URL_WRITER": "your-value"
          }
        }
      }
    }

    只把密钥粘贴到应用的输入框里,不要粘贴到聊天中或发给任何人

  5. 退出 Claude 再重新打开

  6. 试一试

    用 sw-postgres-mcp 告诉我你能帮我做什么,然后做一件给我看

    ✓ 如果 Claude 说正在使用 sw-postgres-mcp,或回答中出现 sw-postgres-mcp 的工具名称,就表示连接成功

菜单名称已于 2026年11月11日 对照 Anthropic 帮助页面核实 · 你的界面可能因版本略有不同

ChatGPT 暂时无法连接 sw-postgres-mcp

sw-postgres-mcp 需要安装在你的电脑上,而 ChatGPT 只能连接在网上运行的服务器

你可以改用这些方式

A · 使用能连接 sw-postgres-mcp 的应用

  • 需要 sw-postgres-mcp 的密钥(在开发者网站注册,可能收费) · 需要先在电脑上安装 Node.js(只需一次) · 仅限电脑上的 Claude 应用(Windows 或 Mac),网页和手机不可用
  • 需要 sw-postgres-mcp 的密钥(在开发者网站注册,可能收费) · 需要先在电脑上安装 Node.js(只需一次)
  • 需要 sw-postgres-mcp 的密钥(在开发者网站注册,可能收费) · 需要先在电脑上安装 Node.js(只需一次)
  • 需要 sw-postgres-mcp 的密钥(在开发者网站注册,可能收费) · 需要先在电脑上安装 Node.js(只需一次)

B · 数据库与数据集 类中能连接 ChatGPT 的其他服务器

从同类中使用较多的里挑选,仅限用地址即可连接、无需密钥的

可连接 Claude Code,但需要先准备

需要 sw-postgres-mcp 的密钥(在开发者网站注册,可能收费) · 需要先在电脑上安装 Node.js(只需一次)

  1. 安装 Node.js

    只需一次,所有需要 Node.js 的服务器都能用

    打开 Node.js 下载页 ↗

  2. 注册并创建 sw-postgres-mcp 的密钥

    打开开发者网站,注册账户并创建 API 密钥,下一步要用。可能收费。

    获取密钥的方法见下方开发者的 README

  3. 打开终端

    Mac:按 Command+空格,输入 Terminal · Windows:打开 PowerShell

  4. 粘贴这条命令并按 Enter

    claude mcp add sw-postgres --env DATABASE_URL_READONLY=your-value --env DATABASE_URL_WRITER=your-value -- npx -y sw-postgres-mcp

    按 Enter 前,把“your-value”改成你的密钥

    只把密钥粘贴到应用的输入框里,不要粘贴到聊天中或发给任何人

  5. 在 Claude Code 中输入 /mcp

    应能看到 sw-postgres-mcp 在列表中并显示已连接

  6. 试一试

    用 sw-postgres-mcp 告诉我你能帮我做什么,然后做一件给我看

    ✓ 如果 Claude Code 说正在使用 sw-postgres-mcp,或回答中出现 sw-postgres-mcp 的工具名称,就表示连接成功

菜单名称已于 2026年11月11日 对照 Anthropic 帮助页面核实 · 你的界面可能因版本略有不同

可连接 Cursor,但需要先准备

需要 sw-postgres-mcp 的密钥(在开发者网站注册,可能收费) · 需要先在电脑上安装 Node.js(只需一次)

  1. 安装 Node.js

    只需一次,所有需要 Node.js 的服务器都能用

    打开 Node.js 下载页 ↗

  2. 注册并创建 sw-postgres-mcp 的密钥

    打开开发者网站,注册账户并创建 API 密钥,下一步要用。可能收费。

    获取密钥的方法见下方开发者的 README

  3. 点击这个按钮打开 Cursor

    在 Cursor 中打开

    Cursor 会请你确认安装,点击 Install

  4. 填写你的密钥

    在 sw-postgres-mcp 的设置中,DATABASE_URL_READONLY, DATABASE_URL_WRITER 还是空的,填入你的密钥并保存

    只把密钥粘贴到应用的输入框里,不要粘贴到聊天中或发给任何人

  5. 在 Cursor 中以 Agent 模式打开 AI 聊天

  6. 试一试

    用 sw-postgres-mcp 告诉我你能帮我做什么,然后做一件给我看

    ✓ 如果 Cursor 说正在使用 sw-postgres-mcp,或回答中出现 sw-postgres-mcp 的工具名称,就表示连接成功

菜单名称已于 2026年11月11日 对照 Cursor 帮助页面核实 · 你的界面可能因版本略有不同

可连接 VS Code,但需要先准备

需要 sw-postgres-mcp 的密钥(在开发者网站注册,可能收费) · 需要先在电脑上安装 Node.js(只需一次)

  1. 安装 Node.js

    只需一次,所有需要 Node.js 的服务器都能用

    打开 Node.js 下载页 ↗

  2. 注册并创建 sw-postgres-mcp 的密钥

    打开开发者网站,注册账户并创建 API 密钥,下一步要用。可能收费。

    获取密钥的方法见下方开发者的 README

  3. 点击这个按钮打开 VS Code

    在 VS Code 中打开

    VS Code 会请你确认安装,点击 Install

  4. 填写你的密钥

    在 sw-postgres-mcp 的设置中,DATABASE_URL_READONLY, DATABASE_URL_WRITER 还是空的,填入你的密钥并保存

    只把密钥粘贴到应用的输入框里,不要粘贴到聊天中或发给任何人

  5. 在 VS Code 中以 Agent 模式打开 AI 聊天

  6. 试一试

    用 sw-postgres-mcp 告诉我你能帮我做什么,然后做一件给我看

    ✓ 如果 VS Code 说正在使用 sw-postgres-mcp,或回答中出现 sw-postgres-mcp 的工具名称,就表示连接成功

菜单名称已于 2026年11月11日 对照 VS Code 帮助页面核实 · 你的界面可能因版本略有不同

其他支持 MCP 的应用(如 Windsurf、Zed、Gemini CLI)添加方式各不相同,请在应用列表中查看

查看所有支持 MCP 的应用 →

JSON 设置在下方“开发者专用”中

卡住了?问问正在用 sw-postgres-mcp 的人💬 讨论 →
开发者专用:终端命令和 JSON 设置

安装在电脑上

Claude Code

claude mcp add sw-postgres --env DATABASE_URL_READONLY=your-value --env DATABASE_URL_WRITER=your-value -- npx -y sw-postgres-mcp

Claude Desktop (claude_desktop_config.json)

{
  "mcpServers": {
    "sw-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "sw-postgres-mcp"
      ],
      "env": {
        "DATABASE_URL_READONLY": "your-value",
        "DATABASE_URL_WRITER": "your-value"
      }
    }
  }
}

Cursor (~/.cursor/mcp.json)

{
  "mcpServers": {
    "sw-postgres": {
      "command": "npx",
      "args": [
        "-y",
        "sw-postgres-mcp"
      ],
      "env": {
        "DATABASE_URL_READONLY": "your-value",
        "DATABASE_URL_WRITER": "your-value"
      }
    }
  }
}

VS Code (mcp.json)

{
  "servers": {
    "sw-postgres": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "sw-postgres-mcp"
      ],
      "env": {
        "DATABASE_URL_READONLY": "your-value",
        "DATABASE_URL_WRITER": "your-value"
      }
    }
  }
}

需要你填写的值

  • DATABASE_URL_READONLY 机密 必填 env
    Postgres connection string for the read-only role.
  • DATABASE_URL_WRITER 机密 必填 env
    Postgres connection string for the writer role.

这些设置是根据作者在注册中心的条目生成的。如果 README 的写法不同,请以 README 为准。

一览

每周下载量i
49/周
许可证i
未注明许可证
连接方式
在你的电脑上运行
最新版本i
0.3.1
发布到注册中心i
2026年8月15日
代码最后更新i
2026年9月5日
作者
jpka
软件包
npm: sw-postgres-mcp
注册状态
活跃

哪些应用可以使用它

依据这个服务器的连接方式和各应用自己的文档,检查于 2026年11月10日。

在你的电脑上运行,适用于

ClaudeGooseLM StudioMsty StudioCherry StudioCursorVS Code + GitHub CopilotVisual StudioWindsurf (Devin Desktop)ZedKiroClineContinueJetBrains AI AssistantClaude CodeCodex CLIGemini CLIOpenCodenodecodeWarpLibreChatRaycast

全部应用及其优缺点 →

它能做什么

它在你的电脑上运行;安装后,工具列表会显示在你的 AI 应用中。

基础检查i

我们检查的是任何人都能看到的信息;我们没有阅读代码。不适用的检查项不计入总数。 · 检查于 2026年11月11日

  • ✓ 通过

    作者与仓库一致

    注册名称已通过 GitHub 账户 jpka 验证,该账户拥有此仓库

  • ✓ 通过

    仍在维护

    代码最后更新于2个月前

  • … 尚未检查

    有许可证

    我们还没有从 GitHub 读取这个仓库

  • – 不适用

    端点有响应

    它在你的电脑上运行,没有互联网端点

  • – 不适用

    使用 OAuth 登录

    在你的电脑上运行,改用本地设置

  • … 尚未检查

    工具描述中没有隐藏指令

    它在你的电脑上运行;我们只能读取互联网端点的工具列表

讨论

提问、分享技巧或报告无法使用。按“有帮助”数量排序。

还没有帖子,欢迎第一个提问或分享。

此处内容由用户撰写,不代表 PopNx 团队。

使用 Google 登录后发帖

用户评价

还没有评价

用 Google 登录后写评价

与“数据库与数据集”中的其他服务器比较i

  • 星标数多于此分类中其他 1162 个服务器的 0%
  • 发布到注册中心的时间比此分类中其他 1162 个服务器的 22% 更新
  • 基础检查结果等于或优于此分类中其他 1162 个服务器的 100%

与注册中心里这个分类中所有活跃的服务器比较。只有当发布者拥有该仓库时,星标数才计入。

常见问题

sw-postgres-mcp 安全吗?

它在 2 项适用的基础检查中通过了 2 项。我们没有阅读代码。在添加密钥或令牌之前,请先看看这个服务器要求哪些权限,并使用只具备所需权限的密钥。

它需要哪些密钥或代码?

你需要填写:DATABASE_URL_READONLY, DATABASE_URL_WRITER

它在我的电脑上运行还是在云端?

它在你的电脑上运行。你的 AI 应用会在需要时启动它,数据不会经过作者的服务器(除非它自己调用在线服务)。

它还在维护吗?

GitHub 仓库最后更新于2个月前,最新版本(0.3.1)于3个月前进入注册中心。

哪些应用可以使用它?

支持 MCP 的应用,例如 Claude Desktop、Claude Code、Cursor 和 VS Code。你的电脑上还需要有 Node.js。

有什么可以替代它?

同一分类中有:Dbx, MCP Toolbox for Databases, MCP Toolbox for Databases

替代选择

同一分类中其他作者的服务器,按星标数排序。

如何看卡片:↓ 每周下载量i★ GitHub 星标i三大支柱:评价 · 检查 · 使用情况i更新 = 最新版本发布到注册中心的时间i

Dbx

Query databases from AI agents using connections configured in DBX.

作者:t8y2广泛使用↓ 9446/周★ 3万6个月前更新

在你的电脑上运行

MCP Toolbox for Databases

MCP Toolbox for Databases enables your agent to connect to your database.

作者:googleapis广泛使用★ 1.7万5天前更新

在你的电脑上运行

MCP Toolbox for Databases

MCP Toolbox for Databases enables your agent to connect to your database.

作者:googleapis广泛使用★ 1.7万8个月前更新

在你的电脑上运行

作者的 README

打开 README

按原文从作者的仓库复制。PopNx MCP 没有审查或背书其内容。HTML、图片和脚本已被移除。链接会离开本站。

Safe-write Postgres MCP server

An agent can read and modify a database without being able to cause an unrecoverable accident. The differentiator is the safety layer, not the tool coverage: 8 MCP tools, 3 of them read-only, 4 write tools that only ever *preview* a change, and one execute_plan that commits a previewed change and nothing else.

Architecture

 Claude (agent)

│ MCP stdio (tools/call) ▼ sw-postgres-mcp │ ├─ describe_schema / query / explain_plan ──► readonly pool ──► Postgres "readonly" role (SELECT only) │ ├─ delete_rows / insert_rows / update_rows / run_migration │ │ │ ▼ │ TwoPhaseWrite.preview() │ BEGIN → run the real statement → ROLLBACK │ DML (delete_rows/insert_rows/update_rows): capture exact RETURNING count + sample │ DDL (run_migration): no RETURNING to capture — reports 0 affected rows, a target │ table/schema extracted from the statement text, and always │ goes to "awaiting_approval" regardless of that row count │ └─► plan_token = sha256(statement + params) ("statementFingerprint") │ ├─ affected_rows ≤ approvalRequiredAboveRows → status: "previewed" │ ├─ affected_rows > approvalRequiredAboveRows → status: "awaiting_approval" │ └─ affected_rows > hardMaxRows → refused outright, no token issued │ (run_migration ignores both thresholds — every DDL preview is "awaiting_approval") │ ├─ execute_plan(plan_token, statement, params) ──► writer pool ──► Postgres "writer" role (DML + DDL) │ re-derives the fingerprint from what was passed back and refuses on any mismatch │ (STATEMENT_MISMATCH) or an affected-row-set that changed since preview (ROWSET_CHANGED) │ └─ every preview / approval / execution / rejection / refusal ──► mcp_audit.log (INSERT-only grant; UPDATE/DELETE/TRUNCATE revoked — see "Audit log" below)

an "awaiting_approval" plan surfaces at: localhost approval UI — http://127.0.0.1:4319/?token= (bound to 127.0.0.1, human-only; the token is printed once on stderr at startup and every route requires it as Authorization: Bearer or ?token= — see "Localhost approval UI" below) approve() / reject() are called directly on the shared TwoPhaseWrite instance — never exposed as an MCP tool the agent itself can reach

Two Postgres connection pools, each authenticated as a distinct role (see Threat model below): readonly for describe_schema/query/explain_plan, writer for the four write-preview tools and execute_plan. All 4 write tools — delete_rows, insert_rows, update_rows, run_migration — share one core, TwoPhaseWrite (src/writeCore.ts): every one of them previews inside a transaction that always rolls back, then requires a separate execute_plan call with the exact plan token to actually commit. There is no 5th write tool and no tool that skips the preview step — execute_plan is the only thing in this server that commits anything, and it only ever replays a statement that was already previewed. See Tools below for what each tool takes and returns, and Two-phase writes for the mechanics.

Threat model

The risk here is not SQL injection. delete_rows, insert_rows, and update_rows take structured arguments — table, where + parameterized params, a set object — and every value in those structured inputs goes through $n placeholders, never string concatenation (see update_rows's note on this in Tools). run_migration is different: DDL can't be parameterized the way DML values can, so it sends its raw agent-supplied statement directly to Postgres, the same way query/explain_plan already handle raw SQL — its safety comes not from parameterization but from always requiring human approval regardless of row count (see Tools), never from an $n-placeholder guarantee it doesn't have. The agent is the *author* of the SQL it sends, and it's a trusted-but-fallible author: it isn't trying to escape a quote, but it can absolutely produce a syntactically perfect, well-formed statement whose *scope* is the problem — DELETE FROM users WHERE active = false when 40,000 rows happen to match, or an UPDATE that silently drops its WHERE clause because the agent forgot one. That is the failure mode this project is built to survive, and three mechanisms carry the weight:

1. Preview-and-rollback, not `EXPLAIN`. EXPLAIN only ever gives the Postgres planner's *estimate* of how many rows a statement will touch, derived from table statistics that can be stale (especially right after a bulk load, before ANALYZE has run) or simply wrong for a correlated predicate the planner can't model well. An approval gate built on an estimate is a gate an agent (or ordinary data skew) can defeat by accident, not just by malice — a statement whose *true* affected-row count is 40,000 could still sail under a threshold if the planner guessed 80. So every write tool here instead runs the real statement inside BEGIN … ROLLBACK: the row count in the preview is the exact count a real execution just produced, not a projection. EXPLAIN still has a job — the standalone explain_plan tool offers it as a cheap, side-effect-free pre-check an agent can call before ever attempting a two-phase write — but it is never what the approval thresholds compare against.

2. Role separation, not parsing. readonly and writer are two distinct Postgres roles with distinct grants (docker/init/01-roles.sql): readonly has SELECT only (and CREATE explicitly revoked on its schema); writer has SELECT, INSERT, UPDATE, DELETE, gated further by this project's own write allowlist. A mutating statement submitted through the readonly pool is refused by Postgres itself with permission denied — verified against a live database in tests/roles.test.ts, not just asserted in code. The alternative — parsing or regex-matching SQL text to decide "is this a write?" — was deliberately not made the safety boundary: a parser can always be fooled by a form it wasn't written to catch (a CTE-wrapped WITH x AS (DELETE FROM ... RETURNING *) SELECT * FROM x, a mutating function call, a quoting edge case), and getting that wrong is a security hole, not a cosmetic bug. query/explain_plan do still reject non-SELECT statements and enforce the read allowlist by extracting table references from the statement text (src/tools/sqlGuard.ts) — but that is explicitly a second, defense-in-depth layer on top of the role grant, not the property itself. See DECISIONS.md for the full reasoning, including why a gap in that text-based allowlist parsing (which needed several hardening passes for quoted/Unicode-escaped identifiers) is a bounded allowlist-bypass risk rather than a "read tool executed a write" risk.

3. Plan tokens bind to a statement-hash fingerprint. A plan token by itself — a random, opaque ID — would only prove "some preview happened at some point." It says nothing about *which* statement was previewed, which means a token alone can't stop a bait-and-switch: swap in a wider WHERE clause, a different table, extra rows, and hand the same-looking token to execute_plan. So every token is bound to statementFingerprint(statement, params) — a SHA-256 hash of the trimmed statement text plus the JSON-serialized parameter list — computed at preview time and re-derived from whatever execute_plan is actually called with; any mismatch is refused as STATEMENT_MISMATCH before anything runs. This is what makes a human's approval in the localhost approval UI mean something: they're approving the *exact* statement and params they were shown, not a token that could later be replayed against different SQL. (A second, independent check — the rows-affected digest — separately catches the case where the *same* statement now matches a different row set because of concurrent activity; see Two-phase writes below.)

See Limitations for what this model deliberately does not cover, and DECISIONS.md for the full write-up of each of these three decisions plus the approval-mechanism spike (#1).

Quick start

docker compose up -d

npm install npm test npm run build

Point Claude Desktop at the server (see config.example.json and Claude Desktop section below). node dist/index.js also starts a localhost approval UI at http://127.0.0.1:4319/ alongside it — open the full URL (with ?token=...) the server prints once on stderr, since every route requires the per-session bearer token.

Configuration

Copy config.example.json to config.json (or set SW_POSTGRES_CONFIG to a custom path):

{

"database": { "readonlyConnectionString": "postgres://readonly:readonly_password@localhost:5432/mcp_test", "writerConnectionString": "postgres://writer:writer_password@localhost:5432/mcp_test" }, "allowlist": { "read": { "schemas": ["public"], "tables": [] }, "write": { "schemas": [], "tables": [] } } }

  • allowlist.read — schemas/tables the agent may see via describe_schema/query. If empty, all tables are readable. If tables is non-empty, only those fully-qualified tables are listed.
  • allowlist.write — schemas/tables the agent may mutate. Defaults to deny: if both schemas and tables are empty, nothing is writable. Add entries explicitly.
  • write.planTtlMs — how long a plan_token stays valid (default 60000). Overridable with SW_PLAN_TTL_MS.
  • write.statementTimeoutMs — per-connection statement_timeout for write executions (default 10000). Overridable with SW_STATEMENT_TIMEOUT_MS.
  • write.approvalRequiredAboveRows — a preview whose exact rollback-preview affected-row count is at or below this returns a token execute_plan will honour immediately, same as today. Above it, the preview instead returns status: "awaiting_approval" and the token is refused by execute_plan until a human approves it out-of-band (see Approval threshold and hard row cap below — approval is deliberately not an agent-facing MCP tool). Default 100. Overridable with SW_APPROVAL_REQUIRED_ABOVE_ROWS.
  • write.hardMaxRows — a second, higher, separate threshold. A preview whose exact affected-row count exceeds this is refused outright: no token is issued at all, and there is no approval path — the response is a flat structured error (HARD_MAX_ROWS_EXCEEDED), not something to escalate past. Default 10000. Overridable with SW_HARD_MAX_ROWS. Must be >= write.approvalRequiredAboveRows; loadConfig throws otherwise.
  • approvalServer.enabled — whether the localhost approval UI starts alongside the MCP server (default true). Overridable with SW_APPROVAL_SERVER_ENABLED ("true"/"false"). With it disabled, no plan can ever be approved, so any preview that would require approval (above write.approvalRequiredAboveRows, or any run_migration) is refused outright with a structured APPROVAL_UNAVAILABLE error — no plan_token is issued — rather than issuing a plan that would only block execute_plan until expiry.
  • approvalServer.port — port the localhost approval UI listens on, bound to 127.0.0.1 only (default 4319). Overridable with SW_APPROVAL_SERVER_PORT.
  • approvalServer.requireAuth — whether the localhost approval UI requires its per-session bearer token on every route, including the read-only GET ones (default true). Loopback binding plus the Host/Origin/Sec-Fetch-Site provenance checks stop a hostile bro

只显示了开头部分;其余内容请在仓库中阅读