Sqlike Mcp

io.github.orifisher2由 GitHub 账号 orifisher2 发布v0.2.3更新于 Nov 3, 2026

Lints SQL and checks rewrites return the same rows. Postgres, MySQL, MariaDB, SQLite, MSSQL, DuckDB

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

概览

AI 生成的概览

确定性的 SQL 静态检查与改写等价性校验服务器,让助手在查询运行前检查 SQL,并证明改写后返回相同结果。

可以做什么
  • 分析单条 SQL 查询,返回有效性错误、反模式、建议改写以及表结构与索引建议,可选传入 DDL、表行数、执行计划和方言。
  • 比较两条查询,给出是否等价的判定、置信度,以及列、行、基数、顺序等逐项报告。
适用场景
适合在助手编写、修改或审查 SQL 时先做检查再执行;也适合在查询被重写或优化后,需要证据证明结果未变,而不是依赖模型自行判断。
运行要求
以 npm 包形式通过 stdio 在本机运行,通常用 npx 启动。分析引擎是闭源的托管服务,需要网络访问。可选设置 SQLIKE_API_KEY 以获得更高频率限制,不设置则使用无需注册的匿名额度。
安装前请注意
查询、表结构和执行计划在本地分词脱敏后发送到第三方托管 API;无法解析的查询默认拒绝发送,除非显式开启原始发送。diff 返回 Undecided 绝不代表等价。可选的 API 密钥属于机密,需妥善保管。

安装

在 SourceWeft 中

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

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

其他 MCP 客户端

参照 仓库 中的启动说明。

README

sqlike: MCP server and CLI

[@sqlike/mcp] [@sqlike/cli] [license]

Check your SQL before it runs, and check whether a rewrite still returns the same results.

sqlike reads a query and tells you what is wrong with it: validity errors, anti-patterns, rewrites it can apply for you, and index advice. It also compares two queries and reports whether the second one still returns the same results. There is no model anywhere in the analysis, so the same query always gets the same answer.

This repository holds the clients: an MCP server, a CLI, and the library they share. They tokenize your SQL locally, so identifiers and literals are masked before anything leaves your machine, and forward only the tokenized query. The analysis engine is not in this repo. It runs server-side and is closed.

Dialects: Postgres, MySQL, MariaDB, SQLite, SQL Server, and DuckDB. Each rule carries a verdict measured on that engine, so the severity you get is that database's behaviour and not Postgres by inheritance. DuckDB is the columnar one: it has no general-purpose secondary index, so the ten index advisors are replaced there by four columnar ones.

Why

A lot of SQL is written by an AI now, and the SQL it writes reads well more often than it runs correctly. A LEFT JOIN turns into an INNER and rows quietly disappear. A WHERE goes missing and the UPDATE hits every row. Two tables get joined on the wrong key. None of it looks wrong on the page, and none of it shows up until it has already done something.

sqlike is the check in between. It flags unsafe patterns from a catalog of 172 rules, each one verified against a real database before it ships, and it decides whether a rewrite preserves results. That second check is sound rather than complete: it certifies the rewrites it can prove, and when it cannot prove one it answers Undecided instead of guessing. Undecided never means equivalent.

Because nothing is generated, there is no retry loop, no per-token cost, and no variance between two runs on the same input. The equivalence check normalizes rather than solves, so it answers in about a millisecond where the state-of-the-art academic prover takes hundreds. That is measured head to head, including the queries where the prover wins.

Install the MCP server

Add it to any MCP client (Claude Code, Claude Desktop, Cursor, and so on):

json
{  "mcpServers": {    "sqlike": { "command": "npx", "args": ["-y", "@sqlike/mcp"] }  }}

Or install it through Smithery. Set SQLIKE_API_KEY if you have a key and want the higher rate limits. Without one you get the anonymous tier, which needs no signup.

Tools

analyze

Static analysis of one query: validity, anti-patterns, suggested rewrites, and schema and index advice. Returns the JSON analysis envelope.

