@berthojoris/mcp-mysql-server 1.43.5 → 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 +22 -0
- package/DOCUMENTATIONS.md +19 -3
- package/README.md +7 -1
- 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 +11 -13
- package/dist/db/connection.d.ts +8 -1
- package/dist/db/connection.js +19 -14
- package/dist/mcp-server.js +30 -302
- package/dist/security/securityLayer.d.ts +21 -2
- package/dist/security/securityLayer.js +151 -21
- package/dist/tools/toolArgumentValidation.js +22 -22
- package/dist/tools/toolRegistry.d.ts +1 -1
- package/dist/tools/toolRegistry.js +7 -1
- package/manifest.json +1 -1
- 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
|
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SecurityLayer = void 0;
|
|
7
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const featureConfig_1 = require("../config/featureConfig");
|
|
9
|
+
const maskingLayer_1 = require("./maskingLayer");
|
|
10
10
|
class SecurityLayer {
|
|
11
11
|
constructor(featureConfig) {
|
|
12
12
|
this.ajv = new ajv_1.default();
|
|
13
|
-
this.featureConfig = featureConfig || new
|
|
13
|
+
this.featureConfig = featureConfig || new featureConfig_1.FeatureConfig();
|
|
14
14
|
// Masking is intentionally not configurable via environment variables.
|
|
15
|
-
this.masking = new
|
|
15
|
+
this.masking = new maskingLayer_1.MaskingLayer("none");
|
|
16
16
|
// Define dangerous SQL keywords that should ALWAYS be blocked (critical security threats)
|
|
17
17
|
// These are blocked even with 'execute' permission
|
|
18
18
|
// Note: Avoid blocking common table/column names like "user" or "password"
|
|
@@ -61,11 +61,11 @@ class SecurityLayer {
|
|
|
61
61
|
: { valid: false, error: this.featureConfig.getPermissionError("executeDdl") };
|
|
62
62
|
}
|
|
63
63
|
const requiredPermissions = {
|
|
64
|
-
SELECT: [
|
|
65
|
-
INSERT: [
|
|
66
|
-
UPDATE: [
|
|
67
|
-
DELETE: [
|
|
68
|
-
INFORMATION: [
|
|
64
|
+
SELECT: [featureConfig_1.ToolCategory.READ],
|
|
65
|
+
INSERT: [featureConfig_1.ToolCategory.CREATE, featureConfig_1.ToolCategory.EXECUTE],
|
|
66
|
+
UPDATE: [featureConfig_1.ToolCategory.UPDATE, featureConfig_1.ToolCategory.EXECUTE],
|
|
67
|
+
DELETE: [featureConfig_1.ToolCategory.DELETE],
|
|
68
|
+
INFORMATION: [featureConfig_1.ToolCategory.LIST, featureConfig_1.ToolCategory.READ],
|
|
69
69
|
};
|
|
70
70
|
const permissions = requiredPermissions[queryType];
|
|
71
71
|
if (!permissions) {
|
|
@@ -200,10 +200,23 @@ class SecurityLayer {
|
|
|
200
200
|
}
|
|
201
201
|
// Enhanced query type detection with better parsing.
|
|
202
202
|
// EXPLAIN ANALYZE is classified by the inner statement it executes.
|
|
203
|
-
const
|
|
203
|
+
const statement = explainAnalyzeMatch ? explainAnalyzeMatch[1].trim() : cleanQuery;
|
|
204
|
+
// A WITH clause is authorized as the main statement that follows its CTEs.
|
|
205
|
+
const mainStatement = this.resolveCteMainStatement(statement);
|
|
206
|
+
if (mainStatement === null) {
|
|
207
|
+
return { valid: false, error: "Unable to parse WITH clause. Query type not allowed" };
|
|
208
|
+
}
|
|
209
|
+
const queryTypeResult = this.detectQueryType(mainStatement);
|
|
204
210
|
if (!queryTypeResult.valid) {
|
|
205
211
|
return queryTypeResult;
|
|
206
212
|
}
|
|
213
|
+
// CTEs are as expressive as derived tables, which also require execute permission.
|
|
214
|
+
if (!allowAdvancedQueries && /^WITH\b/.test(statement)) {
|
|
215
|
+
return {
|
|
216
|
+
valid: false,
|
|
217
|
+
error: "Common table expressions (WITH) not allowed without 'execute' permission",
|
|
218
|
+
};
|
|
219
|
+
}
|
|
207
220
|
if (!allowAdvancedQueries) {
|
|
208
221
|
// Additional checks for specific query types
|
|
209
222
|
if (queryTypeResult.queryType === "SELECT") {
|
|
@@ -215,10 +228,128 @@ class SecurityLayer {
|
|
|
215
228
|
}
|
|
216
229
|
return { valid: true, queryType: queryTypeResult.queryType };
|
|
217
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Blank out the contents of string literals and quoted identifiers so that
|
|
233
|
+
* comment, statement-separator, and keyword checks only see SQL syntax.
|
|
234
|
+
* Strings become '' and identifiers become `` (or their bare content when
|
|
235
|
+
* keepIdentifiers is set). Returns null when the query cannot be lexed
|
|
236
|
+
* unambiguously: an unterminated quote, or a backslash inside a literal,
|
|
237
|
+
* whose meaning depends on the NO_BACKSLASH_ESCAPES sql_mode.
|
|
238
|
+
*/
|
|
239
|
+
maskQuotedContent(query, keepIdentifiers = false) {
|
|
240
|
+
let result = "";
|
|
241
|
+
let i = 0;
|
|
242
|
+
while (i < query.length) {
|
|
243
|
+
const quote = query[i];
|
|
244
|
+
if (quote !== "'" && quote !== '"' && quote !== "`") {
|
|
245
|
+
result += quote;
|
|
246
|
+
i++;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
let content = "";
|
|
250
|
+
let j = i + 1;
|
|
251
|
+
let closed = false;
|
|
252
|
+
while (j < query.length) {
|
|
253
|
+
if (query[j] === quote) {
|
|
254
|
+
// A doubled quote is an escaped quote in both sql_modes
|
|
255
|
+
if (query[j + 1] === quote) {
|
|
256
|
+
content += quote + quote;
|
|
257
|
+
j += 2;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
closed = true;
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
if (query[j] === "\\" && quote !== "`") {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
content += query[j];
|
|
267
|
+
j++;
|
|
268
|
+
}
|
|
269
|
+
if (!closed) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
if (quote === "`") {
|
|
273
|
+
result += keepIdentifiers ? content : "``";
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
result += quote + quote;
|
|
277
|
+
}
|
|
278
|
+
i = j + 1;
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Return the main statement that follows the CTE definitions of a WITH
|
|
284
|
+
* clause, the statement itself when it has no WITH clause, or null when the
|
|
285
|
+
* WITH clause cannot be parsed.
|
|
286
|
+
*/
|
|
287
|
+
resolveCteMainStatement(statement) {
|
|
288
|
+
if (!/^WITH\b/i.test(statement)) {
|
|
289
|
+
return statement;
|
|
290
|
+
}
|
|
291
|
+
const masked = this.maskQuotedContent(statement);
|
|
292
|
+
if (masked === null) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
let rest = masked.replace(/^WITH\s+(?:RECURSIVE\s+)?/i, "");
|
|
296
|
+
while (true) {
|
|
297
|
+
const nameMatch = rest.match(/^(?:``|[A-Z0-9_$]+)\s*/i);
|
|
298
|
+
if (!nameMatch) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
rest = rest.slice(nameMatch[0].length);
|
|
302
|
+
// Optional column list
|
|
303
|
+
if (rest.startsWith("(")) {
|
|
304
|
+
const end = this.findClosingParen(rest);
|
|
305
|
+
if (end < 0) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
rest = rest.slice(end + 1).trimStart();
|
|
309
|
+
}
|
|
310
|
+
const asMatch = rest.match(/^AS\s*/i);
|
|
311
|
+
if (!asMatch) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
rest = rest.slice(asMatch[0].length);
|
|
315
|
+
if (!rest.startsWith("(")) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
const end = this.findClosingParen(rest);
|
|
319
|
+
if (end < 0) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
rest = rest.slice(end + 1).trimStart();
|
|
323
|
+
if (!rest.startsWith(",")) {
|
|
324
|
+
return rest;
|
|
325
|
+
}
|
|
326
|
+
rest = rest.slice(1).trimStart();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Index of the parenthesis closing the one at position 0, or -1 if unbalanced.
|
|
331
|
+
*/
|
|
332
|
+
findClosingParen(text) {
|
|
333
|
+
let depth = 0;
|
|
334
|
+
for (let i = 0; i < text.length; i++) {
|
|
335
|
+
if (text[i] === "(") {
|
|
336
|
+
depth++;
|
|
337
|
+
}
|
|
338
|
+
else if (text[i] === ")") {
|
|
339
|
+
depth--;
|
|
340
|
+
if (depth === 0) {
|
|
341
|
+
return i;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return -1;
|
|
346
|
+
}
|
|
218
347
|
/**
|
|
219
348
|
* Enhanced comment detection to prevent bypass techniques
|
|
220
349
|
*/
|
|
221
|
-
detectComments(
|
|
350
|
+
detectComments(rawQuery) {
|
|
351
|
+
// Quoted content is data, not syntax; fall back to the raw text if ambiguous
|
|
352
|
+
const query = this.maskQuotedContent(rawQuery) ?? rawQuery;
|
|
222
353
|
// Check for various comment types and bypass attempts
|
|
223
354
|
const commentPatterns = [
|
|
224
355
|
/\/\*[\s\S]*?\*\//g, // Multi-line comments
|
|
@@ -261,15 +392,15 @@ class SecurityLayer {
|
|
|
261
392
|
* Enhanced multiple statement detection
|
|
262
393
|
*/
|
|
263
394
|
detectMultipleStatements(query) {
|
|
264
|
-
// Remove
|
|
265
|
-
const queryWithoutStrings =
|
|
395
|
+
// Remove quoted content to avoid false positives; fall back to the raw text if ambiguous
|
|
396
|
+
const queryWithoutStrings = this.maskQuotedContent(query) ?? query;
|
|
266
397
|
// Check for multiple semicolons not at the end
|
|
267
398
|
const semicolonMatches = queryWithoutStrings.match(/;/g);
|
|
268
399
|
if (semicolonMatches && semicolonMatches.length > 1) {
|
|
269
400
|
return { valid: false, error: "Multiple statements not allowed" };
|
|
270
401
|
}
|
|
271
402
|
// Check for semicolon not at the very end (after trimming)
|
|
272
|
-
const trimmedQuery =
|
|
403
|
+
const trimmedQuery = queryWithoutStrings.trim();
|
|
273
404
|
if (trimmedQuery.includes(';') && !trimmedQuery.endsWith(';')) {
|
|
274
405
|
return { valid: false, error: "Multiple statements not allowed" };
|
|
275
406
|
}
|
|
@@ -312,10 +443,9 @@ class SecurityLayer {
|
|
|
312
443
|
* Enhanced dangerous keyword detection
|
|
313
444
|
*/
|
|
314
445
|
detectDangerousKeywords(cleanQuery, allowAdvancedQueries) {
|
|
315
|
-
// Remove string literals to avoid false positives
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
.replace(/`([^`]*)`/g, "$1");
|
|
446
|
+
// Remove string literals to avoid false positives, and unwrap quoted
|
|
447
|
+
// identifiers so `mysql`.`user` is still detected
|
|
448
|
+
const queryWithoutStrings = this.maskQuotedContent(cleanQuery, true) ?? cleanQuery.replace(/`/g, "");
|
|
319
449
|
for (const keyword of this.dangerousKeywords) {
|
|
320
450
|
// Enhanced regex with word boundaries and case insensitivity
|
|
321
451
|
const keywordRegex = new RegExp(`\\b${keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'i');
|
|
@@ -358,8 +488,8 @@ class SecurityLayer {
|
|
|
358
488
|
* Enhanced SELECT query validation
|
|
359
489
|
*/
|
|
360
490
|
validateSelectQuery(cleanQuery) {
|
|
361
|
-
// Remove
|
|
362
|
-
const queryWithoutStrings =
|
|
491
|
+
// Remove quoted content to avoid false positives
|
|
492
|
+
const queryWithoutStrings = this.maskQuotedContent(cleanQuery) ?? cleanQuery;
|
|
363
493
|
// Check for UNION attacks
|
|
364
494
|
if (/\bUNION\b/i.test(queryWithoutStrings)) {
|
|
365
495
|
return {
|
|
@@ -456,7 +586,7 @@ class SecurityLayer {
|
|
|
456
586
|
* Check if execute permission is enabled
|
|
457
587
|
*/
|
|
458
588
|
hasExecutePermission() {
|
|
459
|
-
return this.featureConfig.isCategoryEnabled(
|
|
589
|
+
return this.featureConfig.isCategoryEnabled(featureConfig_1.ToolCategory.EXECUTE);
|
|
460
590
|
}
|
|
461
591
|
/**
|
|
462
592
|
* Escape identifier for safe use in SQL queries
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateToolArguments = validateToolArguments;
|
|
4
|
-
const
|
|
4
|
+
const inputValidation_1 = require("../validation/inputValidation");
|
|
5
5
|
const validatePlanSeedDataArgs = (args) => {
|
|
6
6
|
const errors = [];
|
|
7
7
|
if (!Array.isArray(args.target_tables) || args.target_tables.length === 0) {
|
|
@@ -9,14 +9,14 @@ const validatePlanSeedDataArgs = (args) => {
|
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
11
|
for (const table of args.target_tables) {
|
|
12
|
-
const validation = (0,
|
|
12
|
+
const validation = (0, inputValidation_1.validateTableName)(table);
|
|
13
13
|
if (!validation.valid) {
|
|
14
14
|
errors.push(`Invalid target table '${table}': ${validation.error}`);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
if (args.database !== undefined) {
|
|
19
|
-
const validation = (0,
|
|
19
|
+
const validation = (0, inputValidation_1.validateValue)(args.database);
|
|
20
20
|
if (!validation.valid)
|
|
21
21
|
errors.push(validation.error || "Invalid database name");
|
|
22
22
|
}
|
|
@@ -34,7 +34,7 @@ const validateRowsPerTable = (rowsPerTable, errors) => {
|
|
|
34
34
|
}
|
|
35
35
|
if (typeof rowsPerTable === "object" && rowsPerTable !== null && !Array.isArray(rowsPerTable)) {
|
|
36
36
|
for (const [table, count] of Object.entries(rowsPerTable)) {
|
|
37
|
-
const tableValidation = (0,
|
|
37
|
+
const tableValidation = (0, inputValidation_1.validateTableName)(table);
|
|
38
38
|
if (!tableValidation.valid)
|
|
39
39
|
errors.push(`Invalid rows_per_table key '${table}': ${tableValidation.error}`);
|
|
40
40
|
if (typeof count !== "number" || !Number.isFinite(count) || count < 0) {
|
|
@@ -53,7 +53,7 @@ const validateTableList = (value, key, errors) => {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
for (const table of value) {
|
|
56
|
-
const validation = (0,
|
|
56
|
+
const validation = (0, inputValidation_1.validateTableName)(table);
|
|
57
57
|
if (!validation.valid)
|
|
58
58
|
errors.push(`Invalid ${key} table '${table}': ${validation.error}`);
|
|
59
59
|
}
|
|
@@ -61,7 +61,7 @@ const validateTableList = (value, key, errors) => {
|
|
|
61
61
|
const validateInferSeedRulesArgs = (args) => {
|
|
62
62
|
const errors = [];
|
|
63
63
|
if (args.database !== undefined) {
|
|
64
|
-
const validation = (0,
|
|
64
|
+
const validation = (0, inputValidation_1.validateValue)(args.database);
|
|
65
65
|
if (!validation.valid)
|
|
66
66
|
errors.push(validation.error || "Invalid database name");
|
|
67
67
|
}
|
|
@@ -83,7 +83,7 @@ const validateSeedFromTemplateArgs = (args) => {
|
|
|
83
83
|
errors.push("template must be one of ecommerce, pos, crm");
|
|
84
84
|
}
|
|
85
85
|
if (args.database !== undefined) {
|
|
86
|
-
const validation = (0,
|
|
86
|
+
const validation = (0, inputValidation_1.validateValue)(args.database);
|
|
87
87
|
if (!validation.valid)
|
|
88
88
|
errors.push(validation.error || "Invalid database name");
|
|
89
89
|
}
|
|
@@ -104,7 +104,7 @@ const validateDiscoveryKeyword = (value, key, errors) => {
|
|
|
104
104
|
errors.push(`${key} must be 255 characters or fewer`);
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
|
-
const validation = (0,
|
|
107
|
+
const validation = (0, inputValidation_1.validateValue)(value);
|
|
108
108
|
if (!validation.valid)
|
|
109
109
|
errors.push(validation.error || `Invalid ${key}`);
|
|
110
110
|
};
|
|
@@ -124,7 +124,7 @@ const validateColumnList = (value, key, errors) => {
|
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
for (const column of value) {
|
|
127
|
-
const validation = (0,
|
|
127
|
+
const validation = (0, inputValidation_1.validateTableName)(column);
|
|
128
128
|
if (!validation.valid) {
|
|
129
129
|
errors.push(`Invalid ${key} column '${column}': ${validation.error}`);
|
|
130
130
|
}
|
|
@@ -137,7 +137,7 @@ const validateFindTablesByKeywordArgs = (args) => {
|
|
|
137
137
|
errors.push("search_in must be one of table_names, column_names, comments, all");
|
|
138
138
|
}
|
|
139
139
|
if (args.database !== undefined) {
|
|
140
|
-
const validation = (0,
|
|
140
|
+
const validation = (0, inputValidation_1.validateValue)(args.database);
|
|
141
141
|
if (!validation.valid)
|
|
142
142
|
errors.push(validation.error || "Invalid database name");
|
|
143
143
|
}
|
|
@@ -148,7 +148,7 @@ const validateSearchDataAcrossTablesArgs = (args) => {
|
|
|
148
148
|
const errors = [];
|
|
149
149
|
validateDiscoveryKeyword(args.keyword, "keyword", errors);
|
|
150
150
|
if (args.database !== undefined) {
|
|
151
|
-
const validation = (0,
|
|
151
|
+
const validation = (0, inputValidation_1.validateValue)(args.database);
|
|
152
152
|
if (!validation.valid)
|
|
153
153
|
errors.push(validation.error || "Invalid database name");
|
|
154
154
|
}
|
|
@@ -162,7 +162,7 @@ const validateSearchSchemaArgs = (args) => {
|
|
|
162
162
|
const errors = [];
|
|
163
163
|
validateDiscoveryKeyword(args.query, "query", errors);
|
|
164
164
|
if (args.database !== undefined) {
|
|
165
|
-
const validation = (0,
|
|
165
|
+
const validation = (0, inputValidation_1.validateValue)(args.database);
|
|
166
166
|
if (!validation.valid)
|
|
167
167
|
errors.push(validation.error || "Invalid database name");
|
|
168
168
|
}
|
|
@@ -189,7 +189,7 @@ const validateSearchSchemaArgs = (args) => {
|
|
|
189
189
|
const validateSchemaRagContextArgs = (args) => {
|
|
190
190
|
const errors = [];
|
|
191
191
|
if (args.database !== undefined) {
|
|
192
|
-
const validation = (0,
|
|
192
|
+
const validation = (0, inputValidation_1.validateValue)(args.database);
|
|
193
193
|
if (!validation.valid)
|
|
194
194
|
errors.push(validation.error || "Invalid database name");
|
|
195
195
|
}
|
|
@@ -215,24 +215,24 @@ function validateToolArguments(name, args) {
|
|
|
215
215
|
try {
|
|
216
216
|
switch (name) {
|
|
217
217
|
case "create_record":
|
|
218
|
-
return (0,
|
|
218
|
+
return (0, inputValidation_1.validateCreateRecord)(args);
|
|
219
219
|
case "read_records":
|
|
220
|
-
return (0,
|
|
220
|
+
return (0, inputValidation_1.validateReadRecords)(args);
|
|
221
221
|
case "update_record":
|
|
222
|
-
return (0,
|
|
222
|
+
return (0, inputValidation_1.validateUpdateRecord)(args);
|
|
223
223
|
case "delete_record":
|
|
224
|
-
return (0,
|
|
224
|
+
return (0, inputValidation_1.validateDeleteRecord)(args);
|
|
225
225
|
case "run_select_query":
|
|
226
226
|
case "execute_write_query":
|
|
227
227
|
case "execute_ddl":
|
|
228
|
-
return (0,
|
|
228
|
+
return (0, inputValidation_1.validateQuery)({ query: args?.query || "" });
|
|
229
229
|
case "export_query_to_csv":
|
|
230
|
-
return (0,
|
|
230
|
+
return (0, inputValidation_1.validateQuery)({
|
|
231
231
|
query: args?.query || "",
|
|
232
232
|
params: args?.params,
|
|
233
233
|
});
|
|
234
234
|
case "bulk_insert":
|
|
235
|
-
return (0,
|
|
235
|
+
return (0, inputValidation_1.validateBulkInsert)(args);
|
|
236
236
|
case "plan_seed_data":
|
|
237
237
|
return validatePlanSeedDataArgs(args);
|
|
238
238
|
case "generate_seed_preview":
|
|
@@ -255,7 +255,7 @@ function validateToolArguments(name, args) {
|
|
|
255
255
|
case "get_schema_erd":
|
|
256
256
|
case "get_database_summary":
|
|
257
257
|
if (args.database !== undefined) {
|
|
258
|
-
const validation = (0,
|
|
258
|
+
const validation = (0, inputValidation_1.validateValue)(args.database);
|
|
259
259
|
if (!validation.valid) {
|
|
260
260
|
return {
|
|
261
261
|
valid: false,
|
|
@@ -267,7 +267,7 @@ function validateToolArguments(name, args) {
|
|
|
267
267
|
case "get_column_statistics":
|
|
268
268
|
case "read_table_schema":
|
|
269
269
|
if (args.table_name) {
|
|
270
|
-
const validation = (0,
|
|
270
|
+
const validation = (0, inputValidation_1.validateTableName)(args.table_name);
|
|
271
271
|
if (!validation.valid) {
|
|
272
272
|
return {
|
|
273
273
|
valid: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import { MySQLMCP } from "../index
|
|
2
|
+
import { MySQLMCP } from "../index";
|
|
3
3
|
export declare const isToolEnabled: (mysqlMCP: MySQLMCP, tool: Tool) => boolean;
|
|
4
4
|
export declare const getEnabledTools: (mysqlMCP: MySQLMCP, tools: Tool[]) => Tool[];
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEnabledTools = exports.isToolEnabled = void 0;
|
|
4
|
+
const featureConfig_1 = require("../config/featureConfig");
|
|
4
5
|
const toCamelCase = (value) => value.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
5
6
|
const isToolEnabled = (mysqlMCP, tool) => {
|
|
6
7
|
const camelCaseName = toCamelCase(tool.name);
|
|
7
|
-
|
|
8
|
+
// Some tools are only mapped by their snake_case name; checking an unmapped
|
|
9
|
+
// name logs an "Unknown tool" warning, so pick the mapped one.
|
|
10
|
+
const mappedName = featureConfig_1.toolCategoryMap[camelCaseName] || featureConfig_1.toolDocCategoryMap[camelCaseName]
|
|
11
|
+
? camelCaseName
|
|
12
|
+
: tool.name;
|
|
13
|
+
return mysqlMCP.isToolEnabled(mappedName);
|
|
8
14
|
};
|
|
9
15
|
exports.isToolEnabled = isToolEnabled;
|
|
10
16
|
const getEnabledTools = (mysqlMCP, tools) => tools.filter((tool) => (0, exports.isToolEnabled)(mysqlMCP, tool));
|
package/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,78 +1,86 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@berthojoris/mcp-mysql-server",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Model Context Protocol server for MySQL database integration with dynamic per-project permissions",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"type": "commonjs",
|
|
8
|
-
"bin": {
|
|
9
|
-
"mcp-mysql": "bin/mcp-mysql.js"
|
|
10
|
-
},
|
|
11
|
-
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"@
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@berthojoris/mcp-mysql-server",
|
|
3
|
+
"version": "1.44.0",
|
|
4
|
+
"description": "Model Context Protocol server for MySQL database integration with dynamic per-project permissions",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"bin": {
|
|
9
|
+
"mcp-mysql": "bin/mcp-mysql.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
13
|
+
"build": "npm run clean && tsc",
|
|
14
|
+
"start": "node dist/mcp-server.js",
|
|
15
|
+
"dev": "ts-node src/mcp-server.ts",
|
|
16
|
+
"test": "jest --passWithNoTests",
|
|
17
|
+
"lint": "eslint src/**/*.ts --quiet",
|
|
18
|
+
"prepare": "npm run build",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"mcp",
|
|
23
|
+
"mysql",
|
|
24
|
+
"database",
|
|
25
|
+
"llm",
|
|
26
|
+
"ai",
|
|
27
|
+
"model-context-protocol",
|
|
28
|
+
"claude",
|
|
29
|
+
"cline",
|
|
30
|
+
"windsurf",
|
|
31
|
+
"codex",
|
|
32
|
+
"openai-codex",
|
|
33
|
+
"agent",
|
|
34
|
+
"database-tools",
|
|
35
|
+
"sql",
|
|
36
|
+
"mysql-client",
|
|
37
|
+
"ai-tools"
|
|
38
|
+
],
|
|
39
|
+
"author": "Bertho Joris <berthojoris@gmail.com>",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/berthojoris/mysql-mcp.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/berthojoris/mysql-mcp/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/berthojoris/mysql-mcp#readme",
|
|
49
|
+
"files": [
|
|
50
|
+
"dist",
|
|
51
|
+
"bin",
|
|
52
|
+
"README.md",
|
|
53
|
+
"DOCUMENTATIONS.md",
|
|
54
|
+
"CHANGELOG.md",
|
|
55
|
+
"LICENSE",
|
|
56
|
+
"manifest.json"
|
|
57
|
+
],
|
|
58
|
+
"jest": {
|
|
59
|
+
"preset": "ts-jest",
|
|
60
|
+
"testEnvironment": "node",
|
|
61
|
+
"roots": [
|
|
62
|
+
"<rootDir>/src"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=18.0.0"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@modelcontextprotocol/sdk": "^1.20.0",
|
|
70
|
+
"ajv": "^8.12.0",
|
|
71
|
+
"ajv-formats": "^3.0.1",
|
|
72
|
+
"dotenv": "^16.3.1",
|
|
73
|
+
"mysql2": "^3.6.1"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@types/jest": "^29.5.4",
|
|
77
|
+
"@types/node": "^20.6.0",
|
|
78
|
+
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
79
|
+
"@typescript-eslint/parser": "^8.50.1",
|
|
80
|
+
"eslint": "^9.39.2",
|
|
81
|
+
"jest": "^29.6.4",
|
|
82
|
+
"ts-jest": "^29.1.1",
|
|
83
|
+
"ts-node": "^10.9.1",
|
|
84
|
+
"typescript": "^5.2.2"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
2
|
-
export interface User {
|
|
3
|
-
id: string;
|
|
4
|
-
username: string;
|
|
5
|
-
role: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class AuthService {
|
|
8
|
-
/**
|
|
9
|
-
* Generate a JWT token for a user
|
|
10
|
-
*/
|
|
11
|
-
generateToken(user: User): string;
|
|
12
|
-
/**
|
|
13
|
-
* Verify a JWT token
|
|
14
|
-
*/
|
|
15
|
-
verifyToken(token: string): User;
|
|
16
|
-
/**
|
|
17
|
-
* Middleware to authenticate using JWT
|
|
18
|
-
*/
|
|
19
|
-
authenticateJWT(req: Request, res: Response, next: NextFunction): void;
|
|
20
|
-
/**
|
|
21
|
-
* Middleware to authenticate using API key
|
|
22
|
-
*/
|
|
23
|
-
authenticateApiKey(req: Request, res: Response, next: NextFunction): void;
|
|
24
|
-
/**
|
|
25
|
-
* Login endpoint handler
|
|
26
|
-
*/
|
|
27
|
-
login(req: Request, res: Response): void;
|
|
28
|
-
}
|
|
29
|
-
export declare const authService: AuthService;
|