@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.
Files changed (50) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/DOCUMENTATIONS.md +19 -3
  3. package/README.md +7 -1
  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 +11 -13
  9. package/dist/db/connection.d.ts +8 -1
  10. package/dist/db/connection.js +19 -14
  11. package/dist/mcp-server.js +30 -302
  12. package/dist/security/securityLayer.d.ts +21 -2
  13. package/dist/security/securityLayer.js +151 -21
  14. package/dist/tools/toolArgumentValidation.js +22 -22
  15. package/dist/tools/toolRegistry.d.ts +1 -1
  16. package/dist/tools/toolRegistry.js +7 -1
  17. package/manifest.json +1 -1
  18. package/package.json +86 -78
  19. package/dist/auth/authService.d.ts +0 -29
  20. package/dist/auth/authService.js +0 -114
  21. package/dist/tools/backupRestoreTools.d.ts +0 -18
  22. package/dist/tools/backupRestoreTools.js +0 -70
  23. package/dist/tools/documentationGeneratorTools.d.ts +0 -145
  24. package/dist/tools/documentationGeneratorTools.js +0 -820
  25. package/dist/tools/forecastingTools.d.ts +0 -36
  26. package/dist/tools/forecastingTools.js +0 -256
  27. package/dist/tools/functionTools.d.ts +0 -87
  28. package/dist/tools/functionTools.js +0 -358
  29. package/dist/tools/indexRecommendationTools.d.ts +0 -50
  30. package/dist/tools/indexRecommendationTools.js +0 -451
  31. package/dist/tools/intelligentQueryTools.d.ts +0 -94
  32. package/dist/tools/intelligentQueryTools.js +0 -713
  33. package/dist/tools/performanceTools.d.ts +0 -76
  34. package/dist/tools/performanceTools.js +0 -505
  35. package/dist/tools/processTools.d.ts +0 -61
  36. package/dist/tools/processTools.js +0 -181
  37. package/dist/tools/queryVisualizationTools.d.ts +0 -22
  38. package/dist/tools/queryVisualizationTools.js +0 -155
  39. package/dist/tools/schemaDesignTools.d.ts +0 -67
  40. package/dist/tools/schemaDesignTools.js +0 -359
  41. package/dist/tools/schemaPatternTools.d.ts +0 -19
  42. package/dist/tools/schemaPatternTools.js +0 -253
  43. package/dist/tools/schemaVersioningTools.d.ts +0 -138
  44. package/dist/tools/schemaVersioningTools.js +0 -1008
  45. package/dist/tools/securityAuditTools.d.ts +0 -39
  46. package/dist/tools/securityAuditTools.js +0 -319
  47. package/dist/tools/smartDiscoveryTools.d.ts +0 -163
  48. package/dist/tools/smartDiscoveryTools.js +0 -750
  49. package/dist/tools/testDataTools.d.ts +0 -26
  50. package/dist/tools/testDataTools.js +0 -325
