@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +57 -6
  2. package/DOCUMENTATIONS.md +40 -38
  3. package/README.md +26 -7
  4. package/bin/mcp-mysql.js +168 -168
  5. package/dist/cache/queryCache.js +1 -1
  6. package/dist/config/config.js +2 -1
  7. package/dist/config/featureConfig.d.ts +5 -0
  8. package/dist/config/featureConfig.js +26 -12
  9. package/dist/db/connection.d.ts +8 -1
  10. package/dist/db/connection.js +19 -14
  11. package/dist/index.js +0 -10
  12. package/dist/mcp-server.js +45 -305
  13. package/dist/security/securityLayer.d.ts +33 -5
  14. package/dist/security/securityLayer.js +211 -58
  15. package/dist/tools/aiTools.js +1 -1
  16. package/dist/tools/dataExportTools.js +8 -0
  17. package/dist/tools/queryTools.d.ts +1 -1
  18. package/dist/tools/queryTools.js +6 -7
  19. package/dist/tools/toolArgumentValidation.js +22 -22
  20. package/dist/tools/toolRegistry.d.ts +1 -1
  21. package/dist/tools/toolRegistry.js +7 -1
  22. package/dist/tools/transactionTools.js +1 -1
  23. package/manifest.json +5 -5
  24. package/package.json +86 -78
  25. package/dist/auth/authService.d.ts +0 -29
  26. package/dist/auth/authService.js +0 -114
  27. package/dist/tools/backupRestoreTools.d.ts +0 -18
  28. package/dist/tools/backupRestoreTools.js +0 -70
  29. package/dist/tools/documentationGeneratorTools.d.ts +0 -145
  30. package/dist/tools/documentationGeneratorTools.js +0 -820
  31. package/dist/tools/forecastingTools.d.ts +0 -36
  32. package/dist/tools/forecastingTools.js +0 -256
  33. package/dist/tools/functionTools.d.ts +0 -87
  34. package/dist/tools/functionTools.js +0 -358
  35. package/dist/tools/indexRecommendationTools.d.ts +0 -50
  36. package/dist/tools/indexRecommendationTools.js +0 -451
  37. package/dist/tools/intelligentQueryTools.d.ts +0 -94
  38. package/dist/tools/intelligentQueryTools.js +0 -713
  39. package/dist/tools/performanceTools.d.ts +0 -76
  40. package/dist/tools/performanceTools.js +0 -505
  41. package/dist/tools/processTools.d.ts +0 -61
  42. package/dist/tools/processTools.js +0 -181
  43. package/dist/tools/queryVisualizationTools.d.ts +0 -22
  44. package/dist/tools/queryVisualizationTools.js +0 -155
  45. package/dist/tools/schemaDesignTools.d.ts +0 -67
  46. package/dist/tools/schemaDesignTools.js +0 -359
  47. package/dist/tools/schemaPatternTools.d.ts +0 -19
  48. package/dist/tools/schemaPatternTools.js +0 -253
  49. package/dist/tools/schemaVersioningTools.d.ts +0 -138
  50. package/dist/tools/schemaVersioningTools.js +0 -1008
  51. package/dist/tools/securityAuditTools.d.ts +0 -39
  52. package/dist/tools/securityAuditTools.js +0 -319
  53. package/dist/tools/smartDiscoveryTools.d.ts +0 -163
  54. package/dist/tools/smartDiscoveryTools.js +0 -750
  55. package/dist/tools/testDataTools.d.ts +0 -26
  56. package/dist/tools/testDataTools.js +0 -325
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateToolArguments = validateToolArguments;
4
- const inputValidation_js_1 = require("../validation/inputValidation.js");
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, inputValidation_js_1.validateTableName)(table);
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, inputValidation_js_1.validateValue)(args.database);
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, inputValidation_js_1.validateTableName)(table);
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, inputValidation_js_1.validateTableName)(table);
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, inputValidation_js_1.validateValue)(args.database);
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, inputValidation_js_1.validateValue)(args.database);
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, inputValidation_js_1.validateValue)(value);
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, inputValidation_js_1.validateTableName)(column);
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, inputValidation_js_1.validateValue)(args.database);
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, inputValidation_js_1.validateValue)(args.database);
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, inputValidation_js_1.validateValue)(args.database);
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, inputValidation_js_1.validateValue)(args.database);
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, inputValidation_js_1.validateCreateRecord)(args);
218
+ return (0, inputValidation_1.validateCreateRecord)(args);
219
219
  case "read_records":