ArgumentTypeDescription
sqlstringThe query to analyze. Required.
schemastringOptional DDL (CREATE TABLE / CREATE INDEX) for column and type aware checks.
statsstringOptional JSON map of table to row count, e.g. {"orders": 2000000}. Severity and index advice follow volume.
explainstringOptional query plan (Postgres EXPLAIN (ANALYZE, FORMAT JSON), MySQL EXPLAIN FORMAT=JSON, SQLite EXPLAIN QUERY PLAN as .mode json rows, SQL Server SHOWPLAN_XML, DuckDB EXPLAIN (FORMAT JSON)). Confirms or dismisses index findings by what the planner did.
dialectstringpostgres (default), mysql, mariadb, sqlite, mssql, or duckdb.
allow_rawbooleanOnly used when a query fails to parse, and so cannot be tokenized: send the raw SQL to get a parse diagnostic. Default false.

diff

Checks whether two queries are equivalent, which is the judgement an LLM cannot reliably make about its own rewrite. Returns a verdict (Equivalent, EquivalentWithNotes, Differs, or Undecided), a confidence level, and a report per property (columns, rows, cardinality, order), so you see what changed rather than a single yes or no.

ArgumentTypeDescription
sql_astringThe original query. Required.
sql_bstringThe rewritten query to check against sql_a. Required.
schemastringOptional DDL both queries resolve against (one shared schema).
dialectstringpostgres (default), mysql, mariadb, sqlite, mssql, duckdb.

CLI

The same checks from a terminal or a CI job. Run it with no install, or put it on the path:

sh
npx -y @sqlike/cli --helpnpm i -g @sqlike/clibrew install orifisher2/sqlike/sqlike
sh
# analyze a query — the hosted API is the default, so no flags are neededsqlike check query.sql
# several files at once, with a schemasqlike check migrations/*.sql --schema schema.sql
# reading from stdin, machine-readable output (one JSON record per file)cat query.sql | sqlike check - --schema schema.sql --json
# check that a rewrite is equivalentsqlike diff before.sql after.sql

Point it elsewhere with --remote or SQLIKE_URL, and authenticate with --key or SQLIKE_API_KEY.

If you have the query's EXPLAIN output, pass it with --explain plan.json and the real access paths will confirm or dismiss the index findings. The plan is tokenized before it leaves the machine, same as the query and the schema.

Exit codes are a contract, so each one means exactly one thing:

checkdiff
0clean, or nothing at or above --fail-onequivalent
1a warning, when --fail-on warn asks for itdiffers
2a blocking defect: invalid SQL, or a high-severity correctness problemundecided
3operational — unreachable, rate-limited, or unparseablesame
4usage error (a bad flag)same

check defaults to --fail-on block, so advisory findings report without failing a build. Ask for --fail-on warn to be strict, or never to only report. 3 is never a verdict about your SQL — a pipeline can tell "this query is bad" from "the call did not go through".

In CI, and on commit

Gate SQL where it is written. Both run the same checks as the CLI, and both tokenize locally first.

GitHub Actions. Findings land inline on the pull-request diff. The workflow authenticates as your repository owner using GitHub's own OIDC token — no signup, no API key to store or leak.

yaml
permissions:  id-token: write        # authenticate as this repo's owner  pull-requests: read    # check only the files this PR changes  contents: read         # mode: diff, to read the earlier version of a filesteps:  - uses: actions/checkout@v5  - uses: orifisher2/[email protected]    with:      dialect: postgres      schema: db/schema.sql

Set mode: diff and it answers a different question on every pull request: did this rewrite change what the query returns? Only modified files are compared, and a verdict of "cannot prove either way" never fails a build.

Pull requests from forks run anonymously. GitHub does not issue OIDC tokens to workflows a fork triggers, so a contributor's pull request cannot authenticate as your repository — it falls back to an anonymous, per-IP rate limit. Nothing is broken and there is nothing to configure; your own branches still authenticate normally. The action says so rather than suggesting a permission that would not help.

Outside a pull request there is no set of changed files, so changed-only cannot apply and every matching file is checked. The action warns when that happens, because on a large repository it is enough requests to reach a rate limit.

