@berthojoris/mcp-mysql-server 1.10.2 → 1.10.4

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 (44) hide show
  1. package/CHANGELOG.md +25 -7
  2. package/DOCUMENTATIONS.md +2 -2
  3. package/README.md +1 -1
  4. package/dist/index.d.ts +0 -99
  5. package/dist/mcp-server.js +0 -21
  6. package/dist/tools/backupRestoreTools.d.ts +1 -6
  7. package/dist/tools/backupRestoreTools.js +99 -97
  8. package/dist/tools/constraintTools.d.ts +4 -11
  9. package/dist/tools/constraintTools.js +114 -115
  10. package/dist/tools/crudTools.d.ts +2 -6
  11. package/dist/tools/crudTools.js +186 -189
  12. package/dist/tools/dataExportTools.d.ts +0 -7
  13. package/dist/tools/dataExportTools.js +0 -15
  14. package/dist/tools/databaseTools.d.ts +1 -4
  15. package/dist/tools/databaseTools.js +29 -33
  16. package/dist/tools/ddlTools.d.ts +1 -5
  17. package/dist/tools/ddlTools.js +68 -53
  18. package/dist/tools/functionTools.d.ts +3 -9
  19. package/dist/tools/functionTools.js +111 -104
  20. package/dist/tools/indexTools.d.ts +3 -8
  21. package/dist/tools/indexTools.js +99 -95
  22. package/dist/tools/maintenanceTools.d.ts +2 -10
  23. package/dist/tools/maintenanceTools.js +66 -80
  24. package/dist/tools/migrationTools.d.ts +0 -5
  25. package/dist/tools/migrationTools.js +56 -24
  26. package/dist/tools/performanceTools.d.ts +1 -11
  27. package/dist/tools/performanceTools.js +278 -267
  28. package/dist/tools/processTools.d.ts +4 -13
  29. package/dist/tools/processTools.js +78 -80
  30. package/dist/tools/queryTools.d.ts +0 -2
  31. package/dist/tools/queryTools.js +0 -4
  32. package/dist/tools/schemaVersioningTools.d.ts +0 -9
  33. package/dist/tools/schemaVersioningTools.js +167 -166
  34. package/dist/tools/storedProcedureTools.d.ts +2 -4
  35. package/dist/tools/storedProcedureTools.js +143 -134
  36. package/dist/tools/transactionTools.d.ts +2 -3
  37. package/dist/tools/transactionTools.js +28 -29
  38. package/dist/tools/triggerTools.d.ts +3 -8
  39. package/dist/tools/triggerTools.js +98 -85
  40. package/dist/tools/utilityTools.d.ts +0 -1
  41. package/dist/tools/utilityTools.js +0 -2
  42. package/dist/tools/viewTools.d.ts +7 -13
  43. package/dist/tools/viewTools.js +100 -93
  44. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { SecurityLayer } from '../security/securityLayer';
