easy-mysql-mcp 1.1.2 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MANUAL.md ADDED
@@ -0,0 +1,120 @@
1
+ # easy-mysql-mcp Manual
2
+
3
+ `easy-mysql-mcp` 是一個用來操作 MySQL 的 MCP server,提供查詢、寫入、批次執行、CSV 匯入,以及 schema / 權限檢查工具。
4
+
5
+ ## Overview
6
+
7
+ 適合用在:
8
+ - 讀取資料
9
+ - 新增、更新、刪除資料
10
+ - 批次執行 SQL
11
+ - CSV 匯入與匯出
12
+ - 需要查看 schema、index、trigger、權限與 query plan 的場景
13
+
14
+ 不適合用在:
15
+ - 多語句 SQL
16
+ - 未驗證字串直接拼接 SQL
17
+ - 繞過 denylist / allowlist / policy hook
18
+
19
+ ## When to Consult This Manual
20
+
21
+ 如果你遇到以下情況,先看這份手冊:
22
+ - 不確定 `mysql_query`、`mysql_execute`、`mysql_batch_execute` 要怎麼用
23
+ - SQL 被拒絕或回傳錯誤
24
+ - 不確定 `?` 參數要怎麼綁定
25
+ - 不確定哪些 SQL 寫法是安全且允許的
26
+ - 不確定應該先查 schema 還是直接執行
27
+
28
+ ## Modes
29
+
30
+ - `readonly`: 只提供讀取相關工具
31
+ - `readwrite`: 預設模式,允許一般讀寫,但不包含 DDL
32
+ - `advanced`: 允許 schema / DDL 類工具
33
+
34
+ ## Tools
35
+
36
+ - `mysql_query`: 讀取資料
37
+ - `mysql_execute`: 執行單一寫入或變更 SQL
38
+ - `mysql_batch_execute`: 以多組參數批次執行同一段 SQL
39
+ - `mysql_import_csv`: 匯入 UTF-8 CSV
40
+ - `mysql_export_csv`: 匯出表格為 UTF-8 CSV
41
+ - `mysql_schema_execute`: 執行 schema / DDL 變更,僅 advanced 模式可用
42
+ - `mysql_list_pending_approvals`: 列出待審核命令
43
+ - `mysql_run_approved_command`: 執行已核准命令
44
+ - `mysql_cancel_approval`: 取消審核
45
+ - `explain_query`: 檢查 query plan
46
+ - `list_tables`, `list_views`, `describe_table`, `describe_index`, `list_triggers`
47
+ - `get_current_privileges`
48
+
49
+ ## Execute Usage
50
+
51
+ `mysql_execute` 只應使用單一 SQL 指令。適合:
52
+ - `INSERT`
53
+ - `UPDATE`
54
+ - `DELETE`
55
+
56
+ `mysql_batch_execute` 適合:
57
+ - 同一個 SQL 搭配多組參數重複執行
58
+ - 大量資料寫入
59
+
60
+ 不要這樣用:
61
+ - 多語句連寫
62
+ - 把使用者輸入直接拼到 SQL 字串裡
63
+
64
+ 參數寫法以 `mysql2` 的 binding 方式為準:
65
+ - 位置型參數使用 `?`
66
+ - 批次執行時,`paramsList` 裡每一組參數都會依序對應 SQL 中的 `?`
67
+ - 建議不要手動拼接字串值,改用參數綁定
68
+
69
+ ## SQL Algebra / Composition Rules
70
+
71
+ MySQL 查詢可視為一個由上而下組裝的代數式:
72
+
73
+ 1. 先決定資料來源:`FROM`
74
+ 2. 再加條件:`WHERE`
75
+ 3. 需要關聯時使用 `JOIN ... ON`
76
+ 4. 有聚合時使用 `GROUP BY`
77
+ 5. 聚合後條件放在 `HAVING`
78
+ 6. 排序使用 `ORDER BY`
79
+ 7. 最後限制筆數:`LIMIT` / `OFFSET`
80
+
81
+ 常見正確組合:
82
+ - 單表查詢:`SELECT ... FROM ... WHERE ...`
83
+ - 聚合查詢:`SELECT ... COUNT(*) ... GROUP BY ... HAVING ...`
84
+ - 多表查詢:`SELECT ... FROM a JOIN b ON ... WHERE ...`
85
+
86
+ 值與欄位的規則:
87
+ - 欄位名稱必要時用反引號包住
88
+ - 字串值使用單引號
89
+ - 數值不要加引號
90
+ - 日期與時間要用正確的 SQL 字面值
91
+ - 不要把未驗證內容直接串進條件式
92
+
93
+ ## Safety Rules
94
+
95
+ - 不支援 multi-statement
96
+ - 不支援 `SELECT ... INTO`
97
+ - 不支援 locking reads
98
+ - 不支援 `CREATE TABLE ... AS SELECT`
99
+ - 寫入前先確認 schema
100
+ - deny tables 的優先級高於 allow tables
101
+
102
+ ## Examples
103
+
104
+ - 查詢單一使用者:
105
+ - `SELECT id, name FROM users WHERE id = ?`
106
+ - 聚合統計:
107
+ - `SELECT status, COUNT(*) FROM orders GROUP BY status`
108
+ - join 查詢:
109
+ - `SELECT o.id, u.name FROM orders o JOIN users u ON o.user_id = u.id`
110
+ - 更新資料:
111
+ - `UPDATE users SET name = ? WHERE id = ?`
112
+ - 分頁查詢:
113
+ - `SELECT * FROM posts ORDER BY created_at DESC LIMIT 20 OFFSET 0`
114
+
115
+ ## Troubleshooting
116
+
117
+ - 查不到欄位時,先用 `describe_table`
118
+ - SQL 被拒絕時,先檢查是否是多語句或受限語法
119
+ - 結果不如預期時,先確認 `WHERE` 與 `JOIN ON`
120
+ - 效能不好時,先看 `explain_query`
package/README.md CHANGED
@@ -16,7 +16,7 @@ This project uses Node.js, TypeScript, the official MCP SDK, and `mysql2/promise
16
16
 
17
17
  ## Requirements
18
18
 
19
- - Node.js 18 or newer
19
+ - Node.js 20 or newer
20
20
  - npm
21
21
  - A reachable MySQL-compatible database
22
22
 
@@ -91,6 +91,8 @@ npm start
91
91
 
92
92
  The server communicates over stdio and is normally launched by an MCP client rather than run manually.
93
93
 
94
+ If you are unsure how a tool should be used, or an operation fails, call `mysql_manual` first. It returns the built-in manual with safe usage rules, parameter binding guidance, and SQL composition notes.
95
+
94
96
  ## Claude Desktop Example
95
97
 
96
98
  ```json
