MySQL MCP Server - A universal MySQL MCP Server for database diagnostics, performance analysis, and query execution
18 tools with complete input schemas and descriptions. Naming follows verb_noun pattern (connect, query, show_*, kill_*, list_*, describe_*, sample_*, search_*, count_*, explain, disconnect). Descriptions are detailed and domain-specific (100-300 chars), explaining WHAT, WHEN, and context. Parameters have types and descriptions. However, output schemas are not formally documented in the code, only inferred from docstrings. No error handling guidance, no recovery hints, no parameter constraints (enums, ranges). No tool annotations (readOnlyHint/destructiveHint). Missing idempotency guarantees and confirmation patterns for destructive ops (kill_query, disconnect).
连接 MySQL 实例。host 必传,user/password 可省略(从 config.yaml 读取)。用不同 alias 可同时连接多个实例。 连接成功后自动返回服务器元数据(版本、sql_mode、时区、双一配置等),供后续工具判断特性支持与 SQL 语法。
返回表行数估算与数据大小(information_schema.TABLES,不扫业务表)。 database 必传(由 mysql_describe_schema 返回的 database 传入)。InnoDB 的行数为统计估算值,非精确 COUNT。
返回表或视图的 DDL(SHOW CREATE TABLE/VIEW):列、类型、主键、索引、外键、引擎、字符集、注释。 table 传表/视图名即可。定位顺序:1) 带库名前缀('mydb.orders')直接用; 2) 取当前连接库;3) 未选库时跨库搜同名对象(唯一即用,多个返回候选库名)。
断开指定连接。
查看 SQL 执行计划,返回 dict 格式,用于性能分析与索引优化。
终止指定连接正在执行的 SQL(KILL QUERY),保留连接本身。用于紧急杀掉慢查询、长事务、 阻塞型 DDL、元数据锁等问题 SQL,避免连锁阻塞与性能事件。 process_id 为 SHOW PROCESSLIST / mysql_show_active_connections 中的连接 ID。
Output schemas not formally documented. Docstrings describe return types informally ('dict', 'list[dict]') but no structured JSON Schema is visible. LLMs cannot reliably parse response structure or plan downstream tool calls.
No tool annotations (readOnlyHint, destructiveHint, idempotentHint). Destructive tools (kill_query, disconnect) lack explicit marking. LLMs cannot distinguish safe reads from dangerous writes without annotations.
| Scored | Grade | Overall | Spec posture | Rubric |
|---|---|---|---|---|
| 2026-09-23 | C | 63 | 2026-07-28+ | v2 |
列出所有活跃连接。
查 ibd 文件超过阈值的表,按文件大小降序。用于发现大表、评估空间占用与优化方向。 min_size_gb 默认 10;limit 默认 10,上限 50。 返回 total(符合阈值的全量表数)与 data(前 limit 条)。
查长时间未提交的 InnoDB 事务,按持续时长降序。用于发现持锁不放、导致 undo log 膨胀与 purge 阻塞的事务。 min_duration_sec 为最小持续时长(秒,默认 60),返回 thread_id 可配合 mysql_kill_query 终止。
执行任意只读 SQL,超过 2000 行自动截断。
抽样表数据(SELECT * FROM table LIMIT N),供 AI 理解字段语义、值格式、枚举范围。 database 必传(由 mysql_describe_schema 返回的 database 字段传入);limit 默认 10,上限 50。
按关键词搜表名/列名/表注释,返回匹配的表与列。纯 information_schema 查询,不扫业务表, 用于在几千张表里定位相关表,再走 mysql_describe_schema / mysql_sample_data 深入。表最多 100 条,列最多 200 条。
查看活跃连接(非 Sleep、非 event_scheduler、排除自身及 SHOW PROCESSLIST 监查查询),按耗时降序,用于发现长查询与锁等待。
SHOW ENGINE INNODB STATUS,返回死锁日志、事务状态、缓冲池、锁等诊断信息。
分析 InnoDB 锁阻塞关系:谁被谁阻塞、等待时长、锁对象、持锁/等待连接的用户主机状态; 持锁连接已 Sleep 导致 blocker_query 为空时,通过 events_statements_current 关联出 blocker_last_sql(最后执行的 SQL),附 kill 阻塞线程建议。
查看按 SQL 指纹聚合的执行统计,按平均单次耗时降序,定位真正慢的 SQL。 按平均单次耗时(AVG_TIMER_WAIT)而非总耗时排序——总耗时受执行次数影响,高频但每次都快的 SQL 会掩盖真正单次慢的 SQL。rows_examined_ratio(扫描行数/返回行数)可辅助判断是否缺索引。 该表为 MySQL 启动以来的累积值,为避免历史数据误导,within_hours 仅返回 last_seen 在该时长 内的近期活跃 SQL(最低 1 小时,默认 24 小时,最大 360 小时)。limit 控制返回条数(1-50,默认 20)。
SHOW GLOBAL STATUS,返回状态变量字典。用于性能分析:连接数、缓冲池命中率、慢查询等。
SHOW GLOBAL VARIABLES,返回配置变量字典。如 innodb_buffer_pool_size、max_connections 等。
No error handling guidance or recovery hints. Tools return errors but do not tell LLMs what to do next (retry, ask user, abort). E.g., 'Connection failed' vs 'Connection failed: host unreachable. Verify host/port and retry.'
No parameter constraints (enums, ranges, patterns). E.g., limit params (1-50) lack min/max validation hints. LLMs may pass invalid values; tools must validate and return actionable errors.
Destructive operations (kill_query, disconnect) lack confirmation/dry-run patterns. Agents may accidentally kill critical queries or drop connections. No safeguard against misuse.