1
+ import { SecurityLayer } from "../security/securityLayer";
2
2
  export declare class ProcessTools {
3
3
  private db;
4
4
  private security;
@@ -12,19 +12,17 @@ export declare class ProcessTools {
12
12
  status: string;
13
13
  data?: any[];
14
14
  error?: string;
15
- queryLog?: string;
16
15
  }>;
17
16
  /**
18
17
  * Kill a specific process/connection
19
18
  */
20
19
  killProcess(params: {
21
20
  process_id: number;
22
- type?: 'CONNECTION' | 'QUERY';
21
+ type?: "CONNECTION" | "QUERY";
23
22
  }): Promise<{
24
23
  status: string;
25
24
  message?: string;
26
25
  error?: string;
27
- queryLog?: string;
28
26
  }>;
29
27
  /**
30
28
  * Show server status variables
@@ -36,7 +34,6 @@ export declare class ProcessTools {
36
34
  status: string;
37
35
  data?: any;
38
36
  error?: string;
39
- queryLog?: string;
40
37
  }>;
41
38
  /**
42
39
  * Show server variables
@@ -48,20 +45,18 @@ export declare class ProcessTools {
48
45
  status: string;
49
46
  data?: any;
50
47
  error?: string;
51
- queryLog?: string;
52
48
  }>;
53
49
  /**
54
50
  * Explain a query (show execution plan)
55
51
  */
56
52
  explainQuery(params: {
57
53
  query: string;
58
- format?: 'TRADITIONAL' | 'JSON' | 'TREE';
54
+ format?: "TRADITIONAL" | "JSON" | "TREE";
59
55
  analyze?: boolean;
60
56
  }): Promise<{
61
57
  status: string;
62
58
  data?: any;
63
59
  error?: string;
64
- queryLog?: string;
65
60
  }>;
66
61
  /**
67
62
  * Show engine status (InnoDB, etc.)
@@ -72,7 +67,6 @@ export declare class ProcessTools {
72
67
  status: string;
73
68
  data?: any;
74
69
  error?: string;
75
- queryLog?: string;
76
70
  }>;
77
71
  /**
78
72
  * Get server information
@@ -81,7 +75,6 @@ export declare class ProcessTools {
81
75
  status: string;
82
76
  data?: any;
83
77
  error?: string;
84
- queryLog?: string;
85
78
  }>;
86
79
  /**
87
80
  * Show binary logs
@@ -90,17 +83,15 @@ export declare class ProcessTools {
90
83
  status: string;
91
84
  data?: any[];
92
85
  error?: string;
93
- queryLog?: string;
94
86
  }>;
95
87
  /**
96
88
  * Show master/replica status
97
89
  */
98
90
  showReplicationStatus(params?: {
99
- type?: 'MASTER' | 'REPLICA' | 'SLAVE';
91
+ type?: "MASTER" | "REPLICA" | "SLAVE";
100
92
  }): Promise<{
101
93
  status: string;
102
94
  data?: any;
103
95
  error?: string;
104
- queryLog?: string;
105
96
  }>;
106
97
  }
