Skip to main content
Glama
arzharch

pgops-mcp

by arzharch

pgops-mcp

一个生产级 MCP 服务器,为 AI 代理提供安全、可审计、专家级的控制能力, 可操作真实的 PostgreSQL 数据库及其周围的 Docker 栈——无需 shell 命令, 无需 Python 脚本,只有工具。

为什么

现有的 Postgres MCP 服务器只是轻量的查询包装器:内省 + SELECT。它们都无法处理 带有锁影响分析的迁移,无法从 EXPLAIN + pg_stat_statements 诊断性能,也无法理解 数据库所在的容器化环境。如今操作数据库的代理是在盲目且不安全地飞行。

pgops-mcp 是运维大脑:模式智能 → 受保护的查询 → 迁移引擎 → 性能诊断 → 环境感知, 其安全架构使每个操作都可分类、可确认、可审计。

Related MCP server: PostgreSQL MCP Server

工具面(v0.1)

分组

工具

模式

schema.inspect

查询

query.readquery.write(受保护)、query.explain(解析计划 + 判定)

性能

index.advisedb.health

迁移

migration.plan(预演 + 锁分析)、migration.applymigration.history

环境

env.topologyenv.correlatecontainer.logscontainer.stats

门控

container.restartcontainer.exec

* 除非服务器以 --approval-mode 运行,否则根本不会注册这些工具,即使如此, 每次调用也需要确认令牌。container.exec 还强制使用只读诊断命令白名单——它不提供 shell。Docker 套接字在主机上等同于 root,因此默认是只读访问。

安全模型(核心差异化)

  • 分离的只读 / 读写连接角色;工具绑定到正确的角色

  • 执行前进行语句分类——无界 DELETE/UPDATE 被阻止

  • 破坏性操作需要显式确认令牌

  • 每条执行的语句都会记录到追加式审计日志中,包含时间和判定

  • 通过超时层级取消失控查询

MCP 表面

原语

这里有什么

工具

13 个——模式、查询、解释、建议、迁移、环境

资源

pgops://schemaschema/summaryschema/{table}healthmigrationsaudit/recentconfig

提示

diagnose-slow-queryplan-safe-migrationincident-triagereview-index-healthexplain-safety-model

引导

危险操作直接询问用户,而不是通过代理;确认令牌是后备方案

进度 / 日志

长时间操作期间尽力通知

远程访问与代理令牌

stdio 不需要认证——服务器是客户端生成的子进程,没有开放端口。 HTTP 则需要认证,因此没有密钥时拒绝启动:

pgops-mcp keygen                                    # RS256 keypair
pgops-mcp issue-token --subject my-agent            # read-only by default
pgops-mcp issue-token --subject deploy-bot --scope pgops:read --scope pgops:write
pgops-mcp scopes                                    # which scope each tool needs

pgops-mcp --transport http --public-key ~/.pgops/keys/pgops_public.pem

服务器只持有公钥,因此可以验证令牌但永远无法生成令牌。 作用域(pgops:read / pgops:write / pgops:admin)映射到与防护相同的危险层级, 没有作用域条目的工具需要 admin——默认拒绝。除非另有说明,否则绑定回环地址。

快速开始

uv sync
# point at your local Postgres in Docker:
export PGOPS_DSN="postgresql://user:pass@localhost:5432/mydb"
uv run pgops-mcp            # stdio transport for Claude Desktop / Cursor / VS Code

添加到 Claude Desktop:

{
  "mcpServers": {
    "pgops": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/pgops-mcp", "pgops-mcp"]
    }
  }
}

文档

状态

阶段 0–6b 已完成(319 个测试,每个防护、判定和锁影响规则都通过 testcontainers 针对真实 Postgres 验证——没有模拟——还有端到端套件,通过 stdio 和经过认证的 HTTP 服务器将服务器作为真正的 MCP 子进程驱动)。

阶段

状态

工具

0 · 引导

种子开发栈(120 万行 orders)、CI、lint/类型门禁

1 · 连接核心 + 读取路径

schema.inspectquery.readdb.health

2 · 写入路径 + 安全

query.write、防护、确认令牌、审计日志

3 · 性能大脑

query.explain(计划判定)、index.advise

4 · 迁移引擎

migration.plan(锁分析 + 预演)、applyhistory

5 · Docker 层

env.topologyenv.correlatecontainer.logs/stats/restart/exec

6a · MCP 完整性

资源、提示、引导、进度

6b · 远程 + 认证

HTTP 传输、JWT、作用域代理令牌、密钥生成 CLI

6c · 打包

下一步

PyPI、Smithery、MCP 注册表

migration.rollback 故意保持开放——参见 docs/TOOLS.md

migration.plan 对 120 万行 orders 表进行类型更改时返回的示例:

ALTER TABLE "orders" ALTER COLUMN "total_cents" TYPE bigint
  op=table_rewrite  risk=high  estimate=4800ms  confidence=medium
  why:   rewrites every row and rebuilds every index, holding AccessExclusiveLock
  SAFER: add a new column of the target type, backfill in batches, sync with a
         trigger, swap the names, then drop the old column

快速启动开发数据库(主机端口 5433,以避免与本地 5432 端口上的 Postgres 冲突):

docker compose up -d
export PGOPS_DSN="postgresql://pgops:pgops_dev@localhost:5433/pgops_demo"
uv run pgops-mcp --selfcheck
A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to interact with PostgreSQL databases through schema intelligence, query execution, and DBA tooling including index analysis and health monitoring. Features configurable access levels and audit logging for secure database operations.
    539
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to safely interact with PostgreSQL databases, perform queries, inspect schemas, and analyze query performance.
    2

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/arzharch/pgops-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server