@@ -1,181 +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.ProcessTools = void 0;
7
- const connection_1 = __importDefault(require("../db/connection"));
8
- class ProcessTools {
9
- constructor(security) {
10
- this.db = connection_1.default.getInstance();
11
- this.security = security;
12
- }
13
- /**
14
- * Show all running processes/connections
15
- */
16
- async showProcessList(params) {
17
- try {
18
- const query = params?.full ? "SHOW FULL PROCESSLIST" : "SHOW PROCESSLIST";
19
- const results = await this.db.query(query);
20
- // Format results for better readability
21
- const formattedResults = results.map((row) => ({
22
- id: row.Id,
23
- user: row.User,
24
- host: row.Host,
25
- database: row.db,
26
- command: row.Command,
27
- time: row.Time,
28
- state: row.State,
29
- info: row.Info,
30
- progress: row.Progress,
31
- }));
32
- return {
33
- status: "success",
34
- data: formattedResults,
35
- };
36
- }
37
- catch (error) {
38
- return {
39
- status: "error",
40
- error: error.message,
41
- };
42
- }
43
- }
44
- /**
45
- * Kill a specific process/connection
46
- */
47
- async killProcess(params) {
48
- try {
49
- const { process_id, type = "CONNECTION" } = params;
50
- // Validate process_id is a positive integer
51
- if (!Number.isInteger(process_id) || process_id <= 0) {
52
- return {
53
- status: "error",
54
- error: "Process ID must be a positive integer",
55
- };
56
- }
57
- const query = type === "QUERY" ? `KILL QUERY ${process_id}` : `KILL ${process_id}`;
58
- await this.db.query(query);
59
- return {
60
- status: "success",
61
- message: type === "QUERY"
62
- ? `Query for process ${process_id} killed successfully`
63
- : `Process ${process_id} killed successfully`,
64
- };
65
- }
66
- catch (error) {
67
- return {
68
- status: "error",
69
- error: error.message,
70
- };
71
- }
72
- }
73
- /**
74
- * Show server status variables
75
- */
76
- async showStatus(params) {
77
- try {
78
- let query = params?.global ? "SHOW GLOBAL STATUS" : "SHOW STATUS";
79
- if (params?.like) {
80
- // Validate the LIKE pattern (basic check)
81
- if (params.like.includes(";") || params.like.includes("--")) {
82
- return { status: "error", error: "Invalid pattern" };
83
- }
84
- query += ` LIKE '${params.like}'`;
85
- }
86
- const results = await this.db.query(query);
87
- // Convert to object for easier access
88
- const statusObj = {};
89
- for (const row of results) {
90
- statusObj[row.Variable_name] = row.Value;
91
- }
92
- return {
93
- status: "success",
94
- data: params?.like
95
- ? statusObj
96
- : {
97
- variables: statusObj,
98
- count: results.length,
99
- },
100
- };
101
- }
102
- catch (error) {
103
- return {
104
- status: "error",
105
- error: error.message,
106
- };
107
- }
108
- }
109
- /**
110
- * Show server variables
111
- */
112
- async showVariables(params) {
113
- try {
114
- let query = params?.global ? "SHOW GLOBAL VARIABLES" : "SHOW VARIABLES";
115
- if (params?.like) {
116
- // Validate the LIKE pattern (basic check)
117
- if (params.like.includes(";") || params.like.includes("--")) {
118
- return { status: "error", error: "Invalid pattern" };
119
- }
120
- query += ` LIKE '${params.like}'`;
121
- }
122
- const results = await this.db.query(query);
123
- // Convert to object for easier access
124
- const varsObj = {};
125
- for (const row of results) {
126
- varsObj[row.Variable_name] = row.Value;
127
- }
128
- return {
129
- status: "success",
130
- data: params?.like
131
- ? varsObj
132
- : {
133
- variables: varsObj,
134
- count: results.length,
135
- },
136
- };
137
- }
138
- catch (error) {
139
- return {
140
- status: "error",
141
- error: error.message,
142
- };
143
- }
144
- }
145
- /**
146
- * Explain a query (show execution plan)
147
- */
148
- async explainQuery(params) {
149
- try {
150
- const { query, format = "TRADITIONAL", analyze = false } = params;
151
- // Only allow SELECT, UPDATE, DELETE, INSERT queries to be explained
152
- const normalizedQuery = query.trim().toUpperCase();
153
- if (!normalizedQuery.startsWith("SELECT") &&
154
- !normalizedQuery.startsWith("UPDATE") &&
155
- !normalizedQuery.startsWith("DELETE") &&
156
- !normalizedQuery.startsWith("INSERT")) {
157
- return {
158
- status: "error",
159
- error: "EXPLAIN only supports SELECT, UPDATE, DELETE, and INSERT statements",
160
- };
161
- }
162
- let explainQuery = analyze ? "EXPLAIN ANALYZE " : "EXPLAIN ";
163
- if (format !== "TRADITIONAL") {
164
- explainQuery += `FORMAT=${format} `;
165
- }
166
- explainQuery += query;
167
- const results = await this.db.query(explainQuery);
168
- return {
169
- status: "success",
170
- data: format === "JSON" ? JSON.parse(results[0]["EXPLAIN"]) : results,
171
- };
172
- }
173
- catch (error) {
174
- return {
175
- status: "error",
176
- error: error.message,
177
- };
178
- }
179
- }
180
- }
181
- exports.ProcessTools = ProcessTools;
@@ -1,22 +0,0 @@
1
- import { SecurityLayer } from "../security/securityLayer";
2
- export declare class QueryVisualizationTools {
3
- private db;
4
- private security;
5
- constructor(security: SecurityLayer);
6
- private extractExplainNodes;
7
- private sqlJoinEdges;
8
- private buildMermaid;
9
- /**
10
- * Create a lightweight visual representation of a SQL query.
11
- * Returns Mermaid flowchart + EXPLAIN FORMAT=JSON summary.
12
- */
13
- visualizeQuery(params: {
14
- query: string;
15
- include_explain_json?: boolean;
16
- format?: "mermaid" | "json" | "both";
17
- }): Promise<{
18
- status: string;
19
- data?: any;
20
- error?: string;
21
- }>;
22
- }
@@ -1,155 +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.QueryVisualizationTools = void 0;
7
- const connection_1 = __importDefault(require("../db/connection"));
8
- class QueryVisualizationTools {
9
- constructor(security) {
10
- this.db = connection_1.default.getInstance();
11
- this.security = security;
12
- }
13
- extractExplainNodes(explainJson) {
14
- const nodes = [];
15
- const visit = (obj) => {
16
- if (!obj || typeof obj !== "object")
17
- return;
18
- if (obj.table && typeof obj.table === "object") {
19
- const t = obj.table;
20
- nodes.push({
21
- table_name: t.table_name,
22
- access_type: t.access_type,
23
- possible_keys: t.possible_keys,
24
- key: t.key,
25
- rows_examined_per_scan: t.rows_examined_per_scan,
26
- rows_produced_per_join: t.rows_produced_per_join,
27
- filtered: t.filtered,
28
- attached_condition: t.attached_condition,
29
- });
30
- }
31
- for (const v of Object.values(obj)) {
32
- if (Array.isArray(v))
33
- v.forEach(visit);
34
- else if (v && typeof v === "object")
35
- visit(v);
36
- }
37
- };
38
- visit(explainJson);
39
- return nodes;
40
- }
41
- sqlJoinEdges(query) {
42
- const edges = [];
43
- const q = query.replace(/\s+/g, " ");
44
- // Very lightweight parser: FROM <t> ... JOIN <t2> ON <cond>
45
- const fromMatch = q.match(/\bFROM\s+([`"']?\w+[`"']?)(?:\s+AS\s+\w+|\s+\w+)?/i);
46
- const base = fromMatch ? fromMatch[1].replace(/[`"']/g, "") : undefined;
47
- if (!base)
48
- return edges;
49
- const joinRegex = /\bJOIN\s+([`"']?\w+[`"']?)(?:\s+AS\s+\w+|\s+\w+)?\s+ON\s+(.+?)(?=\bJOIN\b|\bWHERE\b|\bGROUP\b|\bORDER\b|\bLIMIT\b|$)/gi;
50
- let m;
51
- let prev = base;
52
- while ((m = joinRegex.exec(q))) {
53
- const table = m[1].replace(/[`"']/g, "");
54
- const on = m[2].trim();
55
- edges.push({ from: prev, to: table, on });
56
- prev = table;
57
- }
58
- return edges;
59
- }
60
- buildMermaid(nodes, edges) {
61
- const lines = [];
62
- lines.push("graph TD");
63
- const uniqTables = Array.from(new Set(nodes.map((n) => n.table_name).filter(Boolean)));
64
- const nodeId = (t) => `t_${t.replace(/[^a-zA-Z0-9_]/g, "_")}`;
65
- for (const t of uniqTables) {
66
- const n = nodes.find((x) => x.table_name === t);
67
- const labelParts = [t];
68
- if (n?.access_type)
69
- labelParts.push(`access=${n.access_type}`);
70
- if (n?.key)
71
- labelParts.push(`key=${n.key}`);
72
- if (typeof n?.rows_examined_per_scan === "number") {
73
- labelParts.push(`rows≈${n.rows_examined_per_scan}`);
74
- }
75
- lines.push(`${nodeId(t)}["${labelParts.join("\\n")}"]`);
76
- }
77
- if (edges.length) {
78
- for (const e of edges) {
79
- lines.push(`${nodeId(e.from)} -->|"${(e.on || "").replace(/"/g, "'").slice(0, 60)}"| ${nodeId(e.to)}`);
80
- }
81
- return lines.join("\n");
82
- }
83
- // Fallback: join order from EXPLAIN
84
- for (let i = 0; i < uniqTables.length - 1; i++) {
85
- lines.push(`${nodeId(uniqTables[i])} --> ${nodeId(uniqTables[i + 1])}`);
86
- }
87
- return lines.join("\n");
88
- }
89
- /**
90
- * Create a lightweight visual representation of a SQL query.
91
- * Returns Mermaid flowchart + EXPLAIN FORMAT=JSON summary.
92
- */
93
- async visualizeQuery(params) {
94
- try {
95
- const query = params.query;
96
- if (!query || typeof query !== "string") {
97
- return { status: "error", error: "query is required" };
98
- }
99
- if (!this.security.isReadOnlyQuery(query)) {
100
- return {
101
- status: "error",
102
- error: "Only read-only queries (SELECT/SHOW/DESCRIBE/EXPLAIN) are supported for visualization.",
103
- };
104
- }
105
- const includeExplain = params.include_explain_json ?? true;
106
- const format = params.format ?? "both";
107
- const explainQuery = `EXPLAIN FORMAT=JSON ${query}`;
108
- const explainRows = await this.db.query(explainQuery);
109
- let explainJson = null;
110
- let queryCost = null;
111
- if (explainRows[0] && explainRows[0].EXPLAIN) {
112
- try {
113
- explainJson = JSON.parse(explainRows[0].EXPLAIN);
114
- queryCost =
115
- explainJson?.query_block?.cost_info?.query_cost?.toString?.() ?? null;
116
- }
117
- catch {
118
- explainJson = explainRows;
119
- }
120
- }
121
- const nodes = explainJson ? this.extractExplainNodes(explainJson) : [];
122
- const edges = this.sqlJoinEdges(query);
123
- const mermaid = this.buildMermaid(nodes, edges);
124
- const data = {
125
- mermaid,
126
- explain_summary: {
127
- query_cost: queryCost,
128
- tables: nodes.map((n) => ({
129
- table_name: n.table_name,
130
- access_type: n.access_type,
131
- key: n.key,
132
- rows_examined_per_scan: n.rows_examined_per_scan,
133
- filtered: n.filtered,
134
- })),
135
- },
136
- };
137
- if (includeExplain)
138
- data.explain_json = explainJson;
139
- if (format === "mermaid") {
140
- return { status: "success", data: { mermaid } };
141
- }
142
- if (format === "json") {
143
- return {
144
- status: "success",
145
- data: { explain_summary: data.explain_summary, explain_json: explainJson },
146
- };
147
- }
148
- return { status: "success", data };
149
- }
150
- catch (error) {
151
- return { status: "error", error: error.message };
152
- }
153
- }
154
- }
155
- exports.QueryVisualizationTools = QueryVisualizationTools;
@@ -1,67 +0,0 @@
1
- import { SecurityLayer } from "../security/securityLayer";
2
- type NamingConvention = "snake_case" | "camelCase";
3
- export declare class SchemaDesignTools {
4
- private security;
5
- constructor(security: SecurityLayer);
6
- designSchemaFromRequirements(params: {
7
- requirements_text: string;
8
- entities?: Array<{
9
- name: string;
10
- fields?: string[];
11
- }>;
12
- naming_convention?: NamingConvention;
13
- include_audit_columns?: boolean;
14
- id_type?: "BIGINT" | "UUID";
15
- engine?: string;
16
- charset?: string;
17
- collation?: string;
18
- }): Promise<{
19
- status: string;
20
- data?: {
21
- input: {
22
- requirements_text: string;
23
- inferred_entities_count: number;
24
- };
25
- tables: Array<{
26
- table_name: string;
27
- columns: Array<{
28
- name: string;
29
- type: string;
30
- nullable: boolean;
31
- primary_key?: boolean;
32
- unique?: boolean;
33
- references?: {
34
- table: string;
35
- column: string;
36
- };
37
- }>;
38
- indexes: Array<{
39
- name: string;
40
- columns: string[];
41
- unique?: boolean;
42
- }>;
43
- }>;
44
- relationships: Array<{
45
- from_table: string;
46
- from_column: string;
47
- to_table: string;
48
- to_column: string;
49
- type: "one_to_many" | "many_to_one";
50
- }>;
51
- ddl_statements: string[];
52
- notes: string[];
53
- };
54
- error?: string;
55
- }>;
56
- private normalizeLoose;
57
- private toSnakeCase;
58
- private toCamelCase;
59
- private normalizeIdentifier;
60
- private inferColumnType;
61
- private extractEntitiesAndRelations;
62
- private findTableNameForRaw;
63
- private makeIndexName;
64
- private generateCreateTableDDL;
65
- private generateCreateIndexDDL;
66
- }
67
- export {};