220
- return (0, inputValidation_js_1.validateReadRecords)(args);
220
+ return (0, inputValidation_1.validateReadRecords)(args);
221
221
  case "update_record":
222
- return (0, inputValidation_js_1.validateUpdateRecord)(args);
222
+ return (0, inputValidation_1.validateUpdateRecord)(args);
223
223
  case "delete_record":
224
- return (0, inputValidation_js_1.validateDeleteRecord)(args);
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, inputValidation_js_1.validateQuery)({ query: args?.query || "" });
228
+ return (0, inputValidation_1.validateQuery)({ query: args?.query || "" });
229
229
  case "export_query_to_csv":
230
- return (0, inputValidation_js_1.validateQuery)({
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, inputValidation_js_1.validateBulkInsert)(args);
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, inputValidation_js_1.validateValue)(args.database);
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, inputValidation_js_1.validateTableName)(args.table_name);
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.js";
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
- return mysqlMCP.isToolEnabled(camelCaseName) || mysqlMCP.isToolEnabled(tool.name);
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));
@@ -116,7 +116,7 @@ class TransactionTools {
116
116
  };
117
117
  }
118
118
  // SECURITY VALIDATION: Check if user has execute permission
119
- const hasExecutePermission = this.security.isToolEnabled("executeWriteQuery");
119
+ const hasExecutePermission = this.security.hasExecutePermission();
120
120
  // SECURITY VALIDATION: Validate the query before execution
121
121
  const queryValidation = this.security.validateQuery(params.query, hasExecutePermission);