pre-commit. Same checks before the commit lands:

yaml
repos:  - repo: https://github.com/orifisher2/sqlike    rev: cli-v0.4.2    hooks:      - id: sqlike        args: [--dialect, postgres]

The hook blocks a commit on a real defect, not on a bad connection: if sqlike cannot be reached it says so and lets the commit through.

Private by design

Tokenization happens here, on your machine, before any request goes out. sqlike never sees your real table names, columns, or values, so there is nothing to leak and nothing to train on. An AI assistant needs the real thing to help you; sqlike does not.

If a query cannot be parsed it cannot be tokenized, and the client refuses to send it rather than transmit raw SQL. Sending it anyway is an explicit opt-in (allow_raw on the tools, --allow-raw on the CLI).

See THREAT-MODEL.md for what that does and does not cover.

What is in this repo

  • crates/mcp: sqlike-mcp, the MCP server. Ships to npm as @sqlike/mcp.
  • crates/cli: sqlike, the command-line client. Ships to npm as @sqlike/cli.
  • crates/client: the shared forwarder, with no engine in it: tokenize, call the API, detokenize.
  • crates/core-parse: the SQL parser, stage model, tokenizer, and result types.
  • packages/: the npm packaging, with a prebuilt binary per platform.
  • skills/: the agent skill, so a coding agent knows when to reach for sqlike on its own.

Learn more

Try it at sqlike.com. The equivalence checker is measured in public against the standard academic benchmark, including a head-to-head with the state-of-the-art prover, at sqlike.com/benchmark.

Note

This repository is generated from the upstream monorepo, which is the source of truth. Please file issues here. Code changes are made upstream and mirrored back.

License

Apache-2.0. See LICENSE.

crates/sqlparser is a vendored copy of sqlparser-rs, also Apache-2.0. Its NOTICE file records the upstream version and lists every file changed since.

来源:README.md,提交 ef85632

工具

2

analyze

Use when you write, edit, or review a SQL query and want it checked before it runs. Returns SQLike's deterministic analysis as a JSON envelope: validity errors, anti-patterns, safe rewrites, and schema/index advice. Pass optional schema DDL for column- and type-aware checks, table row counts (stats) so severity follows volume, an EXPLAIN plan so index findings are confirmed or dismissed by what the planner did, and dialect (postgres default, mysql, mariadb, sqlite, mssql, duckdb — DuckDB is columnar, so its severities and index advice differ). The query is tokenized locally before it leaves the machine — identifiers and literals are masked. A query that does not parse is answered locally, with a parse-error finding that names the mistake, or names the construct SQLike does not support yet and says the query is valid, and sends nothing. A query holding a name that can't be masked makes the tool refuse rather than send raw SQL; on that refusal, ask the user whether to send the raw query, and only then call again with allow_raw=true

输入参数sql必填statsschemadialectexplainallow_raw

diff

Use to confirm two SQL queries are equivalent — whenever you rewrite, refactor, or optimize a query and need to prove it still returns the same results (something an LLM cannot reliably self-grade). Returns SQLike's deterministic JSON verdict: an overall result (Equivalent / EquivalentWithNotes / Differs / Undecided / NotComparable), a confidence level, and a per-property report (columns, rows, cardinality, order). Undecided never means equivalent. If one query is invalid (a missing table or column, an ambiguous reference) the pair is Differs, since a query that does not run cannot return the same rows as one that does; if both are invalid it is NotComparable, with a reason for each. A query that does not parse is refused with the reason: the mistake, or the construct SQLike does not support yet. Both queries share one optional schema DDL; dialect is postgres default, mysql, mariadb, sqlite, mssql, duckdb.

输入参数sql_a必填sql_b必填schemadialect

版本历史

3
  1. v0.2.3最新Oct 29, 2026
  2. v0.2.2Oct 6, 2026
  3. v0.1.1Sep 16, 2026

评分

已满足适用检查项的 90%

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

  • 近 30 天内可连通25 分
  • 已声明认证方式10 分

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

  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分