@xingyuchen/mysql-mcp-server 4.0.6 → 4.0.7
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/dist/index.js +2 -2
- package/dist/tools/connection.js +1 -1
- package/dist/tools/query.js +38 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -72,7 +72,7 @@ async function initializeDatabaseConnections(dbManager, configs) {
|
|
|
72
72
|
function createMCPServer(dbManager) {
|
|
73
73
|
const server = new Server({
|
|
74
74
|
name: "mysql-mcp-server",
|
|
75
|
-
version: "4.0.
|
|
75
|
+
version: "4.0.7"
|
|
76
76
|
}, {
|
|
77
77
|
capabilities: {
|
|
78
78
|
tools: {}
|
|
@@ -136,7 +136,7 @@ app.get("/health", (_req, res) => {
|
|
|
136
136
|
status: "healthy",
|
|
137
137
|
transport: "streamable-http",
|
|
138
138
|
activeSessions: sessions.size,
|
|
139
|
-
version: "4.0.
|
|
139
|
+
version: "4.0.7"
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
142
|
// ==================== MCP Endpoint ====================
|
package/dist/tools/connection.js
CHANGED
package/dist/tools/query.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export const queryTools = [
|
|
5
5
|
{
|
|
6
6
|
name: "execute_query",
|
|
7
|
-
description: "执行SQL查询(支持SELECT、INSERT、UPDATE、DELETE等所有SQL
|
|
7
|
+
description: "执行SQL查询(支持SELECT、INSERT、UPDATE、DELETE等所有SQL语句)。注意:通常不需要指定connection_id,系统会自动使用当前活跃连接。",
|
|
8
8
|
inputSchema: {
|
|
9
9
|
type: "object",
|
|
10
10
|
properties: {
|
|
@@ -14,7 +14,7 @@ export const queryTools = [
|
|
|
14
14
|
},
|
|
15
15
|
connection_id: {
|
|
16
16
|
type: "string",
|
|
17
|
-
description: "
|
|
17
|
+
description: "【通常不需要填写】指定连接ID。留空则自动使用当前活跃连接。如需查看可用连接ID,请先调用 list_connections 工具。"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
required: ["query"]
|
|
@@ -22,13 +22,13 @@ export const queryTools = [
|
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
name: "show_tables",
|
|
25
|
-
description: "
|
|
25
|
+
description: "显示数据库中的所有表。自动使用当前活跃的数据库连接。",
|
|
26
26
|
inputSchema: {
|
|
27
27
|
type: "object",
|
|
28
28
|
properties: {
|
|
29
29
|
connection_id: {
|
|
30
30
|
type: "string",
|
|
31
|
-
description: "
|
|
31
|
+
description: "【通常不需要填写】指定连接ID,留空自动使用活跃连接"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
required: []
|
|
@@ -36,7 +36,7 @@ export const queryTools = [
|
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
name: "describe_table",
|
|
39
|
-
description: "
|
|
39
|
+
description: "查看表的结构和字段信息。自动使用当前活跃的数据库连接。",
|
|
40
40
|
inputSchema: {
|
|
41
41
|
type: "object",
|
|
42
42
|
properties: {
|
|
@@ -46,7 +46,7 @@ export const queryTools = [
|
|
|
46
46
|
},
|
|
47
47
|
connection_id: {
|
|
48
48
|
type: "string",
|
|
49
|
-
description: "
|
|
49
|
+
description: "【通常不需要填写】指定连接ID,留空自动使用活跃连接"
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
required: ["table_name"]
|
|
@@ -54,24 +54,53 @@ export const queryTools = [
|
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
name: "show_databases",
|
|
57
|
-
description: "
|
|
57
|
+
description: "显示所有可访问的数据库。自动使用当前活跃的数据库连接。",
|
|
58
58
|
inputSchema: {
|
|
59
59
|
type: "object",
|
|
60
60
|
properties: {
|
|
61
61
|
connection_id: {
|
|
62
62
|
type: "string",
|
|
63
|
-
description: "
|
|
63
|
+
description: "【通常不需要填写】指定连接ID,留空自动使用活跃连接"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
required: []
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
];
|
|
70
|
+
/**
|
|
71
|
+
* 验证并规范化 connection_id 参数
|
|
72
|
+
* 如果传入无效值(空字符串、"默认"、"default" 等),返回 undefined 使用活跃连接
|
|
73
|
+
*/
|
|
74
|
+
function normalizeConnectionId(connectionId, dbManager) {
|
|
75
|
+
// 如果未提供或为空,使用活跃连接
|
|
76
|
+
if (!connectionId || connectionId.trim() === '') {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
const trimmed = connectionId.trim();
|
|
80
|
+
// 常见的无效值列表(AI 可能会传这些)
|
|
81
|
+
const invalidValues = [
|
|
82
|
+
'默认', 'default', 'active', 'current', 'auto',
|
|
83
|
+
'当前', '活跃', 'none', 'null', 'undefined'
|
|
84
|
+
];
|
|
85
|
+
if (invalidValues.includes(trimmed.toLowerCase())) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
// 检查连接是否真实存在
|
|
89
|
+
const connections = dbManager.listConnections();
|
|
90
|
+
const exists = connections.some(conn => conn.id === trimmed);
|
|
91
|
+
if (!exists) {
|
|
92
|
+
// 连接不存在,回退到活跃连接
|
|
93
|
+
console.log(`⚠️ connection_id "${trimmed}" 不存在,使用活跃连接`);
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
return trimmed;
|
|
97
|
+
}
|
|
70
98
|
/**
|
|
71
99
|
* 查询工具处理器
|
|
72
100
|
*/
|
|
73
101
|
export async function handleQueryTool(name, args, dbManager) {
|
|
74
|
-
|
|
102
|
+
// 规范化 connection_id,无效值自动回退到活跃连接
|
|
103
|
+
const connection_id = normalizeConnectionId(args.connection_id, dbManager);
|
|
75
104
|
switch (name) {
|
|
76
105
|
case "execute_query": {
|
|
77
106
|
const { query } = args;
|