@berthojoris/mcp-mysql-server 1.43.2 → 1.44.0
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/CHANGELOG.md +57 -6
- package/DOCUMENTATIONS.md +40 -38
- package/README.md +26 -7
- package/bin/mcp-mysql.js +168 -168
- package/dist/cache/queryCache.js +1 -1
- package/dist/config/config.js +2 -1
- package/dist/config/featureConfig.d.ts +5 -0
- package/dist/config/featureConfig.js +26 -12
- package/dist/db/connection.d.ts +8 -1
- package/dist/db/connection.js +19 -14
- package/dist/index.js +0 -10
- package/dist/mcp-server.js +45 -305
- package/dist/security/securityLayer.d.ts +33 -5
- package/dist/security/securityLayer.js +211 -58
- package/dist/tools/aiTools.js +1 -1
- package/dist/tools/dataExportTools.js +8 -0
- package/dist/tools/queryTools.d.ts +1 -1
- package/dist/tools/queryTools.js +6 -7
- package/dist/tools/toolArgumentValidation.js +22 -22
- package/dist/tools/toolRegistry.d.ts +1 -1
- package/dist/tools/toolRegistry.js +7 -1
- package/dist/tools/transactionTools.js +1 -1
- package/manifest.json +5 -5
- package/package.json +86 -78
- package/dist/auth/authService.d.ts +0 -29
- package/dist/auth/authService.js +0 -114
- package/dist/tools/backupRestoreTools.d.ts +0 -18
- package/dist/tools/backupRestoreTools.js +0 -70
- package/dist/tools/documentationGeneratorTools.d.ts +0 -145
- package/dist/tools/documentationGeneratorTools.js +0 -820
- package/dist/tools/forecastingTools.d.ts +0 -36
- package/dist/tools/forecastingTools.js +0 -256
- package/dist/tools/functionTools.d.ts +0 -87
- package/dist/tools/functionTools.js +0 -358
- package/dist/tools/indexRecommendationTools.d.ts +0 -50
- package/dist/tools/indexRecommendationTools.js +0 -451
- package/dist/tools/intelligentQueryTools.d.ts +0 -94
- package/dist/tools/intelligentQueryTools.js +0 -713
- package/dist/tools/performanceTools.d.ts +0 -76
- package/dist/tools/performanceTools.js +0 -505
- package/dist/tools/processTools.d.ts +0 -61
- package/dist/tools/processTools.js +0 -181
- package/dist/tools/queryVisualizationTools.d.ts +0 -22
- package/dist/tools/queryVisualizationTools.js +0 -155
- package/dist/tools/schemaDesignTools.d.ts +0 -67
- package/dist/tools/schemaDesignTools.js +0 -359
- package/dist/tools/schemaPatternTools.d.ts +0 -19
- package/dist/tools/schemaPatternTools.js +0 -253
- package/dist/tools/schemaVersioningTools.d.ts +0 -138
- package/dist/tools/schemaVersioningTools.js +0 -1008
- package/dist/tools/securityAuditTools.d.ts +0 -39
- package/dist/tools/securityAuditTools.js +0 -319
- package/dist/tools/smartDiscoveryTools.d.ts +0 -163
- package/dist/tools/smartDiscoveryTools.js +0 -750
- package/dist/tools/testDataTools.d.ts +0 -26
- package/dist/tools/testDataTools.js +0 -325
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.featureConfig = exports.FeatureConfig = exports.toolDocCategoryMap = exports.toolCategoryMap = exports.DocCategory = exports.ToolCategory = void 0;
|
|
6
|
+
exports.featureConfig = exports.FeatureConfig = exports.DEFAULT_PERMISSIONS = exports.toolDocCategoryMap = exports.toolCategoryMap = exports.DocCategory = exports.ToolCategory = void 0;
|
|
7
7
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
8
|
// Load environment variables
|
|
9
9
|
dotenv_1.default.config();
|
|
@@ -178,6 +178,14 @@ exports.toolCategoryMap = {
|
|
|
178
178
|
getFulltextStats: ToolCategory.LIST,
|
|
179
179
|
optimizeFulltext: ToolCategory.UTILITY,
|
|
180
180
|
};
|
|
181
|
+
const toolAdditionalPermissions = {
|
|
182
|
+
exportTableToCSV: [ToolCategory.READ],
|
|
183
|
+
exportTableToCsv: [ToolCategory.READ],
|
|
184
|
+
export_table_to_csv: [ToolCategory.READ],
|
|
185
|
+
exportQueryToCSV: [ToolCategory.READ],
|
|
186
|
+
exportQueryToCsv: [ToolCategory.READ],
|
|
187
|
+
export_query_to_csv: [ToolCategory.READ],
|
|
188
|
+
};
|
|
181
189
|
/**
|
|
182
190
|
* Map of tool names to their documentation categories (New Enhanced System)
|
|
183
191
|
*/
|
|
@@ -357,6 +365,11 @@ const legacyToDocCategoryMap = {
|
|
|
357
365
|
transaction: [DocCategory.TRANSACTION_MANAGEMENT, DocCategory.SEED_OPERATIONS],
|
|
358
366
|
procedure: [DocCategory.STORED_PROCEDURES],
|
|
359
367
|
};
|
|
368
|
+
/**
|
|
369
|
+
* Permissions used when neither permissions nor categories are configured.
|
|
370
|
+
* Read-only by default; write and schema access must be granted explicitly.
|
|
371
|
+
*/
|
|
372
|
+
exports.DEFAULT_PERMISSIONS = "list,read,utility";
|
|
360
373
|
/**
|
|
361
374
|
* Class to manage feature configuration based on runtime or environment variables
|
|
362
375
|
* Supports dual-layer filtering:
|
|
@@ -395,12 +408,9 @@ class FeatureConfig {
|
|
|
395
408
|
* Layer 2 (categories): Fine-grained control using documentation categories (optional)
|
|
396
409
|
*/
|
|
397
410
|
parseConfig(permissionsStr, categoriesStr) {
|
|
398
|
-
// If both are empty,
|
|
411
|
+
// If both are empty, fall back to the read-only default permissions
|
|
399
412
|
if (!permissionsStr.trim() && !categoriesStr.trim()) {
|
|
400
|
-
|
|
401
|
-
legacy: new Set(Object.values(ToolCategory)),
|
|
402
|
-
doc: new Set(Object.values(DocCategory)),
|
|
403
|
-
};
|
|
413
|
+
permissionsStr = exports.DEFAULT_PERMISSIONS;
|
|
404
414
|
}
|
|
405
415
|
// Parse Layer 1: Permissions (legacy categories)
|
|
406
416
|
let legacySet = new Set();
|
|
@@ -469,6 +479,9 @@ class FeatureConfig {
|
|
|
469
479
|
if (!hasPermission) {
|
|
470
480
|
return false;
|
|
471
481
|
}
|
|
482
|
+
if (!(toolAdditionalPermissions[toolName] || []).every((permission) => this.enabledLegacyCategories.has(permission))) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
472
485
|
// Layer 2: Check category (documentation category) if dual-layer mode
|
|
473
486
|
if (this.useDualLayer) {
|
|
474
487
|
const hasCategory = docCategory
|
|
@@ -488,10 +501,10 @@ class FeatureConfig {
|
|
|
488
501
|
if (!docCategory && !legacyCategory) {
|
|
489
502
|
return `Unknown tool '${toolName}'. This tool is not recognized by the MCP server.`;
|
|
490
503
|
}
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
504
|
+
const missingPermission = (toolAdditionalPermissions[toolName] || []).find((permission) => !this.enabledLegacyCategories.has(permission));
|
|
505
|
+
if (legacyCategory && this.enabledLegacyCategories.has(legacyCategory) && missingPermission) {
|
|
506
|
+
return (`Permission denied: This tool also requires '${missingPermission}' permission (Layer 1). ` +
|
|
507
|
+
`Add '${missingPermission}' to the permissions argument.`);
|
|
495
508
|
}
|
|
496
509
|
// Build error message based on dual-layer or single-layer mode
|
|
497
510
|
if (this.useDualLayer) {
|
|
@@ -575,7 +588,8 @@ class FeatureConfig {
|
|
|
575
588
|
*/
|
|
576
589
|
getConfigSnapshot() {
|
|
577
590
|
return {
|
|
578
|
-
permissions: this.originalPermissionsString ||
|
|
591
|
+
permissions: this.originalPermissionsString ||
|
|
592
|
+
(this.originalCategoriesString ? "all" : exports.DEFAULT_PERMISSIONS),
|
|
579
593
|
categories: this.originalCategoriesString ||
|
|
580
594
|
(this.useDualLayer ? "" : "derived from permissions"),
|
|
581
595
|
filteringMode: this.getFilteringMode(),
|
|
@@ -589,7 +603,7 @@ class FeatureConfig {
|
|
|
589
603
|
getFilteringMode() {
|
|
590
604
|
if (!this.originalPermissionsString.trim() &&
|
|
591
605
|
!this.originalCategoriesString.trim()) {
|
|
592
|
-
return
|
|
606
|
+
return `Default read-only (${exports.DEFAULT_PERMISSIONS})`;
|
|
593
607
|
}
|
|
594
608
|
if (this.useDualLayer) {
|
|
595
609
|
return "Dual-layer (Permissions + Categories)";
|
package/dist/db/connection.d.ts
CHANGED
|
@@ -13,7 +13,14 @@ declare class DatabaseConnection {
|
|
|
13
13
|
getConnection(): Promise<mysql.PoolConnection>;
|
|
14
14
|
query<T>(sql: string, params?: any[], useCache?: boolean): Promise<T>;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Whether a statement cannot change data seen by cached SELECTs.
|
|
17
|
+
* EXPLAIN/DESCRIBE ANALYZE executes the wrapped statement, so it is excluded.
|
|
18
|
+
*/
|
|
19
|
+
static isReadOnlyStatement(sql: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Clear the whole cache when a statement may have changed data. Writes can
|
|
22
|
+
* touch tables that are hard to extract reliably (multi-table UPDATE/DELETE,
|
|
23
|
+
* db-qualified names, DDL, procedures), so no table-level guessing is done.
|
|
17
24
|
*/
|
|
18
25
|
private invalidateCacheForWriteOperation;
|
|
19
26
|
testConnection(): Promise<{
|
package/dist/db/connection.js
CHANGED
|
@@ -17,7 +17,8 @@ class DatabaseConnection {
|
|
|
17
17
|
port: config_1.dbConfig.port,
|
|
18
18
|
user: config_1.dbConfig.user,
|
|
19
19
|
password: config_1.dbConfig.password,
|
|
20
|
-
|
|
20
|
+
// No default schema unless one was configured
|
|
21
|
+
database: config_1.dbConfig.database || undefined,
|
|
21
22
|
waitForConnections: true,
|
|
22
23
|
connectionLimit: 10,
|
|
23
24
|
queueLimit: 0,
|
|
@@ -67,9 +68,7 @@ class DatabaseConnection {
|
|
|
67
68
|
this.queryCache.set(sql, params, results);
|
|
68
69
|
}
|
|
69
70
|
// Invalidate cache for write operations
|
|
70
|
-
|
|
71
|
-
this.invalidateCacheForWriteOperation(sql);
|
|
72
|
-
}
|
|
71
|
+
this.invalidateCacheForWriteOperation(sql);
|
|
73
72
|
return results;
|
|
74
73
|
}
|
|
75
74
|
catch (error) {
|
|
@@ -79,18 +78,20 @@ class DatabaseConnection {
|
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
/**
|
|
82
|
-
*
|
|
81
|
+
* Whether a statement cannot change data seen by cached SELECTs.
|
|
82
|
+
* EXPLAIN/DESCRIBE ANALYZE executes the wrapped statement, so it is excluded.
|
|
83
|
+
*/
|
|
84
|
+
static isReadOnlyStatement(sql) {
|
|
85
|
+
return /^(?:SELECT|SHOW)\b|^(?:EXPLAIN|DESCRIBE|DESC)\b(?!\s+ANALYZE\b)/i.test(sql.trim());
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Clear the whole cache when a statement may have changed data. Writes can
|
|
89
|
+
* touch tables that are hard to extract reliably (multi-table UPDATE/DELETE,
|
|
90
|
+
* db-qualified names, DDL, procedures), so no table-level guessing is done.
|
|
83
91
|
*/
|
|
84
92
|
invalidateCacheForWriteOperation(sql) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const updateMatch = sql.match(/UPDATE\s+[\`"']?(\w+)[\`"']?/i);
|
|
88
|
-
const deleteMatch = sql.match(/DELETE\s+FROM\s+[\`"']?(\w+)[\`"']?/i);
|
|
89
|
-
const truncateMatch = sql.match(/TRUNCATE\s+(?:TABLE\s+)?[\`"']?(\w+)[\`"']?/i);
|
|
90
|
-
const dropMatch = sql.match(/DROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?[\`"']?(\w+)[\`"']?/i);
|
|
91
|
-
const match = insertMatch || updateMatch || deleteMatch || truncateMatch || dropMatch;
|
|
92
|
-
if (match && match[1]) {
|
|
93
|
-
this.queryCache.invalidateTable(match[1]);
|
|
93
|
+
if (!DatabaseConnection.isReadOnlyStatement(sql)) {
|
|
94
|
+
this.queryCache.clear();
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
async testConnection() {
|
|
@@ -286,6 +287,8 @@ class DatabaseConnection {
|
|
|
286
287
|
await transaction.connection.commit();
|
|
287
288
|
transaction.connection.release();
|
|
288
289
|
this.activeTransactions.delete(transactionId);
|
|
290
|
+
// Reads cached while the transaction was open predate its committed writes
|
|
291
|
+
this.queryCache.clear();
|
|
289
292
|
}
|
|
290
293
|
catch (error) {
|
|
291
294
|
// If commit fails, rollback and release connection
|
|
@@ -395,6 +398,8 @@ class DatabaseConnection {
|
|
|
395
398
|
const [results] = await transaction.connection.query(sql, params);
|
|
396
399
|
const duration = Date.now() - startTime;
|
|
397
400
|
queryLogger_1.QueryLogger.log(sql, params, duration, "success");
|
|
401
|
+
// DDL commits implicitly, so its effects are visible before COMMIT
|
|
402
|
+
this.invalidateCacheForWriteOperation(sql);
|
|
398
403
|
// Reset timeout on successful activity and update last activity
|
|
399
404
|
this.resetTransactionTimeout(transactionId);
|
|
400
405
|
transaction.lastActivity = now;
|
package/dist/index.js
CHANGED
|
@@ -149,16 +149,6 @@ class MySQLMCP {
|
|
|
149
149
|
if (!check.enabled) {
|
|
150
150
|
return { status: "error", error: check.error };
|
|
151
151
|
}
|
|
152
|
-
// Additional security check - block DDL unless DDL permission is enabled
|
|
153
|
-
if (this.security.hasDangerousOperations(params.query)) {
|
|
154
|
-
// Check if DDL permission is enabled
|
|
155
|
-
if (!this.featureConfig.isCategoryEnabled("ddl")) {
|
|
156
|
-
return {
|
|
157
|
-
status: "error",
|
|
158
|
-
error: 'DDL operations (DROP, TRUNCATE, ALTER, CREATE) require the "ddl" permission. Use execute_ddl tool or add "ddl" to permissions.',
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
152
|
return await this.queryTools.executeWriteQuery(params);
|
|
163
153
|
}
|
|
164
154
|
// Analysis Tools
|
package/dist/mcp-server.js
CHANGED
|
@@ -9,16 +9,17 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
10
10
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
11
11
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
12
|
+
const index_1 = require("./index");
|
|
13
|
+
const toolRegistry_1 = require("./tools/toolRegistry");
|
|
14
|
+
const toolArgumentValidation_1 = require("./tools/toolArgumentValidation");
|
|
15
15
|
// Get permissions and categories from environment variables (set by bin/mcp-mysql.js)
|
|
16
16
|
// Layer 1 (Permissions): MCP_PERMISSIONS or MCP_CONFIG (backward compatible)
|
|
17
17
|
// Layer 2 (Categories): MCP_CATEGORIES (optional, for fine-grained control)
|
|
18
18
|
const permissions = process.env.MCP_PERMISSIONS || process.env.MCP_CONFIG || "";
|
|
19
19
|
const categories = process.env.MCP_CATEGORIES || "";
|
|
20
20
|
const SERVER_NAME = "mysql-mcp-server";
|
|
21
|
-
|
|
21
|
+
// Read from package.json (one level above both src/ and dist/)
|
|
22
|
+
const SERVER_VERSION = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, "..", "package.json"), "utf8")).version;
|
|
22
23
|
// Declare the MySQL MCP instance (will be initialized in main())
|
|
23
24
|
let mysqlMCP;
|
|
24
25
|
// Define all available tools with their schemas
|
|
@@ -869,7 +870,7 @@ const TOOLS = [
|
|
|
869
870
|
},
|
|
870
871
|
useCache: {
|
|
871
872
|
type: "boolean",
|
|
872
|
-
description: "Whether to use query result caching (default: true)",
|
|
873
|
+
description: "Whether to use query result caching when the cache is enabled with CACHE_ENABLED=true (default: true)",
|
|
873
874
|
},
|
|
874
875
|
dry_run: {
|
|
875
876
|
type: "boolean",
|
|
@@ -1056,7 +1057,7 @@ const TOOLS = [
|
|
|
1056
1057
|
},
|
|
1057
1058
|
{
|
|
1058
1059
|
name: "cursor_execute_request",
|
|
1059
|
-
description: "Cursor compatibility bridge for clients that can call MCP tools but cannot send arguments. Reads .cursor/mysql-mcp-request.json (or MYSQL_MCP_CURSOR_REQUEST_FILE) and dispatches to the requested MySQL MCP tool. The request file supports {\"tool\":\"execute_ddl\",\"arguments\":{\"query\":\"DROP TABLE IF EXISTS t;\"}} or direct SQL with {\"query\":\"...\",\"mode\":\"auto\"}.",
|
|
1060
|
+
description: "Cursor compatibility bridge for clients that can call MCP tools but cannot send arguments. Requires utility permission and an enabled destination tool. Reads .cursor/mysql-mcp-request.json (or MYSQL_MCP_CURSOR_REQUEST_FILE) and dispatches to the requested MySQL MCP tool. The request file supports {\"tool\":\"execute_ddl\",\"arguments\":{\"query\":\"DROP TABLE IF EXISTS t;\"}} or direct SQL with {\"query\":\"...\",\"mode\":\"auto\"}.",
|
|
1060
1061
|
inputSchema: {
|
|
1061
1062
|
type: "object",
|
|
1062
1063
|
properties: {},
|
|
@@ -1160,7 +1161,7 @@ const TOOLS = [
|
|
|
1160
1161
|
},
|
|
1161
1162
|
{
|
|
1162
1163
|
name: "execute_in_transaction",
|
|
1163
|
-
description: "Executes a SQL query within an existing transaction context.
|
|
1164
|
+
description: "Executes a SQL query within an existing transaction context. Requires transaction plus the SQL operation permission: read for SELECT, create or execute for INSERT, update or execute for UPDATE, delete for DELETE. DDL requires an enabled execute_ddl tool and may implicitly commit. EXPLAIN ANALYZE requires the permission of the statement it executes. Use after begin_transaction.",
|
|
1164
1165
|
inputSchema: {
|
|
1165
1166
|
type: "object",
|
|
1166
1167
|
properties: {
|
|
@@ -1325,7 +1326,7 @@ const TOOLS = [
|
|
|
1325
1326
|
// Data Export Tools
|
|
1326
1327
|
{
|
|
1327
1328
|
name: "export_table_to_csv",
|
|
1328
|
-
description: "📄 Exports table data to CSV format with filtering, pagination, and sorting.
|
|
1329
|
+
description: "📄 Exports table data to CSV format with filtering, pagination, and sorting. Requires both utility and read permissions.",
|
|
1329
1330
|
inputSchema: {
|
|
1330
1331
|
type: "object",
|
|
1331
1332
|
properties: {
|
|
@@ -1381,7 +1382,7 @@ const TOOLS = [
|
|
|
1381
1382
|
},
|
|
1382
1383
|
{
|
|
1383
1384
|
name: "export_query_to_csv",
|
|
1384
|
-
description: "📄 Executes a SELECT query and exports results to CSV format. Supports complex queries with JOINs and aggregations.
|
|
1385
|
+
description: "📄 Executes a SELECT query and exports results to CSV format. Requires both utility and read permissions. Supports complex queries with JOINs and aggregations.",
|
|
1385
1386
|
inputSchema: {
|
|
1386
1387
|
type: "object",
|
|
1387
1388
|
properties: {
|
|
@@ -2279,7 +2280,7 @@ const server = new index_js_1.Server({
|
|
|
2279
2280
|
});
|
|
2280
2281
|
// Handle list tools request - filter tools based on permissions and categories
|
|
2281
2282
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
2282
|
-
const enabledTools = (0,
|
|
2283
|
+
const enabledTools = (0, toolRegistry_1.getEnabledTools)(mysqlMCP, TOOLS);
|
|
2283
2284
|
// Log the filtering results
|
|
2284
2285
|
console.error(`Tools available: ${enabledTools.length} of ${TOOLS.length} total tools`);
|
|
2285
2286
|
return {
|
|
@@ -2293,7 +2294,7 @@ const TOOL_METHOD_OVERRIDES = {
|
|
|
2293
2294
|
};
|
|
2294
2295
|
const toCamelCase = (value) => value.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
2295
2296
|
const getRuntimeToolCatalog = () => {
|
|
2296
|
-
const enabledTools = (0,
|
|
2297
|
+
const enabledTools = (0, toolRegistry_1.getEnabledTools)(mysqlMCP, TOOLS);
|
|
2297
2298
|
return {
|
|
2298
2299
|
tools: TOOLS.map((tool) => ({
|
|
2299
2300
|
name: tool.name,
|
|
@@ -2306,6 +2307,15 @@ const getRuntimeToolCatalog = () => {
|
|
|
2306
2307
|
serverVersion: SERVER_VERSION,
|
|
2307
2308
|
};
|
|
2308
2309
|
};
|
|
2310
|
+
const assertToolEnabled = (toolName) => {
|
|
2311
|
+
const tool = TOOLS.find((candidate) => candidate.name === toolName);
|
|
2312
|
+
if (!tool) {
|
|
2313
|
+
throw new Error(`Unknown tool: ${toolName}`);
|
|
2314
|
+
}
|
|
2315
|
+
if (!(0, toolRegistry_1.isToolEnabled)(mysqlMCP, tool)) {
|
|
2316
|
+
throw new Error(`Permission denied: Tool '${toolName}' is disabled by the active permissions or categories.`);
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2309
2319
|
const getCursorRequestFilePath = () => {
|
|
2310
2320
|
const configuredPath = process.env.MYSQL_MCP_CURSOR_REQUEST_FILE ||
|
|
2311
2321
|
process.env.MCP_MYSQL_REQUEST_FILE ||
|
|
@@ -2333,6 +2343,22 @@ const inferSqlToolName = (query, mode = "auto") => {
|
|
|
2333
2343
|
}
|
|
2334
2344
|
throw new Error("Unable to infer SQL tool. Set mode to one of: select, write, ddl.");
|
|
2335
2345
|
};
|
|
2346
|
+
// Dispatch a tool to its MySQLMCP method (snake_case name -> camelCase method).
|
|
2347
|
+
// Callers must validate arguments and check that the tool is enabled first.
|
|
2348
|
+
const invokeTool = async (toolName, args = {}) => {
|
|
2349
|
+
if (toolName === "list_all_tools") {
|
|
2350
|
+
return await mysqlMCP.listAllTools(getRuntimeToolCatalog());
|
|
2351
|
+
}
|
|
2352
|
+
if (toolName === "cursor_execute_request") {
|
|
2353
|
+
return await executeCursorRequest();
|
|
2354
|
+
}
|
|
2355
|
+
const methodName = TOOL_METHOD_OVERRIDES[toolName] || toCamelCase(toolName);
|
|
2356
|
+
const method = mysqlMCP[methodName];
|
|
2357
|
+
if (typeof method !== "function") {
|
|
2358
|
+
throw new Error(`No handler method found for tool: ${toolName}`);
|
|
2359
|
+
}
|
|
2360
|
+
return await method.call(mysqlMCP, args);
|
|
2361
|
+
};
|
|
2336
2362
|
const executeToolByName = async (toolName, args = {}) => {
|
|
2337
2363
|
const knownToolNames = new Set(TOOLS.map((tool) => tool.name));
|
|
2338
2364
|
if (!knownToolNames.has(toolName)) {
|
|
@@ -2341,21 +2367,15 @@ const executeToolByName = async (toolName, args = {}) => {
|
|
|
2341
2367
|
if (toolName === "cursor_execute_request") {
|
|
2342
2368
|
throw new Error("cursor_execute_request cannot dispatch to itself");
|
|
2343
2369
|
}
|
|
2344
|
-
|
|
2370
|
+
assertToolEnabled(toolName);
|
|
2371
|
+
const validation = (0, toolArgumentValidation_1.validateToolArguments)(toolName, args);
|
|
2345
2372
|
if (!validation.valid) {
|
|
2346
2373
|
throw new Error(`Validation Error: ${validation.errors?.join(", ") || "Invalid arguments"}`);
|
|
2347
2374
|
}
|
|
2348
|
-
|
|
2349
|
-
return await mysqlMCP.listAllTools(getRuntimeToolCatalog());
|
|
2350
|
-
}
|
|
2351
|
-
const methodName = TOOL_METHOD_OVERRIDES[toolName] || toCamelCase(toolName);
|
|
2352
|
-
const method = mysqlMCP[methodName];
|
|
2353
|
-
if (typeof method !== "function") {
|
|
2354
|
-
throw new Error(`No handler method found for Cursor bridge tool: ${toolName}`);
|
|
2355
|
-
}
|
|
2356
|
-
return await method.call(mysqlMCP, args);
|
|
2375
|
+
return await invokeTool(toolName, args);
|
|
2357
2376
|
};
|
|
2358
2377
|
const executeCursorRequest = async () => {
|
|
2378
|
+
assertToolEnabled("cursor_execute_request");
|
|
2359
2379
|
const requestFilePath = getCursorRequestFilePath();
|
|
2360
2380
|
if (!fs_1.default.existsSync(requestFilePath)) {
|
|
2361
2381
|
return {
|
|
@@ -2395,7 +2415,7 @@ const executeCursorRequest = async () => {
|
|
|
2395
2415
|
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
2396
2416
|
const { name, arguments: args } = request.params;
|
|
2397
2417
|
// Validate tool arguments before execution
|
|
2398
|
-
const validation = (0,
|
|
2418
|
+
const validation = (0, toolArgumentValidation_1.validateToolArguments)(name, args);
|
|
2399
2419
|
if (!validation.valid) {
|
|
2400
2420
|
return {
|
|
2401
2421
|
content: [
|
|
@@ -2408,288 +2428,8 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
2408
2428
|
};
|
|
2409
2429
|
}
|
|
2410
2430
|
try {
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
case "list_databases":
|
|
2414
|
-
result = await mysqlMCP.listDatabases();
|
|
2415
|
-
break;
|
|
2416
|
-
case "list_tables":
|
|
2417
|
-
result = await mysqlMCP.listTables((args || {}));
|
|
2418
|
-
break;
|
|
2419
|
-
case "get_database_summary":
|
|
2420
|
-
result = await mysqlMCP.getDatabaseSummary((args || {}));
|
|
2421
|
-
break;
|
|
2422
|
-
case "get_schema_erd":
|
|
2423
|
-
result = await mysqlMCP.getSchemaERD((args || {}));
|
|
2424
|
-
break;
|
|
2425
|
-
case "get_schema_rag_context":
|
|
2426
|
-
result = await mysqlMCP.getSchemaRagContext((args || {}));
|
|
2427
|
-
break;
|
|
2428
|
-
case "find_tables_by_keyword":
|
|
2429
|
-
result = await mysqlMCP.findTablesByKeyword((args || {}));
|
|
2430
|
-
break;
|
|
2431
|
-
case "search_schema":
|
|
2432
|
-
result = await mysqlMCP.searchSchema((args || {}));
|
|
2433
|
-
break;
|
|
2434
|
-
case "search_data_across_tables":
|
|
2435
|
-
result = await mysqlMCP.searchDataAcrossTables((args || {}));
|
|
2436
|
-
break;
|
|
2437
|
-
case "get_column_statistics":
|
|
2438
|
-
result = await mysqlMCP.getColumnStatistics((args || {}));
|
|
2439
|
-
break;
|
|
2440
|
-
case "read_table_schema":
|
|
2441
|
-
result = await mysqlMCP.readTableSchema((args || {}));
|
|
2442
|
-
break;
|
|
2443
|
-
// CRUD Tools
|
|
2444
|
-
case "create_record":
|
|
2445
|
-
result = await mysqlMCP.createRecord((args || {}));
|
|
2446
|
-
break;
|
|
2447
|
-
case "read_records":
|
|
2448
|
-
result = await mysqlMCP.readRecords((args || {}));
|
|
2449
|
-
break;
|
|
2450
|
-
case "update_record":
|
|
2451
|
-
result = await mysqlMCP.updateRecord((args || {}));
|
|
2452
|
-
break;
|
|
2453
|
-
case "delete_record":
|
|
2454
|
-
result = await mysqlMCP.deleteRecord((args || {}));
|
|
2455
|
-
break;
|
|
2456
|
-
// Bulk Operations
|
|
2457
|
-
case "bulk_insert":
|
|
2458
|
-
result = await mysqlMCP.bulkInsert((args || {}));
|
|
2459
|
-
break;
|
|
2460
|
-
case "bulk_update":
|
|
2461
|
-
result = await mysqlMCP.bulkUpdate((args || {}));
|
|
2462
|
-
break;
|
|
2463
|
-
case "bulk_delete":
|
|
2464
|
-
result = await mysqlMCP.bulkDelete((args || {}));
|
|
2465
|
-
break;
|
|
2466
|
-
case "plan_seed_data":
|
|
2467
|
-
result = await mysqlMCP.planSeedData(args || {});
|
|
2468
|
-
break;
|
|
2469
|
-
case "generate_seed_preview":
|
|
2470
|
-
result = await mysqlMCP.generateSeedPreview(args || {});
|
|
2471
|
-
break;
|
|
2472
|
-
case "execute_seed_plan":
|
|
2473
|
-
result = await mysqlMCP.executeSeedPlan(args || {});
|
|
2474
|
-
break;
|
|
2475
|
-
case "validate_seed_integrity":
|
|
2476
|
-
result = await mysqlMCP.validateSeedIntegrity(args || {});
|
|
2477
|
-
break;
|
|
2478
|
-
case "infer_seed_rules":
|
|
2479
|
-
result = await mysqlMCP.inferSeedRules(args || {});
|
|
2480
|
-
break;
|
|
2481
|
-
case "seed_from_template":
|
|
2482
|
-
result = await mysqlMCP.seedFromTemplate(args || {});
|
|
2483
|
-
break;
|
|
2484
|
-
// Query Tools
|
|
2485
|
-
case "run_select_query":
|
|
2486
|
-
result = await mysqlMCP.runSelectQuery((args || {}));
|
|
2487
|
-
break;
|
|
2488
|
-
case "execute_write_query":
|
|
2489
|
-
result = await mysqlMCP.executeWriteQuery((args || {}));
|
|
2490
|
-
break;
|
|
2491
|
-
// DDL Tools
|
|
2492
|
-
case "create_table":
|
|
2493
|
-
result = await mysqlMCP.createTable(args || {});
|
|
2494
|
-
break;
|
|
2495
|
-
case "alter_table":
|
|
2496
|
-
result = await mysqlMCP.alterTable(args || {});
|
|
2497
|
-
break;
|
|
2498
|
-
case "drop_table":
|
|
2499
|
-
result = await mysqlMCP.dropTable(args || {});
|
|
2500
|
-
break;
|
|
2501
|
-
case "execute_ddl":
|
|
2502
|
-
result = await mysqlMCP.executeDdl((args || {}));
|
|
2503
|
-
break;
|
|
2504
|
-
case "describe_connection":
|
|
2505
|
-
result = await mysqlMCP.describeConnection();
|
|
2506
|
-
break;
|
|
2507
|
-
case "cursor_execute_request":
|
|
2508
|
-
result = await executeCursorRequest();
|
|
2509
|
-
break;
|
|
2510
|
-
case "test_connection":
|
|
2511
|
-
result = await mysqlMCP.testConnection();
|
|
2512
|
-
break;
|
|
2513
|
-
case "list_all_tools":
|
|
2514
|
-
result = await mysqlMCP.listAllTools(getRuntimeToolCatalog());
|
|
2515
|
-
break;
|
|
2516
|
-
case "read_changelog":
|
|
2517
|
-
result = await mysqlMCP.readChangelog((args || {}));
|
|
2518
|
-
break;
|
|
2519
|
-
case "get_all_tables_relationships":
|
|
2520
|
-
result = await mysqlMCP.getAllTablesRelationships((args || {}));
|
|
2521
|
-
break;
|
|
2522
|
-
// Transaction Tools
|
|
2523
|
-
case "begin_transaction":
|
|
2524
|
-
result = await mysqlMCP.beginTransaction((args || {}));
|
|
2525
|
-
break;
|
|
2526
|
-
case "commit_transaction":
|
|
2527
|
-
result = await mysqlMCP.commitTransaction((args || {}));
|
|
2528
|
-
break;
|
|
2529
|
-
case "rollback_transaction":
|
|
2530
|
-
result = await mysqlMCP.rollbackTransaction((args || {}));
|
|
2531
|
-
break;
|
|
2532
|
-
case "get_transaction_status":
|
|
2533
|
-
result = await mysqlMCP.getTransactionStatus();
|
|
2534
|
-
break;
|
|
2535
|
-
case "execute_in_transaction":
|
|
2536
|
-
result = await mysqlMCP.executeInTransaction((args || {}));
|
|
2537
|
-
break;
|
|
2538
|
-
// Stored Procedure Tools
|
|
2539
|
-
case "list_stored_procedures":
|
|
2540
|
-
result = await mysqlMCP.listStoredProcedures((args || {}));
|
|
2541
|
-
break;
|
|
2542
|
-
case "get_stored_procedure_info":
|
|
2543
|
-
result = await mysqlMCP.getStoredProcedureInfo((args || {}));
|
|
2544
|
-
break;
|
|
2545
|
-
case "execute_stored_procedure":
|
|
2546
|
-
result = await mysqlMCP.executeStoredProcedure((args || {}));
|
|
2547
|
-
break;
|
|
2548
|
-
case "create_stored_procedure":
|
|
2549
|
-
result = await mysqlMCP.createStoredProcedure((args || {}));
|
|
2550
|
-
break;
|
|
2551
|
-
case "drop_stored_procedure":
|
|
2552
|
-
result = await mysqlMCP.dropStoredProcedure((args || {}));
|
|
2553
|
-
break;
|
|
2554
|
-
case "show_create_procedure":
|
|
2555
|
-
result = await mysqlMCP.showCreateProcedure((args || {}));
|
|
2556
|
-
break;
|
|
2557
|
-
// Data Export Tools
|
|
2558
|
-
case "export_table_to_csv":
|
|
2559
|
-
result = await mysqlMCP.exportTableToCSV((args || {}));
|
|
2560
|
-
break;
|
|
2561
|
-
case "export_query_to_csv":
|
|
2562
|
-
result = await mysqlMCP.exportQueryToCSV((args || {}));
|
|
2563
|
-
break;
|
|
2564
|
-
// Query Optimization Tools
|
|
2565
|
-
case "analyze_query":
|
|
2566
|
-
result = mysqlMCP.analyzeQuery((args || {}));
|
|
2567
|
-
break;
|
|
2568
|
-
case "get_optimization_hints":
|
|
2569
|
-
result = mysqlMCP.getOptimizationHints((args || {}));
|
|
2570
|
-
break;
|
|
2571
|
-
// View Tools
|
|
2572
|
-
case "list_views":
|
|
2573
|
-
result = await mysqlMCP.listViews((args || {}));
|
|
2574
|
-
break;
|
|
2575
|
-
case "get_view_info":
|
|
2576
|
-
result = await mysqlMCP.getViewInfo((args || {}));
|
|
2577
|
-
break;
|
|
2578
|
-
case "create_view":
|
|
2579
|
-
result = await mysqlMCP.createView((args || {}));
|
|
2580
|
-
break;
|
|
2581
|
-
case "alter_view":
|
|
2582
|
-
result = await mysqlMCP.alterView((args || {}));
|
|
2583
|
-
break;
|
|
2584
|
-
case "drop_view":
|
|
2585
|
-
result = await mysqlMCP.dropView((args || {}));
|
|
2586
|
-
break;
|
|
2587
|
-
case "show_create_view":
|
|
2588
|
-
result = await mysqlMCP.showCreateView((args || {}));
|
|
2589
|
-
break;
|
|
2590
|
-
// Trigger Tools
|
|
2591
|
-
case "list_triggers":
|
|
2592
|
-
result = await mysqlMCP.listTriggers((args || {}));
|
|
2593
|
-
break;
|
|
2594
|
-
case "get_trigger_info":
|
|
2595
|
-
result = await mysqlMCP.getTriggerInfo((args || {}));
|
|
2596
|
-
break;
|
|
2597
|
-
case "create_trigger":
|
|
2598
|
-
result = await mysqlMCP.createTrigger((args || {}));
|
|
2599
|
-
break;
|
|
2600
|
-
case "drop_trigger":
|
|
2601
|
-
result = await mysqlMCP.dropTrigger((args || {}));
|
|
2602
|
-
break;
|
|
2603
|
-
case "show_create_trigger":
|
|
2604
|
-
result = await mysqlMCP.showCreateTrigger((args || {}));
|
|
2605
|
-
break;
|
|
2606
|
-
// Index Tools
|
|
2607
|
-
case "list_indexes":
|
|
2608
|
-
result = await mysqlMCP.listIndexes((args || {}));
|
|
2609
|
-
break;
|
|
2610
|
-
case "get_index_info":
|
|
2611
|
-
result = await mysqlMCP.getIndexInfo((args || {}));
|
|
2612
|
-
break;
|
|
2613
|
-
case "create_index":
|
|
2614
|
-
result = await mysqlMCP.createIndex((args || {}));
|
|
2615
|
-
break;
|
|
2616
|
-
case "drop_index":
|
|
2617
|
-
result = await mysqlMCP.dropIndex((args || {}));
|
|
2618
|
-
break;
|
|
2619
|
-
case "analyze_index":
|
|
2620
|
-
result = await mysqlMCP.analyzeIndex((args || {}));
|
|
2621
|
-
break;
|
|
2622
|
-
// Constraint Tools
|
|
2623
|
-
case "list_foreign_keys":
|
|
2624
|
-
result = await mysqlMCP.listForeignKeys((args || {}));
|
|
2625
|
-
break;
|
|
2626
|
-
case "list_constraints":
|
|
2627
|
-
result = await mysqlMCP.listConstraints((args || {}));
|
|
2628
|
-
break;
|
|
2629
|
-
case "add_foreign_key":
|
|
2630
|
-
result = await mysqlMCP.addForeignKey((args || {}));
|
|
2631
|
-
break;
|
|
2632
|
-
case "drop_foreign_key":
|
|
2633
|
-
result = await mysqlMCP.dropForeignKey((args || {}));
|
|
2634
|
-
break;
|
|
2635
|
-
case "add_unique_constraint":
|
|
2636
|
-
result = await mysqlMCP.addUniqueConstraint((args || {}));
|
|
2637
|
-
break;
|
|
2638
|
-
case "drop_constraint":
|
|
2639
|
-
result = await mysqlMCP.dropConstraint((args || {}));
|
|
2640
|
-
break;
|
|
2641
|
-
case "add_check_constraint":
|
|
2642
|
-
result = await mysqlMCP.addCheckConstraint((args || {}));
|
|
2643
|
-
break;
|
|
2644
|
-
// Table Maintenance Tools
|
|
2645
|
-
case "analyze_table":
|
|
2646
|
-
result = await mysqlMCP.analyzeTable((args || {}));
|
|
2647
|
-
break;
|
|
2648
|
-
case "optimize_table":
|
|
2649
|
-
result = await mysqlMCP.optimizeTable((args || {}));
|
|
2650
|
-
break;
|
|
2651
|
-
case "check_table":
|
|
2652
|
-
result = await mysqlMCP.checkTable((args || {}));
|
|
2653
|
-
break;
|
|
2654
|
-
case "repair_table":
|
|
2655
|
-
result = await mysqlMCP.repairTable((args || {}));
|
|
2656
|
-
break;
|
|
2657
|
-
case "truncate_table":
|
|
2658
|
-
result = await mysqlMCP.truncateTable((args || {}));
|
|
2659
|
-
break;
|
|
2660
|
-
case "get_table_status":
|
|
2661
|
-
result = await mysqlMCP.getTableStatus((args || {}));
|
|
2662
|
-
break;
|
|
2663
|
-
case "flush_table":
|
|
2664
|
-
result = await mysqlMCP.flushTable((args || {}));
|
|
2665
|
-
break;
|
|
2666
|
-
case "get_table_size":
|
|
2667
|
-
result = await mysqlMCP.getTableSize((args || {}));
|
|
2668
|
-
break;
|
|
2669
|
-
case "repair_query":
|
|
2670
|
-
result = await mysqlMCP.repairQuery((args || {}));
|
|
2671
|
-
break;
|
|
2672
|
-
case "create_fulltext_index":
|
|
2673
|
-
result = await mysqlMCP.createFulltextIndex((args || {}));
|
|
2674
|
-
break;
|
|
2675
|
-
case "fulltext_search":
|
|
2676
|
-
result = await mysqlMCP.fulltextSearch((args || {}));
|
|
2677
|
-
break;
|
|
2678
|
-
case "get_fulltext_info":
|
|
2679
|
-
result = await mysqlMCP.getFulltextInfo((args || {}));
|
|
2680
|
-
break;
|
|
2681
|
-
case "drop_fulltext_index":
|
|
2682
|
-
result = await mysqlMCP.dropFulltextIndex((args || {}));
|
|
2683
|
-
break;
|
|
2684
|
-
case "get_fulltext_stats":
|
|
2685
|
-
result = await mysqlMCP.getFulltextStats((args || {}));
|
|
2686
|
-
break;
|
|
2687
|
-
case "optimize_fulltext":
|
|
2688
|
-
result = await mysqlMCP.optimizeFulltext((args || {}));
|
|
2689
|
-
break;
|
|
2690
|
-
default:
|
|
2691
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
2692
|
-
}
|
|
2431
|
+
assertToolEnabled(name);
|
|
2432
|
+
const result = await invokeTool(name, args || {});
|
|
2693
2433
|
// Handle the result based on status
|
|
2694
2434
|
if (result.status === "error") {
|
|
2695
2435
|
let errorText = `Error: ${"error" in result ? result.error : "Unknown error"}`;
|
|
@@ -2770,7 +2510,7 @@ async function main() {
|
|
|
2770
2510
|
await server.connect(transport);
|
|
2771
2511
|
// Initialize the MySQL MCP instance AFTER transport is connected
|
|
2772
2512
|
// This ensures the database connection pool is created when the server is ready
|
|
2773
|
-
mysqlMCP = new
|
|
2513
|
+
mysqlMCP = new index_1.MySQLMCP(permissions, categories);
|
|
2774
2514
|
// Log the effective filtering configuration to stderr
|
|
2775
2515
|
const accessProfile = mysqlMCP.getAccessProfile();
|
|
2776
2516
|
console.error(`Permissions (resolved): ${accessProfile.permissions}`);
|