
MySQL Audit
io.github.jimmyjan0824由 GitHub 帳號 jimmyjan0824 發布v0.3.3更新於 Oct 29, 2026
MySQL migration and query safety review for AI agents: locks, table copies, data loss, injection.
發布方自己的服務:audit.domains - Domain Valuation
概覽
本機 MCP 伺服器,審查 MySQL 遷移、查詢與應用程式碼的正式環境風險,並給出 safe/review/block 結論。
- 可以做什麼
- 審查遷移與 DDL:資料表複製、寫入鎖、中繼資料鎖堆積、資料遺失、缺少回復或備份
- 審查資料變更與查詢:沒有 WHERE 的 UPDATE/DELETE、未分批回填、會中斷複寫的語句、無法使用索引的 WHERE/JOIN 欄位
- 審查應用程式原始碼中的 SQL 注入寫法
- 產生部署前應在主庫執行的檢查 SQL
- 依規則 ID 說明規則,並列出所有規則與其預設嚴重程度
- 適用情境
- 當 AI 編碼代理要撰寫或執行 MySQL 結構變更、大量寫入或查詢,而你希望在進入正式環境前取得確定性的 DBA 式審查時使用。也適合檢查應用程式碼中的 SQL 注入,以及產生部署前檢查。
- 執行需求
- 以 stdio 方式在本機執行;需要 Python 3.10 以上,或 uv/uvx(README 的 MCP 設定使用 uvx)。不需要連線資料庫、帳號或 API 金鑰。選用的 schema 匯出、資料表統計 JSON、MySQL 版本與可用磁碟空間可逐次傳入或寫在 .mysql-audit.toml;MYSQL_AUDIT_VERSION 環境變數可覆寫版本。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 MySQL Audit,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
mysql_audit_ai_agent
English | 繁體中文
MySQL schema-change safety review for AI coding agents.
Before Claude Code, Cursor or another agent runs a migration, it sends the SQL to
review_migration and gets back a verdict (safe / review / block) plus, for
every risk, the line, what will happen in production, and a safe way to write it.
The checks are deterministic rules written from DBA experience, not another LLM guess.
Status: beta. Every rule about server behavior is checked against real MySQL in CI. DBAs: try the trial kit and report wrong results.
Contents: Why · What it checks · Quick start · Use with an AI agent (MCP) · Command line · Rules · Inputs that make results exact · Pre-deploy checks · Rollbacks and backups · GitHub Action · Version and upgrades · Troubleshooting · DBA trial kit · Development
Why
AI coding agents write and run migrations quickly, but the SQL that looks correct is often the
SQL that takes production down: an ALTER TABLE that silently copies a 25-million-row table and
blocks writes, a column type change that forces a full rebuild, a DROP COLUMN the previous
release still reads, an UPDATE without WHERE, a backfill that leaves every replica minutes
behind. These are the incidents a DBA catches in review, and an agent has no DBA in the loop.
MySQL Audit puts that review in front of the agent:
- Before it runs, not after. The agent calls the review tool before executing a migration,
query or SQL-building code. On
blockit rewrites and reviews again. - Deterministic. The same SQL always gets the same verdict. Each rule that depends on server behavior is tested against real MySQL 5.7, 8.0 and 8.4 in CI.
- Actionable. Every finding has the line, the production impact and a concrete fix (for
example
ALGORITHM=INSTANT, gh-ost, batching by primary key, expand and contract). - Local and private. It never connects to your database and runs entirely on your machine. Your SQL and data never leave it.
What it checks
- Migrations and DDL: table copies and write locks (Online DDL
ALGORITHM/LOCK), version-dependent INSTANT changes, metadata-lock pile-ups, foreign keys, unique keys, large tables, free disk for rebuilds, data loss fromDROP/TRUNCATE/RENAME, missing rollbacks and backups. - Data changes:
UPDATE/DELETEwithoutWHERE, unbatched backfills,LIMITwithoutORDER BY, statements that stop replication (sql_log_bin = 0). - Queries:
WHERE/JOINcolumns no index can use. - Schema design: tables without a primary key, auto-increment columns that will overflow,
utf8mb3. - Security: SQL injection in application code (Python, JS/TS, PHP, Go, Java) and dangerous
GRANTs.
It is used in three ways:
Quick start
You need Python 3.10 or later, or uv (uv brings its own Python).
1. Review a file from the command line
Example output:
2. Let your AI agent use it (Claude Code)
From then on, Claude reviews migrations before running them. Other agents: see Use with an AI agent.
3. Review every pull request with the GitHub Action.
Use with an AI agent (MCP)
Requires uv. The server runs locally over stdio; your SQL never leaves your machine.
Claude Code
--scope user makes it available in every project. --scope project writes it to the
project's .mcp.json instead, so everyone who clones the repo gets it. Check that it is
connected with claude mcp list (it should show mysql-audit ... ✓ Connected), or type /mcp
inside Claude Code to see the tools. Then ask Claude to review a migration, or just let it run one:
it calls review_migration on its own. Remove it with claude mcp remove mysql-audit.
/mcp says Failed to reconnect to mysql-audit: ENOENT? Claude Code cannot find the
uvx command: uv is not installed, or it is installed in a folder that is not on the PATH
Claude Code was started with.
Restart Claude Code (or reconnect in /mcp) afterwards. The first start downloads the
package and can take a few seconds.
Cursor, Windsurf, Claude Desktop and other MCP clients (mcp.json / claude_desktop_config.json):
Restart the client after editing. If a desktop app reports spawn uvx ENOENT, it cannot find
uvx: replace "uvx" with the full path from which uvx (Windows: where uvx).
Claude Desktop, one click: download mysql-audit.mcpb from the
latest release and open it.
Running
uvx mysql-audit-ai-agentin a terminal prints nothing and seems to hang. That is expected: it is the MCP server, waiting for an MCP client to talk to it over stdin. Press Ctrl+C to leave. Put the command in your client's MCP config as above, and usemysql-audit(see Command line) to review files yourself, for exampleuvx --from mysql-audit-ai-agent mysql-audit migration.sql.
Tools
Arguments the call leaves out are read from .mysql-audit.toml.
Example prompts to try: "Add a nickname column to users", "Drop the note column from
orders", "Check this Python for SQL injection: cur.execute(f\"... {email}\")",
"Explain mysql-audit rule L03".
In our agent evaluation Claude Code called the tool on its own in 10 of 10 migration tasks, with no extra prompt.
Command line
Examples:
Exit code: 0 = safe, 1 = review, 2 = block, so it can gate any CI.
Verdicts: block means do not run it as written; review means it can run but a person
should read the findings first; safe means no findings at warn level or above. Each finding
has a severity (block, warn, info), a line number, the impact and a fix.
Rules
Tables created earlier in the same script are treated as empty, so DDL on them is not flagged.
mysql-audit cannot explain a rule by itself; ask the agent ("explain rule L03") or read
src/mysql_audit/rules/.
Inputs that make results exact
Without extra input the review is conservative: it cannot tell a 100-row table from a 100-million-row one, or what type a column has now. Three inputs fix that. None of them needs a connection from the tool to your database; you export them once.
-
schema: the current
CREATE TABLEstatements (SHOW CREATE TABLE, ormysqldump --no-data --skip-comments your_db > schema.sql). -
stats: approximate size per table from
information_schema.tables, either row counts ({"orders": 25000000}) or rows and bytes:From a shell:
mysql -N -e "<the query above>" your_db > stats.json. A table counts as large at 1,000,000 rows or 5 GB (data plus indexes), and as small under 10,000 rows. With bytes, L03 states how much free space a rebuild needs. -
free disk (
--free-disk-gb,free_disk_gb): free space on the server's data volume, fromdf -h /var/lib/mysqlon the host or your cloud console (RDS / Aurora: theFreeStorageSpacemetric). With table bytes it enables L17.
MySQL version
Which ALTERs run INSTANT depends on the server version: 5.7 has no INSTANT,
8.0.12–8.0.28 only adds columns at the end instantly, and 8.0.29+ also adds anywhere
and drops columns instantly. Without a version the tool assumes 8.0.29+ and says so in
the result. Pass the version you deploy to (SELECT VERSION();), for example 8.0.28,
5.7.44 or aurora-3.04:
Project settings (.mysql-audit.toml)
To avoid repeating options, put a .mysql-audit.toml at the repository root. The CLI,
the MCP server and the GitHub Action all read it (searching upward from the current
directory, stopping at the .git folder); options given on the command line or in the
tool call win.
The MYSQL_AUDIT_VERSION environment variable overrides mysql_version for the CLI and
the MCP server, for example
claude mcp add mysql-audit -e MYSQL_AUDIT_VERSION=8.0.28 -- uvx mysql-audit-ai-agent.
Pre-deploy checks
The review never connects to your database. What only the live server knows (open transactions, metadata locks, replica lag) is checked by SQL you run on the primary right before deploying:
The queries are scoped to the tables the migration touches, and each returns rows only when
the deploy should wait: transactions open longer than 10 seconds, statements on those tables
running 10 seconds or more, sessions holding or waiting for their metadata locks, and tables
that are large right now. The script also says how to check that every replica lags 10 seconds
or less. No rows from every query means go. CI runs it against MySQL 5.7, 8.0.28, 8.0 and 8.4,
with and without a blocking transaction. Agents get the same SQL from the preflight_checks tool.
Rollbacks and backups
L18 warns when a migration with review or block findings has no way back, and when it deletes data without saying where the backup is. It accepts any of these as a rollback:
- a down section in the same file:
-- +goose Down,-- migrate:down(dbmate),-- +migrate Down(sql-migrate); - Liquibase
--rollbacklines; - a sibling file:
*.down.sqlnext to*.up.sql(golang-migrate), orU<version>__*.sqlnext toV<version>__*.sql(Flyway); - for a one-off script, a note:
-- rollback: <what to run>.
A backup is noted with -- backup: <where it is>, for example
-- backup: s3://db-backups/shop/orders_2026-10-28.sql.gz. Down migrations are not reviewed
as changes themselves.
GitHub Action
Reviews the migrations each pull request adds or changes, annotates the lines in the diff,
keeps one summary comment on the pull request up to date, and fails the check on block.
When the result is review or block, the comment ends with a pre-deploy checklist and the preflight SQL for the changed migrations.
DBA approval. Some blocked changes are fine after a DBA has looked, for example a
DROP COLUMN the application stopped using two releases ago. List the DBAs in
dba-approvers: when one of them approves the pull request, the check passes. The approval
must be on the latest commit, so a later push needs a new one, and a later "request changes"
from the same person withdraws it. A ticked checkbox would not do here, because anyone who can
edit the pull request can tick it.
Rollbacks. Down migrations are not reviewed as changes: *.down.sql (golang-migrate) and
U<version>__*.sql (Flyway) count as the rollback of their up file, and so do down sections
(-- +goose Down, -- migrate:down, -- +migrate Down) and Liquibase --rollback lines.
Version and upgrades
mysql-audit --version prints the installed version (mysql-audit-ai-agent --version for
the MCP server). To upgrade:
Troubleshooting
Upgraded, but mysql-audit still runs the old version? (For example,
--version is rejected as an unrecognized argument.) The shell is finding another copy
first, such as an older uv tool install in ~/.local/bin, or it still remembers the old path:
If the first copy is not the one you upgraded, activate that environment
(source .venv/bin/activate), or upgrade or remove the other copy
(uv tool upgrade mysql-audit-ai-agent / uv tool uninstall mysql-audit-ai-agent).
.venv/bin/mysql-audit --version checks a venv's copy directly.
DBA trial kit
trial/ has 24 example migrations and 2 code samples on a small shop
schema (orders 25M rows, users 2.4M), each marked with the verdict it should get. Every
example also runs on MySQL 8.0 and 8.4 in CI. Guides: English ·
繁體中文.
With uv instead: uv run --no-project --with mysql-audit-ai-agent python trial/run.py.
Found a wrong result (a false alarm, a missed risk, or a fix that doesn't work)? Please use the report form.
Development
Every rule has positive and negative test cases under tests/.
To try your local changes in Claude Code without publishing, point it at your checkout. Each
session runs the code as it is now; after an edit, restart Claude Code or reconnect in /mcp.
tests/test_mysql_oracle.py checks the rules against a real server: each ALTER is
run with ALGORITHM=INPLACE, LOCK=NONE, and MySQL's refusal (or not) must match the
rule's verdict. CI runs it on MySQL 8.0 and 8.4. tests/test_mysql_versions.py checks the
version-dependent INSTANT judgment the same way on 5.7, 8.0.28 and 8.4. Locally:
Project layout
Releasing
Bump the version in pyproject.toml, src/mysql_audit/__init__.py, server.json (twice),
mcpb/manifest.json and the Action example in this README and in README.zh-TW.md, merge, then
publish a GitHub release tagged vX.Y.Z on main. The Release workflow checks that the tag
matches every version field, then publishes to PyPI and the MCP Registry and attaches the
.mcpb bundle.
License
Apache-2.0
來源:README.md,提交 7f096da
工具
0版本歷史
1- v0.3.3最新Oct 29, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分
其他 Audit 整合
audit.domains - Domain Valuation
domains.audit官方發布者
確定性的網域名稱估值服務:提供公允價值區間、真實可比成交紀錄、可用性查詢,以及經 DNS 驗證的待售網域市場。
Revenue Agent — OpenAPI Audit & Change Detection
news.prh官方發布者
一個遠端 MCP 端點,用於稽核 OpenAPI 規格並偵測 API 變更,每次分析透過 Base 上的 x402 收取 0.10 USDC。

SEO Audit & Broken Link Checker
由 GitHub 帳號 prometheus-maker 發布
由 Apify 託管的 MCP 伺服器,用來稽核網站頁面的 SEO 中繼資料並找出失效連結與圖片,回傳每頁評分。

FinePrint AI Legal Risk & Contract Audit MCP Server
由 GitHub 帳號 RitualDev-Lab 發布
在本機記憶體中執行的合約風險掃描器,為編碼代理評估法律合約、NDA 與租約風險並產生修訂建議。

Mcp Supply Audit
由 GitHub 帳號 kimmawla 發布
把 MCP 伺服器當成供應鏈產物來稽核:登錄檔項目、PyPI/npm 套件、用戶端設定與工具定義,全為唯讀靜態檢查。