122
122
  if (!queryValidation.valid) {
package/manifest.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mysql-mcp",
3
3
  "description": "A Model Context Protocol for MySQL database interaction",
4
- "version": "1.43.2",
4
+ "version": "1.44.0",
5
5
  "tools": [
6
6
  {
7
7
  "name": "list_databases",
@@ -1383,7 +1383,7 @@
1383
1383
  },
1384
1384
  {
1385
1385
  "name": "cursor_execute_request",
1386
- "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\"}.",
1386
+ "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\"}.",
1387
1387
  "input_schema": {
1388
1388
  "type": "object",
1389
1389
  "properties": {}
@@ -1517,7 +1517,7 @@
1517
1517
  },
1518
1518
  {
1519
1519
  "name": "execute_in_transaction",
1520
- "description": "Executes a SQL query within an existing transaction context. The query becomes part of the transaction and will be committed or rolled back with it. Use after begin_transaction.",
1520
+ "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.",
1521
1521
  "input_schema": {
1522
1522
  "type": "object",
1523
1523
  "properties": {
@@ -1726,7 +1726,7 @@
1726
1726
  },
1727
1727
  {
1728
1728
  "name": "export_table_to_csv",
1729
- "description": "📄 Exports table data to CSV format with filtering, pagination, and sorting. For sensitive data, use safe_export_table instead which includes automatic data masking.",
1729
+ "description": "📄 Exports table data to CSV format with filtering, pagination, and sorting. Requires both utility and read permissions.",
1730
1730
  "input_schema": {
1731
1731
  "type": "object",
1732
1732
  "properties": {
@@ -1811,7 +1811,7 @@
1811
1811
  },
1812
1812
  {
1813
1813
  "name": "export_query_to_csv",
1814
- "description": "📄 Executes a SELECT query and exports results to CSV format. Supports complex queries with JOINs and aggregations. For sensitive data, consider using safe_export_table or adding manual data masking.",
1814
+ "description": "📄 Executes a SELECT query and exports results to CSV format. Requires both utility and read permissions. Supports complex queries with JOINs and aggregations.",
1815
1815
  "input_schema": {
1816
1816
  "type": "object",
1817
1817
  "properties": {
package/package.json CHANGED
@@ -1,78 +1,86 @@
1
- {
2
- "name": "@berthojoris/mcp-mysql-server",
3
- "version": "1.43.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
- "build": "tsc",
13
- "start": "node dist/mcp-server.js",
14
- "dev": "ts-node src/mcp-server.ts",
15
- "test": "jest --passWithNoTests",
16
- "lint": "eslint src/**/*.ts --quiet",
17
- "prepare": "npm run build",
18
- "prepublishOnly": "npm run build"
19
- },
20
- "keywords": [
21
- "mcp",
22
- "mysql",
23
- "database",
24
- "llm",
25
- "ai",
26
- "model-context-protocol",
27
- "claude",
28
- "cline",
29
- "windsurf",
30
- "codex",
31
- "openai-codex",
32
- "agent",
33
- "database-tools",
34
- "sql",
35
- "mysql-client",
36
- "ai-tools"
37
- ],
38
- "author": "Bertho Joris <berthojoris@gmail.com>",
39
- "license": "MIT",
40
- "repository": {
41
- "type": "git",
42
- "url": "git+https://github.com/berthojoris/mysql-mcp.git"
43
- },
44
- "bugs": {
45
- "url": "https://github.com/berthojoris/mysql-mcp/issues"
46
- },
47
- "homepage": "https://github.com/berthojoris/mysql-mcp#readme",
48
- "files": [
49
- "dist",
50
- "bin",
51
- "README.md",
52
- "DOCUMENTATIONS.md",
53
- "CHANGELOG.md",
54
- "LICENSE",
55
- "manifest.json"
56
- ],
57
- "engines": {
58
- "node": ">=18.0.0"
59
- },
60
- "dependencies": {
61
- "@modelcontextprotocol/sdk": "^1.20.0",
62
- "ajv": "^8.12.0",
63
- "ajv-formats": "^3.0.1",
64
- "dotenv": "^16.3.1",
65
- "mysql2": "^3.6.1"
66
- },
67
- "devDependencies": {
68
- "@types/jest": "^29.5.4",
69
- "@types/node": "^20.6.0",
70
- "@typescript-eslint/eslint-plugin": "^8.50.1",
71
- "@typescript-eslint/parser": "^8.50.1",
72
- "eslint": "^9.39.2",
73
- "jest": "^29.6.4",
74
- "ts-jest": "^29.1.1",
75
- "ts-node": "^10.9.1",
76
- "typescript": "^5.2.2"
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;
@@ -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
- }
@@ -1,70 +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.BackupRestoreTools = void 0;
7
- const connection_1 = __importDefault(require("../db/connection"));
8
- const config_1 = require("../config/config");
9
- /**
10
- * Backup and Restore Tools for MySQL MCP Server
11
- * Provides database backup (SQL dump generation) and restore functionality
12
- */
13
- class BackupRestoreTools {
14
- constructor(security) {
15
- this.db = connection_1.default.getInstance();
16
- this.security = security;
17
- }
18
- /**
19
- * Validate database access
20
- */
21
- validateDatabaseAccess(requestedDatabase) {
22
- const connectedDatabase = config_1.dbConfig.database;
23
- if (!connectedDatabase) {
24
- return {
25
- valid: false,
26
- database: "",
27
- error: "No database configured. Please specify a database in your connection settings.",
28
- };
29
- }
30
- if (requestedDatabase && requestedDatabase !== connectedDatabase) {
31
- return {
32
- valid: false,
33
- database: "",
34
- error: `Access denied: You are connected to '${connectedDatabase}' but requested '${requestedDatabase}'. Cross-database access is not permitted.`,
35
- };
36
- }
37
- return {
38
- valid: true,
39
- database: connectedDatabase,
40
- };
41
- }
42
- /**
43
- * Escape string value for SQL
44
- */
45
- escapeValue(value) {
46
- if (value === null)
47
- return "NULL";
48
- if (typeof value === "number")
49
- return String(value);
50
- if (typeof value === "boolean")
51
- return value ? "1" : "0";
52
- if (value instanceof Date) {
53
- return `'${value.toISOString().slice(0, 19).replace("T", " ")}'`;
54
- }
55
- if (Buffer.isBuffer(value)) {
56
- return `X'${value.toString("hex")}'`;
57
- }
58
- // Escape string
59
- const escaped = String(value)
60
- .replace(/\\/g, "\\\\")
61
- .replace(/'/g, "\\'")
62
- .replace(/"/g, '\\"')
63
- .replace(/\n/g, "\\n")
64
- .replace(/\r/g, "\\r")
65
- .replace(/\t/g, "\\t")
66
- .replace(/\0/g, "\\0");
67
- return `'${escaped}'`;
68
- }
69
- }
70
- exports.BackupRestoreTools = BackupRestoreTools;