@@ -15,10 +15,10 @@ class ProcessTools {
15
15
  */
16
16
  async showProcessList(params) {
17
17
  try {
18
- const query = params?.full ? 'SHOW FULL PROCESSLIST' : 'SHOW PROCESSLIST';
18
+ const query = params?.full ? "SHOW FULL PROCESSLIST" : "SHOW PROCESSLIST";
19
19
  const results = await this.db.query(query);
20
20
  // Format results for better readability
21
- const formattedResults = results.map(row => ({
21
+ const formattedResults = results.map((row) => ({
22
22
  id: row.Id,
23
23
  user: row.User,
24
24
  host: row.Host,
@@ -27,19 +27,17 @@ class ProcessTools {
27
27
  time: row.Time,
28
28
  state: row.State,
29
29
  info: row.Info,
30
- progress: row.Progress
30
+ progress: row.Progress,
31
31
  }));
32
32
  return {
33
- status: 'success',
33
+ status: "success",
34
34
  data: formattedResults,
35
- queryLog: this.db.getFormattedQueryLogs(1)
36
35
  };
37
36
  }
38
37
  catch (error) {
39
38
  return {
40
- status: 'error',
39
+ status: "error",
41
40
  error: error.message,
42
- queryLog: this.db.getFormattedQueryLogs(1)
43
41
  };
44
42
  }
45
43
  }
@@ -48,28 +46,27 @@ class ProcessTools {
48
46
  */
49
47
  async killProcess(params) {
50
48
  try {
51
- const { process_id, type = 'CONNECTION' } = params;
49
+ const { process_id, type = "CONNECTION" } = params;
52
50
  // Validate process_id is a positive integer
53
51
  if (!Number.isInteger(process_id) || process_id <= 0) {
54
- return { status: 'error', error: 'Process ID must be a positive integer' };
52
+ return {
53
+ status: "error",
54
+ error: "Process ID must be a positive integer",
55
+ };
55
56
  }
56
- const query = type === 'QUERY'
57
- ? `KILL QUERY ${process_id}`
58
- : `KILL ${process_id}`;
57
+ const query = type === "QUERY" ? `KILL QUERY ${process_id}` : `KILL ${process_id}`;
59
58
  await this.db.query(query);
60
59
  return {
61
- status: 'success',
62
- message: type === 'QUERY'
60
+ status: "success",
61
+ message: type === "QUERY"
63
62
  ? `Query for process ${process_id} killed successfully`
64
63
  : `Process ${process_id} killed successfully`,
65
- queryLog: this.db.getFormattedQueryLogs(1)
66
64
  };
67
65
  }
68
66
  catch (error) {
69
67
  return {
70
- status: 'error',
68
+ status: "error",
71
69
  error: error.message,
72
- queryLog: this.db.getFormattedQueryLogs(1)
73
70
  };
74
71
  }
75
72
  }
@@ -78,11 +75,11 @@ class ProcessTools {
78
75
  */
79
76
  async showStatus(params) {
80
77
  try {
81
- let query = params?.global ? 'SHOW GLOBAL STATUS' : 'SHOW STATUS';
78
+ let query = params?.global ? "SHOW GLOBAL STATUS" : "SHOW STATUS";
82
79
  if (params?.like) {
83
80
  // Validate the LIKE pattern (basic check)
84
- if (params.like.includes(';') || params.like.includes('--')) {
85
- return { status: 'error', error: 'Invalid pattern' };
81
+ if (params.like.includes(";") || params.like.includes("--")) {
82
+ return { status: "error", error: "Invalid pattern" };
86
83
  }
87
84
  query += ` LIKE '${params.like}'`;
88
85
  }
@@ -93,19 +90,19 @@ class ProcessTools {
93
90
  statusObj[row.Variable_name] = row.Value;
94
91
  }
95
92
  return {
96
- status: 'success',
97
- data: params?.like ? statusObj : {
98
- variables: statusObj,
99
- count: results.length
100
- },
101
- queryLog: this.db.getFormattedQueryLogs(1)
93
+ status: "success",
94
+ data: params?.like
95
+ ? statusObj
96
+ : {
97
+ variables: statusObj,
98
+ count: results.length,
99
+ },
102
100
  };
103
101
  }
104
102
  catch (error) {
105
103
  return {
106
- status: 'error',
104
+ status: "error",
107
105
  error: error.message,
108
- queryLog: this.db.getFormattedQueryLogs(1)
109
106
  };
110
107
  }
111
108
  }
@@ -114,11 +111,11 @@ class ProcessTools {
114
111
  */
115
112
  async showVariables(params) {
116
113
  try {
117
- let query = params?.global ? 'SHOW GLOBAL VARIABLES' : 'SHOW VARIABLES';
114
+ let query = params?.global ? "SHOW GLOBAL VARIABLES" : "SHOW VARIABLES";
118
115
  if (params?.like) {
119
116
  // Validate the LIKE pattern (basic check)
120
- if (params.like.includes(';') || params.like.includes('--')) {
121
- return { status: 'error', error: 'Invalid pattern' };
117
+ if (params.like.includes(";") || params.like.includes("--")) {
118
+ return { status: "error", error: "Invalid pattern" };
122
119
  }
123
120
  query += ` LIKE '${params.like}'`;
124
121
  }
@@ -129,19 +126,19 @@ class ProcessTools {
129
126
  varsObj[row.Variable_name] = row.Value;
130
127
  }
131
128
  return {
132
- status: 'success',
133
- data: params?.like ? varsObj : {
134
- variables: varsObj,
135
- count: results.length
136
- },
137
- queryLog: this.db.getFormattedQueryLogs(1)
129
+ status: "success",
130
+ data: params?.like
131
+ ? varsObj
132
+ : {
133
+ variables: varsObj,
134
+ count: results.length,
135
+ },
138
136
  };
139
137
  }
140
138
  catch (error) {
141
139
  return {
142
- status: 'error',
140
+ status: "error",
143
141
  error: error.message,
144
- queryLog: this.db.getFormattedQueryLogs(1)
145
142
  };
146
143
  }
147
144
  }
@@ -150,32 +147,33 @@ class ProcessTools {
150
147
  */
151
148
  async explainQuery(params) {
152
149
  try {
153
- const { query, format = 'TRADITIONAL', analyze = false } = params;
150
+ const { query, format = "TRADITIONAL", analyze = false } = params;
154
151
  // Only allow SELECT, UPDATE, DELETE, INSERT queries to be explained
155
152
  const normalizedQuery = query.trim().toUpperCase();
156
- if (!normalizedQuery.startsWith('SELECT') &&
157
- !normalizedQuery.startsWith('UPDATE') &&
158
- !normalizedQuery.startsWith('DELETE') &&
159
- !normalizedQuery.startsWith('INSERT')) {
160
- return { status: 'error', error: 'EXPLAIN only supports SELECT, UPDATE, DELETE, and INSERT statements' };
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
161
  }
162
- let explainQuery = analyze ? 'EXPLAIN ANALYZE ' : 'EXPLAIN ';
163
- if (format !== 'TRADITIONAL') {
162
+ let explainQuery = analyze ? "EXPLAIN ANALYZE " : "EXPLAIN ";
163
+ if (format !== "TRADITIONAL") {
164
164
  explainQuery += `FORMAT=${format} `;
165
165
  }
166
166
  explainQuery += query;
167
167
  const results = await this.db.query(explainQuery);
168
168
  return {
169
- status: 'success',
170
- data: format === 'JSON' ? JSON.parse(results[0]['EXPLAIN']) : results,
171
- queryLog: this.db.getFormattedQueryLogs(1)
169
+ status: "success",
170
+ data: format === "JSON" ? JSON.parse(results[0]["EXPLAIN"]) : results,
172
171
  };
173
172
  }
174
173
  catch (error) {
175
174
  return {
176
- status: 'error',
175
+ status: "error",
177
176
  error: error.message,
178
- queryLog: this.db.getFormattedQueryLogs(1)
179
177
  };
180
178
  }
181
179
  }
@@ -184,25 +182,31 @@ class ProcessTools {
184
182
  */
185
183
  async showEngineStatus(params) {
186
184
  try {
187
- const engine = params?.engine || 'INNODB';
185
+ const engine = params?.engine || "INNODB";
188
186
  // Validate engine name
189
- const validEngines = ['INNODB', 'PERFORMANCE_SCHEMA', 'NDB', 'NDBCLUSTER'];
187
+ const validEngines = [
188
+ "INNODB",
189
+ "PERFORMANCE_SCHEMA",
190
+ "NDB",
191
+ "NDBCLUSTER",
192
+ ];
190
193
  if (!validEngines.includes(engine.toUpperCase())) {
191
- return { status: 'error', error: `Invalid engine. Supported: ${validEngines.join(', ')}` };
194
+ return {
195
+ status: "error",
196
+ error: `Invalid engine. Supported: ${validEngines.join(", ")}`,
197
+ };
192
198
  }
193
199
  const query = `SHOW ENGINE ${engine.toUpperCase()} STATUS`;
194
200
  const results = await this.db.query(query);
195
201
  return {
196
- status: 'success',
202
+ status: "success",
197
203
  data: results,
198
- queryLog: this.db.getFormattedQueryLogs(1)
199
204
  };
200
205
  }
201
206
  catch (error) {
202
207
  return {
203
- status: 'error',
208
+ status: "error",
204
209
  error: error.message,
205
- queryLog: this.db.getFormattedQueryLogs(1)
206
210
  };
207
211
  }
208
212
  }
@@ -213,10 +217,10 @@ class ProcessTools {
213
217
  try {
214
218
  // Get various server info
215
219
  const queries = [
216
- { key: 'version', query: 'SELECT VERSION() as value' },
217
- { key: 'connection_id', query: 'SELECT CONNECTION_ID() as value' },
218
- { key: 'current_user', query: 'SELECT CURRENT_USER() as value' },
219
- { key: 'database', query: 'SELECT DATABASE() as value' }
220
+ { key: "version", query: "SELECT VERSION() as value" },
221
+ { key: "connection_id", query: "SELECT CONNECTION_ID() as value" },
222
+ { key: "current_user", query: "SELECT CURRENT_USER() as value" },
223
+ { key: "database", query: "SELECT DATABASE() as value" },
220
224
  ];
221
225
  const info = {};
222
226
  for (const q of queries) {
@@ -238,16 +242,14 @@ class ProcessTools {
238
242
  info.uptime_formatted = `${days}d ${hours}h ${minutes}m`;
239
243
  }
240
244
  return {
241
- status: 'success',
245
+ status: "success",
242
246
  data: info,
243
- queryLog: this.db.getFormattedQueryLogs(queries.length + 1)
244
247
  };
245
248
  }
246
249
  catch (error) {
247
250
  return {
248
- status: 'error',
251
+ status: "error",
249
252
  error: error.message,
250
- queryLog: this.db.getFormattedQueryLogs(1)
251
253
  };
252
254
  }
253
255
  }
@@ -256,19 +258,17 @@ class ProcessTools {
256
258
  */
257
259
  async showBinaryLogs() {
258
260
  try {
259
- const query = 'SHOW BINARY LOGS';
261
+ const query = "SHOW BINARY LOGS";
260
262
  const results = await this.db.query(query);
261
263
  return {
262
- status: 'success',
264
+ status: "success",
263
265
  data: results,
264
- queryLog: this.db.getFormattedQueryLogs(1)
265
266
  };
266
267
  }
267
268
  catch (error) {
268
269
  return {
269
- status: 'error',
270
+ status: "error",
270
271
  error: error.message,
271
- queryLog: this.db.getFormattedQueryLogs(1)
272
272
  };
273
273
  }
274
274
  }
@@ -277,27 +277,25 @@ class ProcessTools {
277
277
  */
278
278
  async showReplicationStatus(params) {
279
279
  try {
280
- const type = params?.type || 'REPLICA';
280
+ const type = params?.type || "REPLICA";
281
281
  let query;
282
- if (type === 'MASTER') {
283
- query = 'SHOW MASTER STATUS';
282
+ if (type === "MASTER") {
283
+ query = "SHOW MASTER STATUS";
284
284
  }
285
285
  else {
286
286
  // MySQL 8.0.22+ uses REPLICA, older versions use SLAVE
287
- query = type === 'SLAVE' ? 'SHOW SLAVE STATUS' : 'SHOW REPLICA STATUS';
287
+ query = type === "SLAVE" ? "SHOW SLAVE STATUS" : "SHOW REPLICA STATUS";
288
288
  }
289
289
  const results = await this.db.query(query);
290
290
  return {
291
- status: 'success',
291
+ status: "success",
292
292
  data: results.length > 0 ? results[0] : null,
293
- queryLog: this.db.getFormattedQueryLogs(1)
294
293
  };
295
294
  }
296
295
  catch (error) {
297
296
  return {
298
- status: 'error',
297
+ status: "error",
299
298
  error: error.message,
300
- queryLog: this.db.getFormattedQueryLogs(1)
301
299
  };
302
300
  }
303
301
  }
@@ -17,7 +17,6 @@ export declare class QueryTools {
17
17
  status: string;
18
18
  data?: any[];
19
19
  error?: string;
20
- queryLog?: string;
21
20
  optimizedQuery?: string;
22
21
  }>;
23
22
  /**
@@ -39,6 +38,5 @@ export declare class QueryTools {
39
38
  status: string;
40
39
  data?: any;
41
40
  error?: string;
42
- queryLog?: string;
43
41
  }>;
44
42
  }
@@ -66,7 +66,6 @@ class QueryTools {
66
66
  return {
67
67
  status: "success",
68
68
  data: results,
69
- queryLog: this.db.getFormattedQueryLogs(1),
70
69
  optimizedQuery,
71
70
  };
72
71
  }
@@ -74,7 +73,6 @@ class QueryTools {
74
73
  return {
75
74
  status: "error",
76
75
  error: error.message,
77
- queryLog: this.db.getFormattedQueryLogs(1),
78
76
  };
79
77
  }
80
78
  }
@@ -136,14 +134,12 @@ class QueryTools {
136
134
  affectedRows: result.affectedRows || 0,
137
135
  insertId: result.insertId || null,
138
136
  },
139
- queryLog: this.db.getFormattedQueryLogs(1),
140
137
  };
141
138
  }
142
139
  catch (error) {
143
140
  return {
144
141
  status: "error",
145
142
  error: error.message,
146
- queryLog: this.db.getFormattedQueryLogs(1),
147
143
  };
148
144
  }
149
145
  }
@@ -29,7 +29,6 @@ export declare class SchemaVersioningTools {
29
29
  status: string;
30
30
  data?: any;
31
31
  error?: string;
32
- queryLog?: string;
33
32
  }>;
34
33
  /**
35
34
  * Create a new migration entry
@@ -45,7 +44,6 @@ export declare class SchemaVersioningTools {
45
44
  status: string;
46
45
  data?: any;
47
46
  error?: string;
48
- queryLog?: string;
49
47
  }>;
50
48
  /**
51
49
  * Generate a simple checksum for SQL content
@@ -62,7 +60,6 @@ export declare class SchemaVersioningTools {
62
60
  status: string;
63
61
  data?: any;
64
62
  error?: string;
65
- queryLog?: string;
66
63
  }>;
67
64
  /**
68
65
  * Split SQL content into individual statements
@@ -80,7 +77,6 @@ export declare class SchemaVersioningTools {
80
77
  status: string;
81
78
  data?: any;
82
79
  error?: string;
83
- queryLog?: string;
84
80
  }>;
85
81
  /**
86
82
  * Get migration history and status
@@ -94,7 +90,6 @@ export declare class SchemaVersioningTools {
94
90
  status: string;
95
91
  data?: any;
96
92
  error?: string;
97
- queryLog?: string;
98
93
  }>;
99
94
  /**
100
95
  * Get the current schema version
@@ -105,7 +100,6 @@ export declare class SchemaVersioningTools {
105
100
  status: string;
106
101
  data?: any;
107
102
  error?: string;
108
- queryLog?: string;
109
103
  }>;
110
104
  /**
111
105
  * Validate pending migrations (check for conflicts or issues)
@@ -116,7 +110,6 @@ export declare class SchemaVersioningTools {
116
110
  status: string;
117
111
  data?: any;
118
112
  error?: string;
119
- queryLog?: string;
120
113
  }>;
121
114
  /**
122
115
  * Mark a failed migration as resolved (reset to pending status)
@@ -128,7 +121,6 @@ export declare class SchemaVersioningTools {
128
121
  status: string;
129
122
  data?: any;
130
123
  error?: string;
131
- queryLog?: string;
132
124
  }>;
133
125
  /**
134
126
  * Generate a migration from table comparison
@@ -142,6 +134,5 @@ export declare class SchemaVersioningTools {
142
134
  status: string;
143
135
  data?: any;
144
136
  error?: string;
145
- queryLog?: string;
146
137
  }>;
147
138
  }