@@ -155,6 +157,7 @@ MYSQL_DATABASE = "YOUR DB NAME"
155
157
 
156
158
  | Tool | Description |
157
159
  | --- | --- |
160
+ | `mysql_manual` | Return the built-in manual. Use this first when you are unsure how to use MySQL tools or need help diagnosing an operation error |
158
161
  | `mysql_query` | Execute a SQL query intended for data retrieval, such as `SELECT` |
159
162
  | `mysql_execute` | Execute a data modification statement, such as `INSERT`, `UPDATE`, or `DELETE` |
160
163
  | `mysql_schema_execute` | Execute schema modification statements in advanced mode, such as `CREATE TABLE`, `ALTER TABLE`, `CREATE VIEW`, `CREATE TRIGGER`, and `CREATE INDEX` |
package/README.zh-TW.md CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  ## 需求
18
18
 
19
- - Node.js 18 或更新版本
19
+ - Node.js 20 或更新版本
20
20
  - npm
21
21
  - 可連線的 MySQL-compatible database
22
22
 
@@ -153,8 +153,11 @@ MYSQL_DATABASE = "YOUR DB NAME"
153
153
 
154
154
  ## 可用工具
155
155
 
156
+ 如果你不確定某個工具該怎麼用,或操作失敗,請先呼叫 `mysql_manual`。它會回傳內建手冊,包含安全使用規則、參數綁定指引,以及 SQL 組合方式。
157
+
156
158
  | 工具 | 說明 |
157
159
  | --- | --- |
160
+ | `mysql_manual` | 回傳內建手冊。當你不確定如何使用 MySQL 工具,或需要排查操作錯誤時,請先查這個工具 |
158
161
  | `mysql_query` | 執行用於資料讀取的 SQL query,例如 `SELECT` |
159
162
  | `mysql_execute` | 執行資料修改 statement,例如 `INSERT`、`UPDATE`、`DELETE` |
160
163
  | `mysql_schema_execute` | 在 advanced mode 執行 schema 修改 statement,例如 `CREATE TABLE`、`ALTER TABLE`、`CREATE VIEW`、`CREATE TRIGGER`、`CREATE INDEX` |
package/build/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
2
4
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
5
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
6
  import { z } from 'zod';
@@ -13,8 +15,15 @@ const server = new McpServer({
13
15
  version: '1.1.2',
14
16
  description: `MySQL Database: ${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}`,
15
17
  });
18
+ const manualText = readFileSync(fileURLToPath(new URL('../MANUAL.md', import.meta.url)), 'utf8');
16
19
  // --- Register Tools ---
17
20
  const transactionModeSchema = z.enum(['all', 'batch', 'each', 'none']);
21
+ server.registerTool('mysql_manual', {
22
+ description: 'Return the MySQL MCP manual. Use this first when you are unsure how to use mysql_query, mysql_execute, mysql_batch_execute, or when an operation fails and you need the safe usage rules, parameter rules, or SQL composition guidance.',
23
+ inputSchema: z.object({}),
24
+ }, async () => ({
25
+ content: [{ type: 'text', text: manualText }],
26
+ }));
18
27
  server.registerTool('mysql_query', {
19
28
  description: 'Execute a read-only SQL query (e.g., SELECT). Use this for data retrieval.',
20
29
  inputSchema: z.object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-mysql-mcp",
3
- "version": "1.1.2",
3
+ "version": "1.2.2",
4
4
  "description": "High performance MySQL MCP Server using mysql2",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -9,10 +9,12 @@
9
9
  },
10
10
  "files": [
11
11
  "build",
12
- "README.md"
12
+ "README.md",
13
+ "README.zh-TW.md",
14
+ "MANUAL.md"
13
15
  ],
14
16
  "engines": {
15
- "node": ">=18"
17
+ "node": ">=20"
16
18
  },
17
19
  "keywords": [
18
20
  "mcp",
@@ -34,13 +36,13 @@
34
36
  },
35
37
  "dependencies": {
36
38
  "@modelcontextprotocol/sdk": "^1.29.0",
37
- "mysql2": "^3.22.4",
39
+ "mysql2": "^3.23.0",
38
40
  "node-sql-parser": "^5.4.0",
39
41
  "zod": "^4.4.3"
40
42
  },
41
43
  "devDependencies": {
42
- "@types/node": "^25.6.0",
43
- "typescript": "^6.0.3"
44
+ "@types/node": "^26.1.1",
45
+ "typescript": "^7.0.2"
44
46
  },
45
47
  "repository": {
46
48
  "type": "git",