@berthojoris/mcp-mysql-server 1.43.5 → 1.45.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/CHANGELOG.md +61 -0
- package/DOCUMENTATIONS.md +674 -508
- package/README.md +468 -376
- package/bin/mcp-mysql.js +214 -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/config/runtimeConfig.d.ts +50 -0
- package/dist/config/runtimeConfig.js +173 -0
- package/dist/db/connection.d.ts +40 -1
- package/dist/db/connection.js +188 -22
- package/dist/mcp-server.js +248 -375
- package/dist/security/grantInspector.d.ts +5 -0
- package/dist/security/grantInspector.js +32 -0
- package/dist/security/securityLayer.d.ts +21 -2
- package/dist/security/securityLayer.js +151 -21
- package/dist/server/auditLogger.d.ts +24 -0
- package/dist/server/auditLogger.js +60 -0
- package/dist/server/auth.d.ts +56 -0
- package/dist/server/auth.js +274 -0
- package/dist/server/httpServer.d.ts +22 -0
- package/dist/server/httpServer.js +320 -0
- package/dist/server/rateLimiter.d.ts +15 -0
- package/dist/server/rateLimiter.js +41 -0
- package/dist/server/requestContext.d.ts +12 -0
- package/dist/server/requestContext.js +9 -0
- package/dist/tools/toolAnnotations.d.ts +4 -0
- package/dist/tools/toolAnnotations.js +73 -0
- 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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRequestContext = exports.runWithRequestContext = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
const storage = new async_hooks_1.AsyncLocalStorage();
|
|
6
|
+
const runWithRequestContext = (context, fn) => storage.run(context, fn);
|
|
7
|
+
exports.runWithRequestContext = runWithRequestContext;
|
|
8
|
+
const getRequestContext = () => storage.getStore();
|
|
9
|
+
exports.getRequestContext = getRequestContext;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Tool, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
export declare const getToolAnnotations: (name: string) => ToolAnnotations;
|
|
3
|
+
export declare const hasExplicitAnnotations: (name: string) => boolean;
|
|
4
|
+
export declare const withToolAnnotations: (tools: Tool[]) => Tool[];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withToolAnnotations = exports.hasExplicitAnnotations = exports.getToolAnnotations = void 0;
|
|
4
|
+
// Reads only: no data, schema, or server state changes
|
|
5
|
+
const READ_TOOLS = [
|
|
6
|
+
"list_databases", "list_tables", "get_database_summary", "get_schema_erd",
|
|
7
|
+
"get_schema_rag_context", "find_tables_by_keyword", "search_schema",
|
|
8
|
+
"search_data_across_tables", "get_column_statistics", "read_table_schema",
|
|
9
|
+
"read_records", "plan_seed_data", "generate_seed_preview",
|
|
10
|
+
"validate_seed_integrity", "infer_seed_rules", "seed_from_template",
|
|
11
|
+
"run_select_query", "repair_query", "describe_connection", "read_changelog",
|
|
12
|
+
"test_connection", "list_all_tools", "get_all_tables_relationships",
|
|
13
|
+
"get_transaction_status", "list_stored_procedures", "get_stored_procedure_info",
|
|
14
|
+
"show_create_procedure", "export_table_to_csv", "export_query_to_csv",
|
|
15
|
+
"analyze_query", "get_optimization_hints", "list_views", "get_view_info",
|
|
16
|
+
"show_create_view", "list_triggers", "get_trigger_info", "show_create_trigger",
|
|
17
|
+
"list_indexes", "get_index_info", "list_foreign_keys", "list_constraints",
|
|
18
|
+
"check_table", "get_table_status", "get_table_size", "fulltext_search",
|
|
19
|
+
"get_fulltext_info", "get_fulltext_stats",
|
|
20
|
+
];
|
|
21
|
+
// Change state but only add to it or maintain it; existing data is kept
|
|
22
|
+
const WRITE_TOOLS = [
|
|
23
|
+
"create_record", "bulk_insert", "execute_seed_plan", "begin_transaction",
|
|
24
|
+
"rollback_transaction", "create_table", "create_trigger", "create_index",
|
|
25
|
+
"add_foreign_key", "add_unique_constraint", "add_check_constraint",
|
|
26
|
+
"create_stored_procedure", "create_fulltext_index",
|
|
27
|
+
];
|
|
28
|
+
// Maintenance statements that leave the same state when repeated
|
|
29
|
+
const IDEMPOTENT_WRITE_TOOLS = [
|
|
30
|
+
"analyze_table", "analyze_index", "optimize_table", "flush_table", "optimize_fulltext",
|
|
31
|
+
];
|
|
32
|
+
// May overwrite or remove data or schema objects, or run arbitrary statements
|
|
33
|
+
const DESTRUCTIVE_TOOLS = [
|
|
34
|
+
"update_record", "delete_record", "bulk_update", "bulk_delete",
|
|
35
|
+
"execute_write_query", "alter_table", "drop_table", "execute_ddl",
|
|
36
|
+
"cursor_execute_request", "commit_transaction", "execute_in_transaction",
|
|
37
|
+
"execute_stored_procedure", "drop_stored_procedure", "create_view",
|
|
38
|
+
"alter_view", "drop_view", "drop_trigger", "drop_index", "drop_foreign_key",
|
|
39
|
+
"drop_constraint", "repair_table", "truncate_table", "drop_fulltext_index",
|
|
40
|
+
];
|
|
41
|
+
const behaviors = new Map();
|
|
42
|
+
for (const name of READ_TOOLS)
|
|
43
|
+
behaviors.set(name, { behavior: "read", idempotent: true });
|
|
44
|
+
for (const name of WRITE_TOOLS)
|
|
45
|
+
behaviors.set(name, { behavior: "write", idempotent: false });
|
|
46
|
+
for (const name of IDEMPOTENT_WRITE_TOOLS)
|
|
47
|
+
behaviors.set(name, { behavior: "write", idempotent: true });
|
|
48
|
+
for (const name of DESTRUCTIVE_TOOLS)
|
|
49
|
+
behaviors.set(name, { behavior: "destructive", idempotent: false });
|
|
50
|
+
const ACRONYMS = { csv: "CSV", erd: "ERD", rag: "RAG", ddl: "DDL" };
|
|
51
|
+
const toTitle = (name) => name
|
|
52
|
+
.split("_")
|
|
53
|
+
.map((word) => ACRONYMS[word] || word.charAt(0).toUpperCase() + word.slice(1))
|
|
54
|
+
.join(" ");
|
|
55
|
+
const getToolAnnotations = (name) => {
|
|
56
|
+
// Unknown tools are treated as destructive, the safest hint
|
|
57
|
+
const entry = behaviors.get(name) || { behavior: "destructive", idempotent: false };
|
|
58
|
+
return {
|
|
59
|
+
title: toTitle(name),
|
|
60
|
+
readOnlyHint: entry.behavior === "read",
|
|
61
|
+
destructiveHint: entry.behavior === "destructive",
|
|
62
|
+
idempotentHint: entry.idempotent,
|
|
63
|
+
openWorldHint: false,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.getToolAnnotations = getToolAnnotations;
|
|
67
|
+
const hasExplicitAnnotations = (name) => behaviors.has(name);
|
|
68
|
+
exports.hasExplicitAnnotations = hasExplicitAnnotations;
|
|
69
|
+
const withToolAnnotations = (tools) => tools.map((tool) => ({
|
|
70
|
+
...tool,
|
|
71
|
+
annotations: { ...(0, exports.getToolAnnotations)(tool.name), ...(tool.annotations || {}) },
|
|
72
|
+
}));
|
|
73
|
+
exports.withToolAnnotations = withToolAnnotations;
|
|
@@ -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.45.2",
|
|
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;
|
package/dist/auth/authService.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.authService = exports.AuthService = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
// Environment variables
|
|
9
|
-
const JWT_SECRET = process.env.JWT_SECRET || 'default_secret_change_in_production';
|
|
10
|
-
const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || '24h';
|
|
11
|
-
const API_KEY = process.env.API_KEY;
|
|
12
|
-
class AuthService {
|
|
13
|
-
/**
|
|
14
|
-
* Generate a JWT token for a user
|
|
15
|
-
*/
|
|
16
|
-
generateToken(user) {
|
|
17
|
-
// Cast to any to bypass TypeScript's strict type checking for JWT
|
|
18
|
-
return jsonwebtoken_1.default.sign(user, JWT_SECRET, { expiresIn: JWT_EXPIRES_IN });
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Verify a JWT token
|
|
22
|
-
*/
|
|
23
|
-
verifyToken(token) {
|
|
24
|
-
// Cast to any to bypass TypeScript's strict type checking for JWT
|
|
25
|
-
return jsonwebtoken_1.default.verify(token, JWT_SECRET);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Middleware to authenticate using JWT
|
|
29
|
-
*/
|
|
30
|
-
authenticateJWT(req, res, next) {
|
|
31
|
-
const authHeader = req.headers['authorization'];
|
|
32
|
-
const token = authHeader && authHeader.split(' ')[1];
|
|
33
|
-
if (!token) {
|
|
34
|
-
res.status(401).json({
|
|
35
|
-
error: {
|
|
36
|
-
code: 'AUTH_TOKEN_MISSING',
|
|
37
|
-
message: 'Authentication token is required',
|
|
38
|
-
details: 'Please provide a valid JWT token in the Authorization header'
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
const user = this.verifyToken(token);
|
|
45
|
-
req.user = user;
|
|
46
|
-
next();
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
res.status(403).json({
|
|
50
|
-
error: {
|
|
51
|
-
code: 'AUTH_TOKEN_INVALID',
|
|
52
|
-
message: 'Invalid or expired token',
|
|
53
|
-
details: 'Please provide a valid JWT token'
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Middleware to authenticate using API key
|
|
60
|
-
*/
|
|
61
|
-
authenticateApiKey(req, res, next) {
|
|
62
|
-
const providedApiKey = req.headers['x-api-key'];
|
|
63
|
-
if (!API_KEY) {
|
|
64
|
-
console.warn('API_KEY environment variable is not set');
|
|
65
|
-
res.status(500).json({
|
|
66
|
-
error: {
|
|
67
|
-
code: 'SERVER_CONFIG_ERROR',
|
|
68
|
-
message: 'Server configuration error',
|
|
69
|
-
details: 'API key authentication is not properly configured'
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (!providedApiKey || providedApiKey !== API_KEY) {
|
|
75
|
-
res.status(401).json({
|
|
76
|
-
error: {
|
|
77
|
-
code: 'INVALID_API_KEY',
|
|
78
|
-
message: 'Invalid API key',
|
|
79
|
-
details: 'Please provide a valid API key in the X-API-Key header'
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
next();
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Login endpoint handler
|
|
88
|
-
*/
|
|
89
|
-
login(req, res) {
|
|
90
|
-
const { username, password } = req.body;
|
|
91
|
-
// In a real application, you would validate credentials against a database
|
|
92
|
-
// This is a simplified example for demonstration purposes
|
|
93
|
-
if (username === 'admin' && password === 'password') {
|
|
94
|
-
const user = {
|
|
95
|
-
id: '1',
|
|
96
|
-
username: 'admin',
|
|
97
|
-
role: 'admin'
|
|
98
|
-
};
|
|
99
|
-
const token = this.generateToken(user);
|
|
100
|
-
res.json({ token });
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
res.status(401).json({
|
|
104
|
-
error: {
|
|
105
|
-
code: 'INVALID_CREDENTIALS',
|
|
106
|
-
message: 'Invalid username or password',
|
|
107
|
-
details: 'Please check your credentials and try again'
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.AuthService = AuthService;
|
|
114
|
-
exports.authService = new AuthService();
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import SecurityLayer from "../security/securityLayer";
|
|
2
|
-
/**
|
|
3
|
-
* Backup and Restore Tools for MySQL MCP Server
|
|
4
|
-
* Provides database backup (SQL dump generation) and restore functionality
|
|
5
|
-
*/
|
|
6
|
-
export declare class BackupRestoreTools {
|
|
7
|
-
private db;
|
|
8
|
-
private security;
|
|
9
|
-
constructor(security: SecurityLayer);
|
|
10
|
-
/**
|
|
11
|
-
* Validate database access
|
|
12
|
-
*/
|
|
13
|
-
private validateDatabaseAccess;
|
|
14
|
-
/**
|
|
15
|
-
* Escape string value for SQL
|
|
16
|
-
*/
|
|
17
|
-
private escapeValue;
|
|
18
|
-
}
|