Locksmith

io.github.cxk280由 GitHub 账号 cxk280 发布v0.1.1更新于 Oct 24, 2026

Lints PostgreSQL migrations for dangerous locking operations and suggests safe rewrites.

已验证STDIO仅桌面数据库开发者工具

概览

AI 生成的概览

Locksmith 检查 PostgreSQL 迁移中的危险锁操作,返回 PASS/REVIEW/BLOCK 结论、问题说明和安全改写建议。

可以做什么
分析 PostgreSQL 迁移,给出结论、逐条语句的问题说明和安全改写建议,可选择按大表假设处理。解释某种 Postgres 锁模式会阻塞什么、由什么操作获取。读取表级锁兼容性矩阵和完整规则目录等参考资源。使用 review-migration 提示把迁移风险总结为 PR 评论。
适用场景
适合在助手审查或编写 PostgreSQL 架构迁移时使用,在部署前对锁风险做确定、可重复的检查,而不依赖模型自身对锁语义的推理。
运行要求
通过 npx 从 npm 包 locksmith-mcp 以 stdio 在本地运行,需要 Node.js。无需账号、API 密钥、环境变量或网络访问。
安装前请注意
仅为建议性检查,不能证明安全;它倾向于多报,无法解析的语句会降级为人工审查提示。内联禁用注释可抑制规则,包括对下一条语句抑制全部规则。它只读取你提供的 SQL,不会修改数据库。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Locksmith,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Locksmith 🔒

An MCP server that catches dangerous SQL migrations before they lock your database.

Most migrations look harmless and then take down production: a plain CREATE INDEX blocks every write for the length of the build; ALTER COLUMN ... TYPE rewrites the whole table under ACCESS EXCLUSIVE; SET NOT NULL scans every row. Which operations are safe — and the rewrite that makes the dangerous ones safe — is knowledge that lives in senior engineers' heads.

Locksmith encodes that knowledge as a tool an LLM agent (or a human) can call. Give it a PostgreSQL migration; it returns a PASS / REVIEW / BLOCK verdict, a finding for each risky statement (which lock it takes, why that's dangerous), and a concrete safe rewrite.

🛑 BLOCK — do not ship as written
## 🛑 CREATE INDEX without CONCURRENTLY  `create-index-non-concurrent` (line 5)> `CREATE INDEX idx_users_email ON users (email)`Problem: This index build will block all writes to the table until it completes.Lock taken: SHARE (blocks writes)Fix: Build the index with CREATE INDEX CONCURRENTLY, which does not block writes.Suggested rewrite:  CREATE INDEX CONCURRENTLY idx_users_email ON users (email)

Why an MCP server?

An agent can often reason about lock semantics — but not reproducibly, and not in a way you can test, audit, or trust to gate a deploy unsupervised. The same prompt may approve a table-rewriting ALTER one run and flag it the next, or miss it entirely in a long migration. Locksmith turns that probabilistic capability into a deterministic, tested tool: the lock semantics were verified once (against the PostgreSQL docs and the parser's real behavior, with a test suite pinning each rule) and now run identically every time, returning the same verdict plus a paste-ready fix — so "review this migration" stops being a guess.

Capabilities

Tools

  • analyze_migration(sql, assumeLargeTables?) → verdict + findings + safe rewrites (both human-readable Markdown and validated structured output).
  • explain_lock(query) → what a given Postgres lock mode blocks and what takes it.

Resources

  • locksmith://lock-matrix — the PostgreSQL table-level lock compatibility matrix.
  • locksmith://rules — the full rule catalog (id, severity, rationale) as JSON.

Prompts

  • review-migration — analyze a migration and summarize the risk as a PR comment.

Rule catalog

RuleSeverityWhat it catches
create-index-non-concurrentcriticalCREATE INDEX without CONCURRENTLY (blocks writes)
index-concurrently-in-transactioncriticalCONCURRENTLY inside BEGIN/COMMIT (Postgres rejects it)
add-column-not-null-no-defaultcriticalADD COLUMN NOT NULL with no default (fails / rewrites)
alter-column-typecriticalALTER COLUMN ... TYPE (full table rewrite)
add-column-volatile-defaultwarningADD COLUMN ... DEFAULT now() etc. (rewrites table)
set-not-nullwarningSET NOT NULL (full scan under exclusive lock)
add-foreign-key-validatingwarningADD FOREIGN KEY without NOT VALID (locks both tables)
add-check-constraint-no-not-validwarningADD CHECK without NOT VALID (full scan)
drop-column-or-tablewarningdestructive + breaks deployed code
rename-column-or-tablewarningbreaks running app code

Suppressing a rule

Acknowledge a deliberate risk inline, eslint-style:

sql
-- locksmith:disable create-index-non-concurrentCREATE INDEX idx_users_email ON users (email);

A bare -- locksmith:disable suppresses all rules for the next statement.

Install & run

No clone or build required — run it straight from npm:

bash
npx locksmith-mcp

Use with Claude Code

bash
claude mcp add locksmith -- npx -y locksmith-mcp

Or add to any MCP client config (Claude Desktop, etc.):

json
{  "mcpServers": {    "locksmith": { "command": "npx", "args": ["-y", "locksmith-mcp"] }  }}

Run from source instead

bash
git clone https://github.com/cxk280/locksmith.git && cd locksmithnpm install && npm run build# then point your client at:  node /absolute/path/to/locksmith/dist/index.js

Try it with the MCP Inspector

bash
npx @modelcontextprotocol/inspector npx -y locksmith-mcp

Then call analyze_migration with the contents of examples/dangerous.sql.

Development

bash
npm run dev    # run from source with tsxnpm test       # vitest: per-rule + golden tests on examples/

Design notes

  • Deterministic. No clock, randomness, or network — same SQL in, same verdict out. That's what makes it testable and safe to drop into CI.
  • Hybrid parsing. Statements are parsed to an AST (pgsql-ast-parser) when the parser supports them; rules fall back to normalized text for Postgres clauses the parser doesn't model (NOT VALID, CONCURRENTLY). An unparseable statement degrades to a "review manually" note — the linter never fails closed on input it doesn't understand.
  • Composable rules. Each rule is a pure function with its own metadata in its own file; adding one is a one-file change plus a line in the registry.
  • Advisory, not a prover. Locksmith complements review; assumeLargeTables defaults to true so it errs toward flagging.

Roadmap

  • Remote (Streamable HTTP) transport for hosted deployments.
  • Additional dialects (MySQL, SQLite).
  • Optional live DB introspection to suppress findings on known-small tables.
  • A GitHub Action wrapping the same engine to gate PRs.

License

MIT

来源:README.md,提交 8707022

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分