@berthojoris/mcp-mysql-server 1.4.15 → 1.6.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/DOCUMENTATIONS.md +664 -22
- package/README.md +102 -5
- package/dist/cache/queryCache.d.ts +126 -0
- package/dist/cache/queryCache.js +337 -0
- package/dist/config/featureConfig.js +82 -71
- package/dist/db/connection.d.ts +21 -2
- package/dist/db/connection.js +73 -7
- package/dist/db/queryLogger.d.ts +3 -2
- package/dist/db/queryLogger.js +64 -43
- package/dist/index.d.ts +477 -3
- package/dist/index.js +472 -70
- package/dist/mcp-server.js +1352 -124
- package/dist/optimization/queryOptimizer.d.ts +125 -0
- package/dist/optimization/queryOptimizer.js +509 -0
- package/dist/tools/constraintTools.d.ts +108 -0
- package/dist/tools/constraintTools.js +405 -0
- package/dist/tools/functionTools.d.ts +93 -0
- package/dist/tools/functionTools.js +351 -0
- package/dist/tools/indexTools.d.ts +81 -0
- package/dist/tools/indexTools.js +345 -0
- package/dist/tools/maintenanceTools.d.ts +111 -0
- package/dist/tools/maintenanceTools.js +371 -0
- package/dist/tools/processTools.d.ts +106 -0
- package/dist/tools/processTools.js +305 -0
- package/dist/tools/queryTools.d.ts +14 -1
- package/dist/tools/queryTools.js +27 -3
- package/dist/tools/triggerTools.d.ts +76 -0
- package/dist/tools/triggerTools.js +294 -0
- package/dist/tools/viewTools.d.ts +91 -0
- package/dist/tools/viewTools.js +330 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,6 +12,13 @@ const ddlTools_1 = require("./tools/ddlTools");
|
|
|
12
12
|
const transactionTools_1 = require("./tools/transactionTools");
|
|
13
13
|
const storedProcedureTools_1 = require("./tools/storedProcedureTools");
|
|
14
14
|
const dataExportTools_1 = require("./tools/dataExportTools");
|
|
15
|
+
const viewTools_1 = require("./tools/viewTools");
|
|
16
|
+
const triggerTools_1 = require("./tools/triggerTools");
|
|
17
|
+
const functionTools_1 = require("./tools/functionTools");
|
|
18
|
+
const indexTools_1 = require("./tools/indexTools");
|
|
19
|
+
const constraintTools_1 = require("./tools/constraintTools");
|
|
20
|
+
const maintenanceTools_1 = require("./tools/maintenanceTools");
|
|
21
|
+
const processTools_1 = require("./tools/processTools");
|
|
15
22
|
const securityLayer_1 = __importDefault(require("./security/securityLayer"));
|
|
16
23
|
const connection_1 = __importDefault(require("./db/connection"));
|
|
17
24
|
const featureConfig_1 = require("./config/featureConfig");
|
|
@@ -31,95 +38,102 @@ class MySQLMCP {
|
|
|
31
38
|
this.transactionTools = new transactionTools_1.TransactionTools();
|
|
32
39
|
this.storedProcedureTools = new storedProcedureTools_1.StoredProcedureTools(this.security);
|
|
33
40
|
this.dataExportTools = new dataExportTools_1.DataExportTools(this.security);
|
|
41
|
+
this.viewTools = new viewTools_1.ViewTools(this.security);
|
|
42
|
+
this.triggerTools = new triggerTools_1.TriggerTools(this.security);
|
|
43
|
+
this.functionTools = new functionTools_1.FunctionTools(this.security);
|
|
44
|
+
this.indexTools = new indexTools_1.IndexTools(this.security);
|
|
45
|
+
this.constraintTools = new constraintTools_1.ConstraintTools(this.security);
|
|
46
|
+
this.maintenanceTools = new maintenanceTools_1.MaintenanceTools(this.security);
|
|
47
|
+
this.processTools = new processTools_1.ProcessTools(this.security);
|
|
34
48
|
}
|
|
35
49
|
// Helper method to check if tool is enabled
|
|
36
50
|
checkToolEnabled(toolName) {
|
|
37
51
|
if (!this.featureConfig.isToolEnabled(toolName)) {
|
|
38
52
|
return {
|
|
39
53
|
enabled: false,
|
|
40
|
-
error: this.featureConfig.getPermissionError(toolName)
|
|
54
|
+
error: this.featureConfig.getPermissionError(toolName),
|
|
41
55
|
};
|
|
42
56
|
}
|
|
43
57
|
return { enabled: true };
|
|
44
58
|
}
|
|
45
59
|
// Database Tools
|
|
46
60
|
async listDatabases() {
|
|
47
|
-
const check = this.checkToolEnabled(
|
|
61
|
+
const check = this.checkToolEnabled("listDatabases");
|
|
48
62
|
if (!check.enabled) {
|
|
49
|
-
return { status:
|
|
63
|
+
return { status: "error", error: check.error };
|
|
50
64
|
}
|
|
51
65
|
return await this.dbTools.listDatabases();
|
|
52
66
|
}
|
|
53
67
|
async listTables(params) {
|
|
54
|
-
const check = this.checkToolEnabled(
|
|
68
|
+
const check = this.checkToolEnabled("listTables");
|
|
55
69
|
if (!check.enabled) {
|
|
56
|
-
return { status:
|
|
70
|
+
return { status: "error", error: check.error };
|
|
57
71
|
}
|
|
58
72
|
return await this.dbTools.listTables(params);
|
|
59
73
|
}
|
|
60
74
|
async readTableSchema(params) {
|
|
61
|
-
const check = this.checkToolEnabled(
|
|
75
|
+
const check = this.checkToolEnabled("readTableSchema");
|
|
62
76
|
if (!check.enabled) {
|
|
63
|
-
return { status:
|
|
77
|
+
return { status: "error", error: check.error };
|
|
64
78
|
}
|
|
65
79
|
return await this.dbTools.readTableSchema(params);
|
|
66
80
|
}
|
|
67
81
|
// CRUD Tools
|
|
68
82
|
async createRecord(params) {
|
|
69
|
-
const check = this.checkToolEnabled(
|
|
83
|
+
const check = this.checkToolEnabled("createRecord");
|
|
70
84
|
if (!check.enabled) {
|
|
71
|
-
return { status:
|
|
85
|
+
return { status: "error", error: check.error };
|
|
72
86
|
}
|
|
73
87
|
return await this.crudTools.createRecord(params);
|
|
74
88
|
}
|
|
75
89
|
async readRecords(params) {
|
|
76
|
-
const check = this.checkToolEnabled(
|
|
90
|
+
const check = this.checkToolEnabled("readRecords");
|
|
77
91
|
if (!check.enabled) {
|
|
78
|
-
return { status:
|
|
92
|
+
return { status: "error", error: check.error };
|
|
79
93
|
}
|
|
80
94
|
return await this.crudTools.readRecords(params);
|
|
81
95
|
}
|
|
82
96
|
async updateRecord(params) {
|
|
83
|
-
const check = this.checkToolEnabled(
|
|
97
|
+
const check = this.checkToolEnabled("updateRecord");
|
|
84
98
|
if (!check.enabled) {
|
|
85
|
-
return { status:
|
|
99
|
+
return { status: "error", error: check.error };
|
|
86
100
|
}
|
|
87
101
|
return await this.crudTools.updateRecord(params);
|
|
88
102
|
}
|
|
89
103
|
async deleteRecord(params) {
|
|
90
|
-
const check = this.checkToolEnabled(
|
|
104
|
+
const check = this.checkToolEnabled("deleteRecord");
|
|
91
105
|
if (!check.enabled) {
|
|
92
|
-
return { status:
|
|
106
|
+
return { status: "error", error: check.error };
|
|
93
107
|
}
|
|
94
108
|
return await this.crudTools.deleteRecord(params);
|
|
95
109
|
}
|
|
96
110
|
// Query Tools
|
|
97
111
|
async runQuery(params) {
|
|
98
|
-
const check = this.checkToolEnabled(
|
|
112
|
+
const check = this.checkToolEnabled("runQuery");
|
|
99
113
|
if (!check.enabled) {
|
|
100
|
-
return { status:
|
|
114
|
+
return { status: "error", error: check.error };
|
|
101
115
|
}
|
|
102
116
|
// Additional security check
|
|
103
117
|
if (!this.security.isReadOnlyQuery(params.query)) {
|
|
104
118
|
return {
|
|
105
|
-
status:
|
|
106
|
-
error:
|
|
119
|
+
status: "error",
|
|
120
|
+
error: "Only SELECT queries are allowed with runQuery. Use executeSql for other operations.",
|
|
107
121
|
};
|
|
108
122
|
}
|
|
109
123
|
return await this.queryTools.runQuery(params);
|
|
110
124
|
}
|
|
111
125
|
async executeSql(params) {
|
|
112
|
-
const check = this.checkToolEnabled(
|
|
126
|
+
const check = this.checkToolEnabled("executeSql");
|
|
113
127
|
if (!check.enabled) {
|
|
114
|
-
return { status:
|
|
128
|
+
return { status: "error", error: check.error };
|
|
115
129
|
}
|
|
116
130
|
// Additional security check - block DDL unless DDL permission is enabled
|
|
117
131
|
if (this.security.hasDangerousOperations(params.query)) {
|
|
118
132
|
// Check if DDL permission is enabled
|
|
119
|
-
if (!this.featureConfig.isCategoryEnabled(
|
|
133
|
+
if (!this.featureConfig.isCategoryEnabled("ddl")) {
|
|
120
134
|
return {
|
|
121
|
-
status:
|
|
122
|
-
error: 'DDL operations (DROP, TRUNCATE, ALTER, CREATE) require the "ddl" permission. Use executeDdl tool or add "ddl" to permissions.'
|
|
135
|
+
status: "error",
|
|
136
|
+
error: 'DDL operations (DROP, TRUNCATE, ALTER, CREATE) require the "ddl" permission. Use executeDdl tool or add "ddl" to permissions.',
|
|
123
137
|
};
|
|
124
138
|
}
|
|
125
139
|
}
|
|
@@ -127,178 +141,178 @@ class MySQLMCP {
|
|
|
127
141
|
}
|
|
128
142
|
// DDL Tools
|
|
129
143
|
async createTable(params) {
|
|
130
|
-
const check = this.checkToolEnabled(
|
|
144
|
+
const check = this.checkToolEnabled("createTable");
|
|
131
145
|
if (!check.enabled) {
|
|
132
|
-
return { status:
|
|
146
|
+
return { status: "error", error: check.error };
|
|
133
147
|
}
|
|
134
148
|
return await this.ddlTools.createTable(params);
|
|
135
149
|
}
|
|
136
150
|
async alterTable(params) {
|
|
137
|
-
const check = this.checkToolEnabled(
|
|
151
|
+
const check = this.checkToolEnabled("alterTable");
|
|
138
152
|
if (!check.enabled) {
|
|
139
|
-
return { status:
|
|
153
|
+
return { status: "error", error: check.error };
|
|
140
154
|
}
|
|
141
155
|
return await this.ddlTools.alterTable(params);
|
|
142
156
|
}
|
|
143
157
|
async dropTable(params) {
|
|
144
|
-
const check = this.checkToolEnabled(
|
|
158
|
+
const check = this.checkToolEnabled("dropTable");
|
|
145
159
|
if (!check.enabled) {
|
|
146
|
-
return { status:
|
|
160
|
+
return { status: "error", error: check.error };
|
|
147
161
|
}
|
|
148
162
|
return await this.ddlTools.dropTable(params);
|
|
149
163
|
}
|
|
150
164
|
async executeDdl(params) {
|
|
151
|
-
const check = this.checkToolEnabled(
|
|
165
|
+
const check = this.checkToolEnabled("executeDdl");
|
|
152
166
|
if (!check.enabled) {
|
|
153
|
-
return { status:
|
|
167
|
+
return { status: "error", error: check.error };
|
|
154
168
|
}
|
|
155
169
|
return await this.ddlTools.executeDdl(params);
|
|
156
170
|
}
|
|
157
171
|
// Utility Tools
|
|
158
172
|
async describeConnection() {
|
|
159
|
-
const check = this.checkToolEnabled(
|
|
173
|
+
const check = this.checkToolEnabled("describeConnection");
|
|
160
174
|
if (!check.enabled) {
|
|
161
|
-
return { status:
|
|
175
|
+
return { status: "error", error: check.error };
|
|
162
176
|
}
|
|
163
177
|
return await this.utilityTools.describeConnection();
|
|
164
178
|
}
|
|
165
179
|
async testConnection() {
|
|
166
|
-
const check = this.checkToolEnabled(
|
|
180
|
+
const check = this.checkToolEnabled("testConnection");
|
|
167
181
|
if (!check.enabled) {
|
|
168
|
-
return { status:
|
|
182
|
+
return { status: "error", error: check.error };
|
|
169
183
|
}
|
|
170
184
|
return await this.utilityTools.testConnection();
|
|
171
185
|
}
|
|
172
186
|
async getTableRelationships(params) {
|
|
173
|
-
const check = this.checkToolEnabled(
|
|
187
|
+
const check = this.checkToolEnabled("getTableRelationships");
|
|
174
188
|
if (!check.enabled) {
|
|
175
|
-
return { status:
|
|
189
|
+
return { status: "error", error: check.error };
|
|
176
190
|
}
|
|
177
191
|
return await this.utilityTools.getTableRelationships(params);
|
|
178
192
|
}
|
|
179
193
|
// Transaction Tools
|
|
180
194
|
async beginTransaction(params) {
|
|
181
|
-
const check = this.checkToolEnabled(
|
|
195
|
+
const check = this.checkToolEnabled("beginTransaction");
|
|
182
196
|
if (!check.enabled) {
|
|
183
|
-
return { status:
|
|
197
|
+
return { status: "error", error: check.error };
|
|
184
198
|
}
|
|
185
199
|
return await this.transactionTools.beginTransaction(params);
|
|
186
200
|
}
|
|
187
201
|
async commitTransaction(params) {
|
|
188
|
-
const check = this.checkToolEnabled(
|
|
202
|
+
const check = this.checkToolEnabled("commitTransaction");
|
|
189
203
|
if (!check.enabled) {
|
|
190
|
-
return { status:
|
|
204
|
+
return { status: "error", error: check.error };
|
|
191
205
|
}
|
|
192
206
|
return await this.transactionTools.commitTransaction(params);
|
|
193
207
|
}
|
|
194
208
|
async rollbackTransaction(params) {
|
|
195
|
-
const check = this.checkToolEnabled(
|
|
209
|
+
const check = this.checkToolEnabled("rollbackTransaction");
|
|
196
210
|
if (!check.enabled) {
|
|
197
|
-
return { status:
|
|
211
|
+
return { status: "error", error: check.error };
|
|
198
212
|
}
|
|
199
213
|
return await this.transactionTools.rollbackTransaction(params);
|
|
200
214
|
}
|
|
201
215
|
async getTransactionStatus() {
|
|
202
|
-
const check = this.checkToolEnabled(
|
|
216
|
+
const check = this.checkToolEnabled("getTransactionStatus");
|
|
203
217
|
if (!check.enabled) {
|
|
204
|
-
return { status:
|
|
218
|
+
return { status: "error", error: check.error };
|
|
205
219
|
}
|
|
206
220
|
return await this.transactionTools.getTransactionStatus();
|
|
207
221
|
}
|
|
208
222
|
async executeInTransaction(params) {
|
|
209
|
-
const check = this.checkToolEnabled(
|
|
223
|
+
const check = this.checkToolEnabled("executeSql"); // Use executeSql permission for transaction queries
|
|
210
224
|
if (!check.enabled) {
|
|
211
|
-
return { status:
|
|
225
|
+
return { status: "error", error: check.error };
|
|
212
226
|
}
|
|
213
227
|
return await this.transactionTools.executeInTransaction(params);
|
|
214
228
|
}
|
|
215
229
|
// Stored Procedure Tools
|
|
216
230
|
async listStoredProcedures(params) {
|
|
217
|
-
const check = this.checkToolEnabled(
|
|
231
|
+
const check = this.checkToolEnabled("listStoredProcedures");
|
|
218
232
|
if (!check.enabled) {
|
|
219
|
-
return { status:
|
|
233
|
+
return { status: "error", error: check.error };
|
|
220
234
|
}
|
|
221
235
|
return await this.storedProcedureTools.listStoredProcedures(params);
|
|
222
236
|
}
|
|
223
237
|
async getStoredProcedureInfo(params) {
|
|
224
|
-
const check = this.checkToolEnabled(
|
|
238
|
+
const check = this.checkToolEnabled("getStoredProcedureInfo");
|
|
225
239
|
if (!check.enabled) {
|
|
226
|
-
return { status:
|
|
240
|
+
return { status: "error", error: check.error };
|
|
227
241
|
}
|
|
228
242
|
return await this.storedProcedureTools.getStoredProcedureInfo(params);
|
|
229
243
|
}
|
|
230
244
|
async executeStoredProcedure(params) {
|
|
231
|
-
const check = this.checkToolEnabled(
|
|
245
|
+
const check = this.checkToolEnabled("executeStoredProcedure");
|
|
232
246
|
if (!check.enabled) {
|
|
233
|
-
return { status:
|
|
247
|
+
return { status: "error", error: check.error };
|
|
234
248
|
}
|
|
235
249
|
return await this.storedProcedureTools.executeStoredProcedure(params);
|
|
236
250
|
}
|
|
237
251
|
async createStoredProcedure(params) {
|
|
238
|
-
const check = this.checkToolEnabled(
|
|
252
|
+
const check = this.checkToolEnabled("createStoredProcedure");
|
|
239
253
|
if (!check.enabled) {
|
|
240
|
-
return { status:
|
|
254
|
+
return { status: "error", error: check.error };
|
|
241
255
|
}
|
|
242
256
|
return await this.storedProcedureTools.createStoredProcedure(params);
|
|
243
257
|
}
|
|
244
258
|
async dropStoredProcedure(params) {
|
|
245
|
-
const check = this.checkToolEnabled(
|
|
259
|
+
const check = this.checkToolEnabled("dropStoredProcedure");
|
|
246
260
|
if (!check.enabled) {
|
|
247
|
-
return { status:
|
|
261
|
+
return { status: "error", error: check.error };
|
|
248
262
|
}
|
|
249
263
|
return await this.storedProcedureTools.dropStoredProcedure(params);
|
|
250
264
|
}
|
|
251
265
|
async showCreateProcedure(params) {
|
|
252
|
-
const check = this.checkToolEnabled(
|
|
266
|
+
const check = this.checkToolEnabled("showCreateProcedure");
|
|
253
267
|
if (!check.enabled) {
|
|
254
|
-
return { status:
|
|
268
|
+
return { status: "error", error: check.error };
|
|
255
269
|
}
|
|
256
270
|
return await this.storedProcedureTools.showCreateProcedure(params);
|
|
257
271
|
}
|
|
258
272
|
// Data Export Tools
|
|
259
273
|
async exportTableToCSV(params) {
|
|
260
|
-
const check = this.checkToolEnabled(
|
|
274
|
+
const check = this.checkToolEnabled("exportTableToCSV");
|
|
261
275
|
if (!check.enabled) {
|
|
262
|
-
return { status:
|
|
276
|
+
return { status: "error", error: check.error };
|
|
263
277
|
}
|
|
264
278
|
return await this.dataExportTools.exportTableToCSV(params);
|
|
265
279
|
}
|
|
266
280
|
async exportQueryToCSV(params) {
|
|
267
|
-
const check = this.checkToolEnabled(
|
|
281
|
+
const check = this.checkToolEnabled("exportQueryToCSV");
|
|
268
282
|
if (!check.enabled) {
|
|
269
|
-
return { status:
|
|
283
|
+
return { status: "error", error: check.error };
|
|
270
284
|
}
|
|
271
285
|
return await this.dataExportTools.exportQueryToCSV(params);
|
|
272
286
|
}
|
|
273
287
|
// Get feature configuration status
|
|
274
288
|
getFeatureStatus() {
|
|
275
289
|
return {
|
|
276
|
-
status:
|
|
290
|
+
status: "success",
|
|
277
291
|
data: {
|
|
278
292
|
enabledCategories: this.featureConfig.getEnabledCategories(),
|
|
279
|
-
categoryStatus: this.featureConfig.getCategoryStatus()
|
|
280
|
-
}
|
|
293
|
+
categoryStatus: this.featureConfig.getCategoryStatus(),
|
|
294
|
+
},
|
|
281
295
|
};
|
|
282
296
|
}
|
|
283
297
|
/**
|
|
284
298
|
* Bulk insert multiple records into the specified table
|
|
285
299
|
*/
|
|
286
300
|
async bulkInsert(params) {
|
|
287
|
-
this.checkToolEnabled(
|
|
301
|
+
this.checkToolEnabled("bulk_insert");
|
|
288
302
|
return this.crudTools.bulkInsert(params);
|
|
289
303
|
}
|
|
290
304
|
/**
|
|
291
305
|
* Bulk update multiple records with different conditions and data
|
|
292
306
|
*/
|
|
293
307
|
async bulkUpdate(params) {
|
|
294
|
-
this.checkToolEnabled(
|
|
308
|
+
this.checkToolEnabled("bulk_update");
|
|
295
309
|
return this.crudTools.bulkUpdate(params);
|
|
296
310
|
}
|
|
297
311
|
/**
|
|
298
312
|
* Bulk delete records based on multiple condition sets
|
|
299
313
|
*/
|
|
300
314
|
async bulkDelete(params) {
|
|
301
|
-
this.checkToolEnabled(
|
|
315
|
+
this.checkToolEnabled("bulk_delete");
|
|
302
316
|
return this.crudTools.bulkDelete(params);
|
|
303
317
|
}
|
|
304
318
|
// Close database connection
|
|
@@ -306,6 +320,394 @@ class MySQLMCP {
|
|
|
306
320
|
const db = connection_1.default.getInstance();
|
|
307
321
|
await db.closePool();
|
|
308
322
|
}
|
|
323
|
+
// ==========================================
|
|
324
|
+
// Cache Management Methods
|
|
325
|
+
// ==========================================
|
|
326
|
+
/**
|
|
327
|
+
* Get cache statistics
|
|
328
|
+
*/
|
|
329
|
+
getCacheStats() {
|
|
330
|
+
const db = connection_1.default.getInstance();
|
|
331
|
+
return {
|
|
332
|
+
status: "success",
|
|
333
|
+
data: db.getCacheStats(),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Get cache configuration
|
|
338
|
+
*/
|
|
339
|
+
getCacheConfig() {
|
|
340
|
+
const db = connection_1.default.getInstance();
|
|
341
|
+
return {
|
|
342
|
+
status: "success",
|
|
343
|
+
data: db.getCacheConfig(),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Configure cache settings
|
|
348
|
+
*/
|
|
349
|
+
configureCacheSettings(params) {
|
|
350
|
+
const db = connection_1.default.getInstance();
|
|
351
|
+
db.setCacheConfig(params);
|
|
352
|
+
return {
|
|
353
|
+
status: "success",
|
|
354
|
+
data: {
|
|
355
|
+
message: "Cache configuration updated successfully",
|
|
356
|
+
config: db.getCacheConfig(),
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Clear the query cache
|
|
362
|
+
*/
|
|
363
|
+
clearCache() {
|
|
364
|
+
const db = connection_1.default.getInstance();
|
|
365
|
+
const clearedCount = db.clearCache();
|
|
366
|
+
return {
|
|
367
|
+
status: "success",
|
|
368
|
+
data: {
|
|
369
|
+
message: `Cache cleared successfully`,
|
|
370
|
+
entriesCleared: clearedCount,
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Invalidate cache for a specific table
|
|
376
|
+
*/
|
|
377
|
+
invalidateCacheForTable(params) {
|
|
378
|
+
const db = connection_1.default.getInstance();
|
|
379
|
+
const invalidatedCount = db.invalidateCacheForTable(params.table_name);
|
|
380
|
+
return {
|
|
381
|
+
status: "success",
|
|
382
|
+
data: {
|
|
383
|
+
message: `Cache invalidated for table '${params.table_name}'`,
|
|
384
|
+
entriesInvalidated: invalidatedCount,
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
// ==========================================
|
|
389
|
+
// Query Optimization Methods
|
|
390
|
+
// ==========================================
|
|
391
|
+
/**
|
|
392
|
+
* Analyze a query and get optimization suggestions
|
|
393
|
+
*/
|
|
394
|
+
analyzeQuery(params) {
|
|
395
|
+
const analysis = this.queryTools.analyzeQuery(params.query);
|
|
396
|
+
return {
|
|
397
|
+
status: "success",
|
|
398
|
+
data: analysis,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Get suggested optimizer hints for a specific optimization goal
|
|
403
|
+
*/
|
|
404
|
+
getOptimizationHints(params) {
|
|
405
|
+
const hints = this.queryTools.getSuggestedHints(params.goal);
|
|
406
|
+
return {
|
|
407
|
+
status: "success",
|
|
408
|
+
data: {
|
|
409
|
+
goal: params.goal,
|
|
410
|
+
hints,
|
|
411
|
+
},
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
// ==========================================
|
|
415
|
+
// View Tools
|
|
416
|
+
// ==========================================
|
|
417
|
+
async listViews(params) {
|
|
418
|
+
const check = this.checkToolEnabled("listViews");
|
|
419
|
+
if (!check.enabled)
|
|
420
|
+
return { status: "error", error: check.error };
|
|
421
|
+
return await this.viewTools.listViews(params);
|
|
422
|
+
}
|
|
423
|
+
async getViewInfo(params) {
|
|
424
|
+
const check = this.checkToolEnabled("getViewInfo");
|
|
425
|
+
if (!check.enabled)
|
|
426
|
+
return { status: "error", error: check.error };
|
|
427
|
+
return await this.viewTools.getViewInfo(params);
|
|
428
|
+
}
|
|
429
|
+
async createView(params) {
|
|
430
|
+
const check = this.checkToolEnabled("createView");
|
|
431
|
+
if (!check.enabled)
|
|
432
|
+
return { status: "error", error: check.error };
|
|
433
|
+
return await this.viewTools.createView(params);
|
|
434
|
+
}
|
|
435
|
+
async alterView(params) {
|
|
436
|
+
const check = this.checkToolEnabled("alterView");
|
|
437
|
+
if (!check.enabled)
|
|
438
|
+
return { status: "error", error: check.error };
|
|
439
|
+
return await this.viewTools.alterView(params);
|
|
440
|
+
}
|
|
441
|
+
async dropView(params) {
|
|
442
|
+
const check = this.checkToolEnabled("dropView");
|
|
443
|
+
if (!check.enabled)
|
|
444
|
+
return { status: "error", error: check.error };
|
|
445
|
+
return await this.viewTools.dropView(params);
|
|
446
|
+
}
|
|
447
|
+
async showCreateView(params) {
|
|
448
|
+
const check = this.checkToolEnabled("showCreateView");
|
|
449
|
+
if (!check.enabled)
|
|
450
|
+
return { status: "error", error: check.error };
|
|
451
|
+
return await this.viewTools.showCreateView(params);
|
|
452
|
+
}
|
|
453
|
+
// ==========================================
|
|
454
|
+
// Trigger Tools
|
|
455
|
+
// ==========================================
|
|
456
|
+
async listTriggers(params) {
|
|
457
|
+
const check = this.checkToolEnabled("listTriggers");
|
|
458
|
+
if (!check.enabled)
|
|
459
|
+
return { status: "error", error: check.error };
|
|
460
|
+
return await this.triggerTools.listTriggers(params);
|
|
461
|
+
}
|
|
462
|
+
async getTriggerInfo(params) {
|
|
463
|
+
const check = this.checkToolEnabled("getTriggerInfo");
|
|
464
|
+
if (!check.enabled)
|
|
465
|
+
return { status: "error", error: check.error };
|
|
466
|
+
return await this.triggerTools.getTriggerInfo(params);
|
|
467
|
+
}
|
|
468
|
+
async createTrigger(params) {
|
|
469
|
+
const check = this.checkToolEnabled("createTrigger");
|
|
470
|
+
if (!check.enabled)
|
|
471
|
+
return { status: "error", error: check.error };
|
|
472
|
+
return await this.triggerTools.createTrigger(params);
|
|
473
|
+
}
|
|
474
|
+
async dropTrigger(params) {
|
|
475
|
+
const check = this.checkToolEnabled("dropTrigger");
|
|
476
|
+
if (!check.enabled)
|
|
477
|
+
return { status: "error", error: check.error };
|
|
478
|
+
return await this.triggerTools.dropTrigger(params);
|
|
479
|
+
}
|
|
480
|
+
async showCreateTrigger(params) {
|
|
481
|
+
const check = this.checkToolEnabled("showCreateTrigger");
|
|
482
|
+
if (!check.enabled)
|
|
483
|
+
return { status: "error", error: check.error };
|
|
484
|
+
return await this.triggerTools.showCreateTrigger(params);
|
|
485
|
+
}
|
|
486
|
+
// ==========================================
|
|
487
|
+
// Function Tools
|
|
488
|
+
// ==========================================
|
|
489
|
+
async listFunctions(params) {
|
|
490
|
+
const check = this.checkToolEnabled("listFunctions");
|
|
491
|
+
if (!check.enabled)
|
|
492
|
+
return { status: "error", error: check.error };
|
|
493
|
+
return await this.functionTools.listFunctions(params);
|
|
494
|
+
}
|
|
495
|
+
async getFunctionInfo(params) {
|
|
496
|
+
const check = this.checkToolEnabled("getFunctionInfo");
|
|
497
|
+
if (!check.enabled)
|
|
498
|
+
return { status: "error", error: check.error };
|
|
499
|
+
return await this.functionTools.getFunctionInfo(params);
|
|
500
|
+
}
|
|
501
|
+
async createFunction(params) {
|
|
502
|
+
const check = this.checkToolEnabled("createFunction");
|
|
503
|
+
if (!check.enabled)
|
|
504
|
+
return { status: "error", error: check.error };
|
|
505
|
+
return await this.functionTools.createFunction(params);
|
|
506
|
+
}
|
|
507
|
+
async dropFunction(params) {
|
|
508
|
+
const check = this.checkToolEnabled("dropFunction");
|
|
509
|
+
if (!check.enabled)
|
|
510
|
+
return { status: "error", error: check.error };
|
|
511
|
+
return await this.functionTools.dropFunction(params);
|
|
512
|
+
}
|
|
513
|
+
async showCreateFunction(params) {
|
|
514
|
+
const check = this.checkToolEnabled("showCreateFunction");
|
|
515
|
+
if (!check.enabled)
|
|
516
|
+
return { status: "error", error: check.error };
|
|
517
|
+
return await this.functionTools.showCreateFunction(params);
|
|
518
|
+
}
|
|
519
|
+
async executeFunction(params) {
|
|
520
|
+
const check = this.checkToolEnabled("executeFunction");
|
|
521
|
+
if (!check.enabled)
|
|
522
|
+
return { status: "error", error: check.error };
|
|
523
|
+
return await this.functionTools.executeFunction(params);
|
|
524
|
+
}
|
|
525
|
+
// ==========================================
|
|
526
|
+
// Index Tools
|
|
527
|
+
// ==========================================
|
|
528
|
+
async listIndexes(params) {
|
|
529
|
+
const check = this.checkToolEnabled("listIndexes");
|
|
530
|
+
if (!check.enabled)
|
|
531
|
+
return { status: "error", error: check.error };
|
|
532
|
+
return await this.indexTools.listIndexes(params);
|
|
533
|
+
}
|
|
534
|
+
async getIndexInfo(params) {
|
|
535
|
+
const check = this.checkToolEnabled("getIndexInfo");
|
|
536
|
+
if (!check.enabled)
|
|
537
|
+
return { status: "error", error: check.error };
|
|
538
|
+
return await this.indexTools.getIndexInfo(params);
|
|
539
|
+
}
|
|
540
|
+
async createIndex(params) {
|
|
541
|
+
const check = this.checkToolEnabled("createIndex");
|
|
542
|
+
if (!check.enabled)
|
|
543
|
+
return { status: "error", error: check.error };
|
|
544
|
+
return await this.indexTools.createIndex(params);
|
|
545
|
+
}
|
|
546
|
+
async dropIndex(params) {
|
|
547
|
+
const check = this.checkToolEnabled("dropIndex");
|
|
548
|
+
if (!check.enabled)
|
|
549
|
+
return { status: "error", error: check.error };
|
|
550
|
+
return await this.indexTools.dropIndex(params);
|
|
551
|
+
}
|
|
552
|
+
async analyzeIndex(params) {
|
|
553
|
+
const check = this.checkToolEnabled("analyzeIndex");
|
|
554
|
+
if (!check.enabled)
|
|
555
|
+
return { status: "error", error: check.error };
|
|
556
|
+
return await this.indexTools.analyzeIndex(params);
|
|
557
|
+
}
|
|
558
|
+
// ==========================================
|
|
559
|
+
// Constraint Tools
|
|
560
|
+
// ==========================================
|
|
561
|
+
async listForeignKeys(params) {
|
|
562
|
+
const check = this.checkToolEnabled("listForeignKeys");
|
|
563
|
+
if (!check.enabled)
|
|
564
|
+
return { status: "error", error: check.error };
|
|
565
|
+
return await this.constraintTools.listForeignKeys(params);
|
|
566
|
+
}
|
|
567
|
+
async listConstraints(params) {
|
|
568
|
+
const check = this.checkToolEnabled("listConstraints");
|
|
569
|
+
if (!check.enabled)
|
|
570
|
+
return { status: "error", error: check.error };
|
|
571
|
+
return await this.constraintTools.listConstraints(params);
|
|
572
|
+
}
|
|
573
|
+
async addForeignKey(params) {
|
|
574
|
+
const check = this.checkToolEnabled("addForeignKey");
|
|
575
|
+
if (!check.enabled)
|
|
576
|
+
return { status: "error", error: check.error };
|
|
577
|
+
return await this.constraintTools.addForeignKey(params);
|
|
578
|
+
}
|
|
579
|
+
async dropForeignKey(params) {
|
|
580
|
+
const check = this.checkToolEnabled("dropForeignKey");
|
|
581
|
+
if (!check.enabled)
|
|
582
|
+
return { status: "error", error: check.error };
|
|
583
|
+
return await this.constraintTools.dropForeignKey(params);
|
|
584
|
+
}
|
|
585
|
+
async addUniqueConstraint(params) {
|
|
586
|
+
const check = this.checkToolEnabled("addUniqueConstraint");
|
|
587
|
+
if (!check.enabled)
|
|
588
|
+
return { status: "error", error: check.error };
|
|
589
|
+
return await this.constraintTools.addUniqueConstraint(params);
|
|
590
|
+
}
|
|
591
|
+
async dropConstraint(params) {
|
|
592
|
+
const check = this.checkToolEnabled("dropConstraint");
|
|
593
|
+
if (!check.enabled)
|
|
594
|
+
return { status: "error", error: check.error };
|
|
595
|
+
return await this.constraintTools.dropConstraint(params);
|
|
596
|
+
}
|
|
597
|
+
async addCheckConstraint(params) {
|
|
598
|
+
const check = this.checkToolEnabled("addCheckConstraint");
|
|
599
|
+
if (!check.enabled)
|
|
600
|
+
return { status: "error", error: check.error };
|
|
601
|
+
return await this.constraintTools.addCheckConstraint(params);
|
|
602
|
+
}
|
|
603
|
+
// ==========================================
|
|
604
|
+
// Table Maintenance Tools
|
|
605
|
+
// ==========================================
|
|
606
|
+
async analyzeTable(params) {
|
|
607
|
+
const check = this.checkToolEnabled("analyzeTable");
|
|
608
|
+
if (!check.enabled)
|
|
609
|
+
return { status: "error", error: check.error };
|
|
610
|
+
return await this.maintenanceTools.analyzeTable(params);
|
|
611
|
+
}
|
|
612
|
+
async optimizeTable(params) {
|
|
613
|
+
const check = this.checkToolEnabled("optimizeTable");
|
|
614
|
+
if (!check.enabled)
|
|
615
|
+
return { status: "error", error: check.error };
|
|
616
|
+
return await this.maintenanceTools.optimizeTable(params);
|
|
617
|
+
}
|
|
618
|
+
async checkTable(params) {
|
|
619
|
+
const check = this.checkToolEnabled("checkTable");
|
|
620
|
+
if (!check.enabled)
|
|
621
|
+
return { status: "error", error: check.error };
|
|
622
|
+
return await this.maintenanceTools.checkTable(params);
|
|
623
|
+
}
|
|
624
|
+
async repairTable(params) {
|
|
625
|
+
const check = this.checkToolEnabled("repairTable");
|
|
626
|
+
if (!check.enabled)
|
|
627
|
+
return { status: "error", error: check.error };
|
|
628
|
+
return await this.maintenanceTools.repairTable(params);
|
|
629
|
+
}
|
|
630
|
+
async truncateTable(params) {
|
|
631
|
+
const check = this.checkToolEnabled("truncateTable");
|
|
632
|
+
if (!check.enabled)
|
|
633
|
+
return { status: "error", error: check.error };
|
|
634
|
+
return await this.maintenanceTools.truncateTable(params);
|
|
635
|
+
}
|
|
636
|
+
async getTableStatus(params) {
|
|
637
|
+
const check = this.checkToolEnabled("getTableStatus");
|
|
638
|
+
if (!check.enabled)
|
|
639
|
+
return { status: "error", error: check.error };
|
|
640
|
+
return await this.maintenanceTools.getTableStatus(params);
|
|
641
|
+
}
|
|
642
|
+
async flushTable(params) {
|
|
643
|
+
const check = this.checkToolEnabled("flushTable");
|
|
644
|
+
if (!check.enabled)
|
|
645
|
+
return { status: "error", error: check.error };
|
|
646
|
+
return await this.maintenanceTools.flushTable(params);
|
|
647
|
+
}
|
|
648
|
+
async getTableSize(params) {
|
|
649
|
+
const check = this.checkToolEnabled("getTableSize");
|
|
650
|
+
if (!check.enabled)
|
|
651
|
+
return { status: "error", error: check.error };
|
|
652
|
+
return await this.maintenanceTools.getTableSize(params);
|
|
653
|
+
}
|
|
654
|
+
// ==========================================
|
|
655
|
+
// Process Management Tools
|
|
656
|
+
// ==========================================
|
|
657
|
+
async showProcessList(params) {
|
|
658
|
+
const check = this.checkToolEnabled("showProcessList");
|
|
659
|
+
if (!check.enabled)
|
|
660
|
+
return { status: "error", error: check.error };
|
|
661
|
+
return await this.processTools.showProcessList(params);
|
|
662
|
+
}
|
|
663
|
+
async killProcess(params) {
|
|
664
|
+
const check = this.checkToolEnabled("killProcess");
|
|
665
|
+
if (!check.enabled)
|
|
666
|
+
return { status: "error", error: check.error };
|
|
667
|
+
return await this.processTools.killProcess(params);
|
|
668
|
+
}
|
|
669
|
+
async showStatus(params) {
|
|
670
|
+
const check = this.checkToolEnabled("showStatus");
|
|
671
|
+
if (!check.enabled)
|
|
672
|
+
return { status: "error", error: check.error };
|
|
673
|
+
return await this.processTools.showStatus(params);
|
|
674
|
+
}
|
|
675
|
+
async showVariables(params) {
|
|
676
|
+
const check = this.checkToolEnabled("showVariables");
|
|
677
|
+
if (!check.enabled)
|
|
678
|
+
return { status: "error", error: check.error };
|
|
679
|
+
return await this.processTools.showVariables(params);
|
|
680
|
+
}
|
|
681
|
+
async explainQuery(params) {
|
|
682
|
+
const check = this.checkToolEnabled("explainQuery");
|
|
683
|
+
if (!check.enabled)
|
|
684
|
+
return { status: "error", error: check.error };
|
|
685
|
+
return await this.processTools.explainQuery(params);
|
|
686
|
+
}
|
|
687
|
+
async showEngineStatus(params) {
|
|
688
|
+
const check = this.checkToolEnabled("showEngineStatus");
|
|
689
|
+
if (!check.enabled)
|
|
690
|
+
return { status: "error", error: check.error };
|
|
691
|
+
return await this.processTools.showEngineStatus(params);
|
|
692
|
+
}
|
|
693
|
+
async getServerInfo() {
|
|
694
|
+
const check = this.checkToolEnabled("getServerInfo");
|
|
695
|
+
if (!check.enabled)
|
|
696
|
+
return { status: "error", error: check.error };
|
|
697
|
+
return await this.processTools.getServerInfo();
|
|
698
|
+
}
|
|
699
|
+
async showBinaryLogs() {
|
|
700
|
+
const check = this.checkToolEnabled("showBinaryLogs");
|
|
701
|
+
if (!check.enabled)
|
|
702
|
+
return { status: "error", error: check.error };
|
|
703
|
+
return await this.processTools.showBinaryLogs();
|
|
704
|
+
}
|
|
705
|
+
async showReplicationStatus(params) {
|
|
706
|
+
const check = this.checkToolEnabled("showReplicationStatus");
|
|
707
|
+
if (!check.enabled)
|
|
708
|
+
return { status: "error", error: check.error };
|
|
709
|
+
return await this.processTools.showReplicationStatus(params);
|
|
710
|
+
}
|
|
309
711
|
}
|
|
310
712
|
exports.MySQLMCP = MySQLMCP;
|
|
311
713
|
exports.default = MySQLMCP;
|