@berthojoris/mcp-mysql-server 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -60
- package/README.md +209 -79
- package/dist/mcp-server.js +429 -379
- package/dist/security/securityLayer.d.ts +8 -2
- package/dist/security/securityLayer.js +120 -48
- package/dist/tools/queryTools.d.ts +1 -1
- package/dist/tools/queryTools.js +33 -29
- package/package.json +86 -86
package/dist/mcp-server.js
CHANGED
|
@@ -7,770 +7,810 @@ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
|
7
7
|
const index_js_2 = require("./index.js");
|
|
8
8
|
// Get permissions from environment variable (set by bin/mcp-mysql.js)
|
|
9
9
|
// Priority: MCP_PERMISSIONS (from command line) > MCP_CONFIG (from .env) > all permissions
|
|
10
|
-
const permissions = process.env.MCP_PERMISSIONS || process.env.MCP_CONFIG ||
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
// Log the effective permissions to stderr
|
|
14
|
-
if (permissions) {
|
|
15
|
-
console.error(`Active permissions: ${permissions}`);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
console.error('Active permissions: all (default)');
|
|
19
|
-
}
|
|
10
|
+
const permissions = process.env.MCP_PERMISSIONS || process.env.MCP_CONFIG || "";
|
|
11
|
+
// Declare the MySQL MCP instance (will be initialized in main())
|
|
12
|
+
let mysqlMCP;
|
|
20
13
|
// Define all available tools with their schemas
|
|
21
14
|
const TOOLS = [
|
|
22
15
|
{
|
|
23
|
-
name:
|
|
24
|
-
description:
|
|
16
|
+
name: "list_databases",
|
|
17
|
+
description: "Lists all databases available on the MySQL server.",
|
|
25
18
|
inputSchema: {
|
|
26
|
-
type:
|
|
19
|
+
type: "object",
|
|
27
20
|
properties: {},
|
|
28
21
|
},
|
|
29
22
|
},
|
|
30
23
|
{
|
|
31
|
-
name:
|
|
32
|
-
description:
|
|
24
|
+
name: "list_tables",
|
|
25
|
+
description: "Lists all tables in the connected MySQL database.",
|
|
33
26
|
inputSchema: {
|
|
34
|
-
type:
|
|
27
|
+
type: "object",
|
|
35
28
|
properties: {
|
|
36
29
|
database: {
|
|
37
|
-
type:
|
|
38
|
-
description:
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Optional: specific database name to list tables from",
|
|
39
32
|
},
|
|
40
33
|
},
|
|
41
34
|
},
|
|
42
35
|
},
|
|
43
36
|
{
|
|
44
|
-
name:
|
|
45
|
-
description:
|
|
37
|
+
name: "read_table_schema",
|
|
38
|
+
description: "Reads the schema of a specified table, including columns, types, keys, and indexes.",
|
|
46
39
|
inputSchema: {
|
|
47
|
-
type:
|
|
40
|
+
type: "object",
|
|
48
41
|
properties: {
|
|
49
42
|
table_name: {
|
|
50
|
-
type:
|
|
51
|
-
description:
|
|
43
|
+
type: "string",
|
|
44
|
+
description: "Name of the table to read schema from",
|
|
52
45
|
},
|
|
53
46
|
},
|
|
54
|
-
required: [
|
|
47
|
+
required: ["table_name"],
|
|
55
48
|
},
|
|
56
49
|
},
|
|
57
50
|
{
|
|
58
|
-
name:
|
|
59
|
-
description:
|
|
51
|
+
name: "create_record",
|
|
52
|
+
description: "Creates a new record in the specified table.",
|
|
60
53
|
inputSchema: {
|
|
61
|
-
type:
|
|
54
|
+
type: "object",
|
|
62
55
|
properties: {
|
|
63
56
|
table_name: {
|
|
64
|
-
type:
|
|
65
|
-
description:
|
|
57
|
+
type: "string",
|
|
58
|
+
description: "Name of the table to insert into",
|
|
66
59
|
},
|
|
67
60
|
data: {
|
|
68
|
-
type:
|
|
69
|
-
description:
|
|
61
|
+
type: "object",
|
|
62
|
+
description: "Object containing column names and values to insert",
|
|
70
63
|
},
|
|
71
64
|
},
|
|
72
|
-
required: [
|
|
65
|
+
required: ["table_name", "data"],
|
|
73
66
|
},
|
|
74
67
|
},
|
|
75
68
|
{
|
|
76
|
-
name:
|
|
77
|
-
description:
|
|
69
|
+
name: "read_records",
|
|
70
|
+
description: "Reads records from the specified table with optional filtering, pagination, and sorting.",
|
|
78
71
|
inputSchema: {
|
|
79
|
-
type:
|
|
72
|
+
type: "object",
|
|
80
73
|
properties: {
|
|
81
74
|
table_name: {
|
|
82
|
-
type:
|
|
83
|
-
description:
|
|
75
|
+
type: "string",
|
|
76
|
+
description: "Name of the table to read from",
|
|
84
77
|
},
|
|
85
78
|
filters: {
|
|
86
|
-
type:
|
|
87
|
-
description:
|
|
79
|
+
type: "array",
|
|
80
|
+
description: "Array of filter conditions",
|
|
88
81
|
items: {
|
|
89
|
-
type:
|
|
82
|
+
type: "object",
|
|
90
83
|
properties: {
|
|
91
|
-
field: { type:
|
|
84
|
+
field: { type: "string" },
|
|
92
85
|
operator: {
|
|
93
|
-
type:
|
|
94
|
-
enum: [
|
|
86
|
+
type: "string",
|
|
87
|
+
enum: ["eq", "neq", "gt", "gte", "lt", "lte", "like", "in"],
|
|
95
88
|
},
|
|
96
89
|
value: {
|
|
97
|
-
description: 'Value to compare against (can be string, number, boolean, or array for "in" operator)'
|
|
90
|
+
description: 'Value to compare against (can be string, number, boolean, or array for "in" operator)',
|
|
98
91
|
},
|
|
99
92
|
},
|
|
100
|
-
required: [
|
|
93
|
+
required: ["field", "operator", "value"],
|
|
101
94
|
},
|
|
102
95
|
},
|
|
103
96
|
pagination: {
|
|
104
|
-
type:
|
|
97
|
+
type: "object",
|
|
105
98
|
properties: {
|
|
106
|
-
page: {
|
|
107
|
-
|
|
99
|
+
page: {
|
|
100
|
+
type: "number",
|
|
101
|
+
description: "Page number (starting from 1)",
|
|
102
|
+
},
|
|
103
|
+
limit: {
|
|
104
|
+
type: "number",
|
|
105
|
+
description: "Number of records per page",
|
|
106
|
+
},
|
|
108
107
|
},
|
|
109
108
|
},
|
|
110
109
|
sorting: {
|
|
111
|
-
type:
|
|
110
|
+
type: "object",
|
|
112
111
|
properties: {
|
|
113
|
-
field: { type:
|
|
114
|
-
direction: { type:
|
|
112
|
+
field: { type: "string", description: "Field name to sort by" },
|
|
113
|
+
direction: { type: "string", enum: ["asc", "desc"] },
|
|
115
114
|
},
|
|
116
115
|
},
|
|
117
116
|
},
|
|
118
|
-
required: [
|
|
117
|
+
required: ["table_name"],
|
|
119
118
|
},
|
|
120
119
|
},
|
|
121
120
|
{
|
|
122
|
-
name:
|
|
123
|
-
description:
|
|
121
|
+
name: "update_record",
|
|
122
|
+
description: "Updates existing records in the specified table based on conditions.",
|
|
124
123
|
inputSchema: {
|
|
125
|
-
type:
|
|
124
|
+
type: "object",
|
|
126
125
|
properties: {
|
|
127
126
|
table_name: {
|
|
128
|
-
type:
|
|
129
|
-
description:
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "Name of the table to update",
|
|
130
129
|
},
|
|
131
130
|
data: {
|
|
132
|
-
type:
|
|
133
|
-
description:
|
|
131
|
+
type: "object",
|
|
132
|
+
description: "Object containing column names and new values",
|
|
134
133
|
},
|
|
135
134
|
conditions: {
|
|
136
|
-
type:
|
|
137
|
-
description:
|
|
135
|
+
type: "array",
|
|
136
|
+
description: "Array of conditions to identify which records to update",
|
|
138
137
|
items: {
|
|
139
|
-
type:
|
|
138
|
+
type: "object",
|
|
140
139
|
properties: {
|
|
141
|
-
field: { type:
|
|
140
|
+
field: { type: "string" },
|
|
142
141
|
operator: {
|
|
143
|
-
type:
|
|
144
|
-
enum: [
|
|
142
|
+
type: "string",
|
|
143
|
+
enum: ["eq", "neq", "gt", "gte", "lt", "lte", "like", "in"],
|
|
145
144
|
},
|
|
146
145
|
value: {},
|
|
147
146
|
},
|
|
148
|
-
required: [
|
|
147
|
+
required: ["field", "operator", "value"],
|
|
149
148
|
},
|
|
150
149
|
},
|
|
151
150
|
},
|
|
152
|
-
required: [
|
|
151
|
+
required: ["table_name", "data", "conditions"],
|
|
153
152
|
},
|
|
154
153
|
},
|
|
155
154
|
{
|
|
156
|
-
name:
|
|
157
|
-
description:
|
|
155
|
+
name: "delete_record",
|
|
156
|
+
description: "Deletes records from the specified table based on conditions.",
|
|
158
157
|
inputSchema: {
|
|
159
|
-
type:
|
|
158
|
+
type: "object",
|
|
160
159
|
properties: {
|
|
161
160
|
table_name: {
|
|
162
|
-
type:
|
|
163
|
-
description:
|
|
161
|
+
type: "string",
|
|
162
|
+
description: "Name of the table to delete from",
|
|
164
163
|
},
|
|
165
164
|
conditions: {
|
|
166
|
-
type:
|
|
167
|
-
description:
|
|
165
|
+
type: "array",
|
|
166
|
+
description: "Array of conditions to identify which records to delete",
|
|
168
167
|
items: {
|
|
169
|
-
type:
|
|
168
|
+
type: "object",
|
|
170
169
|
properties: {
|
|
171
|
-
field: { type:
|
|
170
|
+
field: { type: "string" },
|
|
172
171
|
operator: {
|
|
173
|
-
type:
|
|
174
|
-
enum: [
|
|
172
|
+
type: "string",
|
|
173
|
+
enum: ["eq", "neq", "gt", "gte", "lt", "lte", "like", "in"],
|
|
175
174
|
},
|
|
176
175
|
value: {},
|
|
177
176
|
},
|
|
178
|
-
required: [
|
|
177
|
+
required: ["field", "operator", "value"],
|
|
179
178
|
},
|
|
180
179
|
},
|
|
181
180
|
},
|
|
182
|
-
required: [
|
|
181
|
+
required: ["table_name", "conditions"],
|
|
183
182
|
},
|
|
184
183
|
},
|
|
185
184
|
{
|
|
186
|
-
name:
|
|
187
|
-
description:
|
|
185
|
+
name: "bulk_insert",
|
|
186
|
+
description: "Bulk insert multiple records into the specified table with batch processing for optimal performance.",
|
|
188
187
|
inputSchema: {
|
|
189
|
-
type:
|
|
188
|
+
type: "object",
|
|
190
189
|
properties: {
|
|
191
190
|
table_name: {
|
|
192
|
-
type:
|
|
193
|
-
description:
|
|
191
|
+
type: "string",
|
|
192
|
+
description: "Name of the table to insert into",
|
|
194
193
|
},
|
|
195
194
|
data: {
|
|
196
|
-
type:
|
|
197
|
-
description:
|
|
195
|
+
type: "array",
|
|
196
|
+
description: "Array of objects containing column names and values to insert",
|
|
198
197
|
minItems: 1,
|
|
199
198
|
items: {
|
|
200
|
-
type:
|
|
199
|
+
type: "object",
|
|
201
200
|
additionalProperties: true,
|
|
202
201
|
},
|
|
203
202
|
},
|
|
204
203
|
batch_size: {
|
|
205
|
-
type:
|
|
206
|
-
description:
|
|
204
|
+
type: "number",
|
|
205
|
+
description: "Optional batch size for processing (default: 1000, max: 10000)",
|
|
207
206
|
minimum: 1,
|
|
208
207
|
maximum: 10000,
|
|
209
208
|
},
|
|
210
209
|
},
|
|
211
|
-
required: [
|
|
210
|
+
required: ["table_name", "data"],
|
|
212
211
|
},
|
|
213
212
|
},
|
|
214
213
|
{
|
|
215
|
-
name:
|
|
216
|
-
description:
|
|
214
|
+
name: "bulk_update",
|
|
215
|
+
description: "Bulk update multiple records with different conditions and data using batch processing.",
|
|
217
216
|
inputSchema: {
|
|
218
|
-
type:
|
|
217
|
+
type: "object",
|
|
219
218
|
properties: {
|
|
220
219
|
table_name: {
|
|
221
|
-
type:
|
|
222
|
-
description:
|
|
220
|
+
type: "string",
|
|
221
|
+
description: "Name of the table to update",
|
|
223
222
|
},
|
|
224
223
|
updates: {
|
|
225
|
-
type:
|
|
226
|
-
description:
|
|
224
|
+
type: "array",
|
|
225
|
+
description: "Array of update operations with data and conditions",
|
|
227
226
|
minItems: 1,
|
|
228
227
|
items: {
|
|
229
|
-
type:
|
|
228
|
+
type: "object",
|
|
230
229
|
properties: {
|
|
231
230
|
data: {
|
|
232
|
-
type:
|
|
233
|
-
description:
|
|
231
|
+
type: "object",
|
|
232
|
+
description: "Object containing column names and new values",
|
|
234
233
|
additionalProperties: true,
|
|
235
234
|
},
|
|
236
235
|
conditions: {
|
|
237
|
-
type:
|
|
238
|
-
description:
|
|
236
|
+
type: "array",
|
|
237
|
+
description: "Array of conditions to identify which records to update",
|
|
239
238
|
minItems: 1,
|
|
240
239
|
items: {
|
|
241
|
-
type:
|
|
240
|
+
type: "object",
|
|
242
241
|
properties: {
|
|
243
|
-
field: { type:
|
|
242
|
+
field: { type: "string" },
|
|
244
243
|
operator: {
|
|
245
|
-
type:
|
|
246
|
-
enum: [
|
|
244
|
+
type: "string",
|
|
245
|
+
enum: [
|
|
246
|
+
"eq",
|
|
247
|
+
"neq",
|
|
248
|
+
"gt",
|
|
249
|
+
"gte",
|
|
250
|
+
"lt",
|
|
251
|
+
"lte",
|
|
252
|
+
"like",
|
|
253
|
+
"in",
|
|
254
|
+
],
|
|
247
255
|
},
|
|
248
256
|
value: {},
|
|
249
257
|
},
|
|
250
|
-
required: [
|
|
258
|
+
required: ["field", "operator", "value"],
|
|
251
259
|
},
|
|
252
260
|
},
|
|
253
261
|
},
|
|
254
|
-
required: [
|
|
262
|
+
required: ["data", "conditions"],
|
|
255
263
|
},
|
|
256
264
|
},
|
|
257
265
|
batch_size: {
|
|
258
|
-
type:
|
|
259
|
-
description:
|
|
266
|
+
type: "number",
|
|
267
|
+
description: "Optional batch size for processing (default: 100, max: 1000)",
|
|
260
268
|
minimum: 1,
|
|
261
269
|
maximum: 1000,
|
|
262
270
|
},
|
|
263
271
|
},
|
|
264
|
-
required: [
|
|
272
|
+
required: ["table_name", "updates"],
|
|
265
273
|
},
|
|
266
274
|
},
|
|
267
275
|
{
|
|
268
|
-
name:
|
|
269
|
-
description:
|
|
276
|
+
name: "bulk_delete",
|
|
277
|
+
description: "Bulk delete records based on multiple condition sets using batch processing.",
|
|
270
278
|
inputSchema: {
|
|
271
|
-
type:
|
|
279
|
+
type: "object",
|
|
272
280
|
properties: {
|
|
273
281
|
table_name: {
|
|
274
|
-
type:
|
|
275
|
-
description:
|
|
282
|
+
type: "string",
|
|
283
|
+
description: "Name of the table to delete from",
|
|
276
284
|
},
|
|
277
285
|
condition_sets: {
|
|
278
|
-
type:
|
|
279
|
-
description:
|
|
286
|
+
type: "array",
|
|
287
|
+
description: "Array of condition sets, each defining records to delete",
|
|
280
288
|
minItems: 1,
|
|
281
289
|
items: {
|
|
282
|
-
type:
|
|
283
|
-
description:
|
|
290
|
+
type: "array",
|
|
291
|
+
description: "Array of conditions for this delete operation",
|
|
284
292
|
minItems: 1,
|
|
285
293
|
items: {
|
|
286
|
-
type:
|
|
294
|
+
type: "object",
|
|
287
295
|
properties: {
|
|
288
|
-
field: { type:
|
|
296
|
+
field: { type: "string" },
|
|
289
297
|
operator: {
|
|
290
|
-
type:
|
|
291
|
-
enum: [
|
|
298
|
+
type: "string",
|
|
299
|
+
enum: ["eq", "neq", "gt", "gte", "lt", "lte", "like", "in"],
|
|
292
300
|
},
|
|
293
301
|
value: {},
|
|
294
302
|
},
|
|
295
|
-
required: [
|
|
303
|
+
required: ["field", "operator", "value"],
|
|
296
304
|
},
|
|
297
305
|
},
|
|
298
306
|
},
|
|
299
307
|
batch_size: {
|
|
300
|
-
type:
|
|
301
|
-
description:
|
|
308
|
+
type: "number",
|
|
309
|
+
description: "Optional batch size for processing (default: 100, max: 1000)",
|
|
302
310
|
minimum: 1,
|
|
303
311
|
maximum: 1000,
|
|
304
312
|
},
|
|
305
313
|
},
|
|
306
|
-
required: [
|
|
314
|
+
required: ["table_name", "condition_sets"],
|
|
307
315
|
},
|
|
308
316
|
},
|
|
309
317
|
{
|
|
310
|
-
name:
|
|
311
|
-
description:
|
|
318
|
+
name: "run_query",
|
|
319
|
+
description: "Runs a read-only SQL SELECT query with optional parameters. Only SELECT statements are allowed.",
|
|
312
320
|
inputSchema: {
|
|
313
|
-
type:
|
|
321
|
+
type: "object",
|
|
314
322
|
properties: {
|
|
315
323
|
query: {
|
|
316
|
-
type:
|
|
317
|
-
description:
|
|
324
|
+
type: "string",
|
|
325
|
+
description: "SQL SELECT query to execute",
|
|
318
326
|
},
|
|
319
327
|
params: {
|
|
320
|
-
type:
|
|
321
|
-
description:
|
|
328
|
+
type: "array",
|
|
329
|
+
description: "Optional array of parameters for parameterized queries",
|
|
322
330
|
items: {},
|
|
323
331
|
},
|
|
324
332
|
},
|
|
325
|
-
required: [
|
|
333
|
+
required: ["query"],
|
|
326
334
|
},
|
|
327
335
|
},
|
|
328
336
|
{
|
|
329
|
-
name:
|
|
337
|
+
name: "execute_sql",
|
|
330
338
|
description: 'Executes a write SQL operation (INSERT, UPDATE, DELETE) with optional parameters. DDL operations require "ddl" permission.',
|
|
331
339
|
inputSchema: {
|
|
332
|
-
type:
|
|
340
|
+
type: "object",
|
|
333
341
|
properties: {
|
|
334
342
|
query: {
|
|
335
|
-
type:
|
|
336
|
-
description:
|
|
343
|
+
type: "string",
|
|
344
|
+
description: "SQL query to execute (INSERT, UPDATE, DELETE, or DDL if permitted)",
|
|
337
345
|
},
|
|
338
346
|
params: {
|
|
339
|
-
type:
|
|
340
|
-
description:
|
|
347
|
+
type: "array",
|
|
348
|
+
description: "Optional array of parameters for parameterized queries",
|
|
341
349
|
items: {},
|
|
342
350
|
},
|
|
343
351
|
},
|
|
344
|
-
required: [
|
|
352
|
+
required: ["query"],
|
|
345
353
|
},
|
|
346
354
|
},
|
|
347
355
|
{
|
|
348
|
-
name:
|
|
356
|
+
name: "create_table",
|
|
349
357
|
description: 'Creates a new table with the specified columns and indexes. Requires "ddl" permission.',
|
|
350
358
|
inputSchema: {
|
|
351
|
-
type:
|
|
359
|
+
type: "object",
|
|
352
360
|
properties: {
|
|
353
361
|
table_name: {
|
|
354
|
-
type:
|
|
355
|
-
description:
|
|
362
|
+
type: "string",
|
|
363
|
+
description: "Name of the table to create",
|
|
356
364
|
},
|
|
357
365
|
columns: {
|
|
358
|
-
type:
|
|
359
|
-
description:
|
|
366
|
+
type: "array",
|
|
367
|
+
description: "Array of column definitions",
|
|
360
368
|
items: {
|
|
361
|
-
type:
|
|
369
|
+
type: "object",
|
|
362
370
|
properties: {
|
|
363
|
-
name: { type:
|
|
364
|
-
type: {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
371
|
+
name: { type: "string", description: "Column name" },
|
|
372
|
+
type: {
|
|
373
|
+
type: "string",
|
|
374
|
+
description: "MySQL data type (e.g., VARCHAR(255), INT, TEXT)",
|
|
375
|
+
},
|
|
376
|
+
nullable: {
|
|
377
|
+
type: "boolean",
|
|
378
|
+
description: "Whether column can be NULL",
|
|
379
|
+
},
|
|
380
|
+
primary_key: {
|
|
381
|
+
type: "boolean",
|
|
382
|
+
description: "Whether this is the primary key",
|
|
383
|
+
},
|
|
384
|
+
auto_increment: {
|
|
385
|
+
type: "boolean",
|
|
386
|
+
description: "Whether column auto-increments",
|
|
387
|
+
},
|
|
388
|
+
default: { type: "string", description: "Default value" },
|
|
369
389
|
},
|
|
370
|
-
required: [
|
|
390
|
+
required: ["name", "type"],
|
|
371
391
|
},
|
|
372
392
|
},
|
|
373
393
|
indexes: {
|
|
374
|
-
type:
|
|
375
|
-
description:
|
|
394
|
+
type: "array",
|
|
395
|
+
description: "Optional indexes to create",
|
|
376
396
|
items: {
|
|
377
|
-
type:
|
|
397
|
+
type: "object",
|
|
378
398
|
properties: {
|
|
379
|
-
name: { type:
|
|
380
|
-
columns: { type:
|
|
381
|
-
unique: { type:
|
|
399
|
+
name: { type: "string" },
|
|
400
|
+
columns: { type: "array", items: { type: "string" } },
|
|
401
|
+
unique: { type: "boolean" },
|
|
382
402
|
},
|
|
383
403
|
},
|
|
384
404
|
},
|
|
385
405
|
},
|
|
386
|
-
required: [
|
|
406
|
+
required: ["table_name", "columns"],
|
|
387
407
|
},
|
|
388
408
|
},
|
|
389
409
|
{
|
|
390
|
-
name:
|
|
410
|
+
name: "alter_table",
|
|
391
411
|
description: 'Alters an existing table structure (add/drop/modify columns, add/drop indexes). Requires "ddl" permission.',
|
|
392
412
|
inputSchema: {
|
|
393
|
-
type:
|
|
413
|
+
type: "object",
|
|
394
414
|
properties: {
|
|
395
415
|
table_name: {
|
|
396
|
-
type:
|
|
397
|
-
description:
|
|
416
|
+
type: "string",
|
|
417
|
+
description: "Name of the table to alter",
|
|
398
418
|
},
|
|
399
419
|
operations: {
|
|
400
|
-
type:
|
|
401
|
-
description:
|
|
420
|
+
type: "array",
|
|
421
|
+
description: "Array of alter operations to perform",
|
|
402
422
|
items: {
|
|
403
|
-
type:
|
|
423
|
+
type: "object",
|
|
404
424
|
properties: {
|
|
405
425
|
type: {
|
|
406
|
-
type:
|
|
407
|
-
enum: [
|
|
408
|
-
|
|
426
|
+
type: "string",
|
|
427
|
+
enum: [
|
|
428
|
+
"add_column",
|
|
429
|
+
"drop_column",
|
|
430
|
+
"modify_column",
|
|
431
|
+
"rename_column",
|
|
432
|
+
"add_index",
|
|
433
|
+
"drop_index",
|
|
434
|
+
],
|
|
435
|
+
description: "Type of alteration",
|
|
409
436
|
},
|
|
410
|
-
column_name: { type:
|
|
411
|
-
new_column_name: { type:
|
|
412
|
-
column_type: { type:
|
|
413
|
-
nullable: { type:
|
|
414
|
-
default: { type:
|
|
415
|
-
index_name: { type:
|
|
416
|
-
index_columns: { type:
|
|
417
|
-
unique: { type:
|
|
437
|
+
column_name: { type: "string" },
|
|
438
|
+
new_column_name: { type: "string" },
|
|
439
|
+
column_type: { type: "string" },
|
|
440
|
+
nullable: { type: "boolean" },
|
|
441
|
+
default: { type: "string" },
|
|
442
|
+
index_name: { type: "string" },
|
|
443
|
+
index_columns: { type: "array", items: { type: "string" } },
|
|
444
|
+
unique: { type: "boolean" },
|
|
418
445
|
},
|
|
419
|
-
required: [
|
|
446
|
+
required: ["type"],
|
|
420
447
|
},
|
|
421
448
|
},
|
|
422
449
|
},
|
|
423
|
-
required: [
|
|
450
|
+
required: ["table_name", "operations"],
|
|
424
451
|
},
|
|
425
452
|
},
|
|
426
453
|
{
|
|
427
|
-
name:
|
|
454
|
+
name: "drop_table",
|
|
428
455
|
description: 'Drops (deletes) a table and all its data. Requires "ddl" permission. WARNING: This is irreversible!',
|
|
429
456
|
inputSchema: {
|
|
430
|
-
type:
|
|
457
|
+
type: "object",
|
|
431
458
|
properties: {
|
|
432
459
|
table_name: {
|
|
433
|
-
type:
|
|
434
|
-
description:
|
|
460
|
+
type: "string",
|
|
461
|
+
description: "Name of the table to drop",
|
|
435
462
|
},
|
|
436
463
|
if_exists: {
|
|
437
|
-
type:
|
|
438
|
-
description:
|
|
464
|
+
type: "boolean",
|
|
465
|
+
description: "If true, will not error if table does not exist",
|
|
439
466
|
},
|
|
440
467
|
},
|
|
441
|
-
required: [
|
|
468
|
+
required: ["table_name"],
|
|
442
469
|
},
|
|
443
470
|
},
|
|
444
471
|
{
|
|
445
|
-
name:
|
|
472
|
+
name: "execute_ddl",
|
|
446
473
|
description: 'Executes raw DDL SQL (CREATE, ALTER, DROP, TRUNCATE, RENAME). Requires "ddl" permission.',
|
|
447
474
|
inputSchema: {
|
|
448
|
-
type:
|
|
475
|
+
type: "object",
|
|
449
476
|
properties: {
|
|
450
477
|
query: {
|
|
451
|
-
type:
|
|
452
|
-
description:
|
|
478
|
+
type: "string",
|
|
479
|
+
description: "DDL SQL query to execute",
|
|
453
480
|
},
|
|
454
481
|
},
|
|
455
|
-
required: [
|
|
482
|
+
required: ["query"],
|
|
456
483
|
},
|
|
457
484
|
},
|
|
458
485
|
{
|
|
459
|
-
name:
|
|
460
|
-
description:
|
|
486
|
+
name: "describe_connection",
|
|
487
|
+
description: "Returns information about the current database connection.",
|
|
461
488
|
inputSchema: {
|
|
462
|
-
type:
|
|
489
|
+
type: "object",
|
|
463
490
|
properties: {},
|
|
464
491
|
},
|
|
465
492
|
},
|
|
466
493
|
{
|
|
467
|
-
name:
|
|
468
|
-
description:
|
|
494
|
+
name: "test_connection",
|
|
495
|
+
description: "Tests the database connection and returns latency information.",
|
|
469
496
|
inputSchema: {
|
|
470
|
-
type:
|
|
497
|
+
type: "object",
|
|
471
498
|
properties: {},
|
|
472
499
|
},
|
|
473
500
|
},
|
|
474
501
|
{
|
|
475
|
-
name:
|
|
476
|
-
description:
|
|
502
|
+
name: "get_table_relationships",
|
|
503
|
+
description: "Returns foreign key relationships for a specified table.",
|
|
477
504
|
inputSchema: {
|
|
478
|
-
type:
|
|
505
|
+
type: "object",
|
|
479
506
|
properties: {
|
|
480
507
|
table_name: {
|
|
481
|
-
type:
|
|
482
|
-
description:
|
|
508
|
+
type: "string",
|
|
509
|
+
description: "Name of the table to get relationships for",
|
|
483
510
|
},
|
|
484
511
|
},
|
|
485
|
-
required: [
|
|
512
|
+
required: ["table_name"],
|
|
486
513
|
},
|
|
487
514
|
},
|
|
488
515
|
// Transaction Tools
|
|
489
516
|
{
|
|
490
|
-
name:
|
|
491
|
-
description:
|
|
517
|
+
name: "begin_transaction",
|
|
518
|
+
description: "Begins a new database transaction. Returns a transaction ID for subsequent operations.",
|
|
492
519
|
inputSchema: {
|
|
493
|
-
type:
|
|
520
|
+
type: "object",
|
|
494
521
|
properties: {
|
|
495
522
|
transactionId: {
|
|
496
|
-
type:
|
|
497
|
-
description:
|
|
523
|
+
type: "string",
|
|
524
|
+
description: "Optional custom transaction ID. If not provided, one will be generated.",
|
|
498
525
|
},
|
|
499
526
|
},
|
|
500
527
|
},
|
|
501
528
|
},
|
|
502
529
|
{
|
|
503
|
-
name:
|
|
504
|
-
description:
|
|
530
|
+
name: "commit_transaction",
|
|
531
|
+
description: "Commits a transaction and makes all changes permanent.",
|
|
505
532
|
inputSchema: {
|
|
506
|
-
type:
|
|
533
|
+
type: "object",
|
|
507
534
|
properties: {
|
|
508
535
|
transactionId: {
|
|
509
|
-
type:
|
|
510
|
-
description:
|
|
536
|
+
type: "string",
|
|
537
|
+
description: "The transaction ID to commit",
|
|
511
538
|
},
|
|
512
539
|
},
|
|
513
|
-
required: [
|
|
540
|
+
required: ["transactionId"],
|
|
514
541
|
},
|
|
515
542
|
},
|
|
516
543
|
{
|
|
517
|
-
name:
|
|
518
|
-
description:
|
|
544
|
+
name: "rollback_transaction",
|
|
545
|
+
description: "Rolls back a transaction and undoes all changes made within it.",
|
|
519
546
|
inputSchema: {
|
|
520
|
-
type:
|
|
547
|
+
type: "object",
|
|
521
548
|
properties: {
|
|
522
549
|
transactionId: {
|
|
523
|
-
type:
|
|
524
|
-
description:
|
|
550
|
+
type: "string",
|
|
551
|
+
description: "The transaction ID to rollback",
|
|
525
552
|
},
|
|
526
553
|
},
|
|
527
|
-
required: [
|
|
554
|
+
required: ["transactionId"],
|
|
528
555
|
},
|
|
529
556
|
},
|
|
530
557
|
{
|
|
531
|
-
name:
|
|
532
|
-
description:
|
|
558
|
+
name: "get_transaction_status",
|
|
559
|
+
description: "Returns the status of all active transactions.",
|
|
533
560
|
inputSchema: {
|
|
534
|
-
type:
|
|
561
|
+
type: "object",
|
|
535
562
|
properties: {},
|
|
536
563
|
},
|
|
537
564
|
},
|
|
538
565
|
{
|
|
539
|
-
name:
|
|
540
|
-
description:
|
|
566
|
+
name: "execute_in_transaction",
|
|
567
|
+
description: "Executes a SQL query within an active transaction.",
|
|
541
568
|
inputSchema: {
|
|
542
|
-
type:
|
|
569
|
+
type: "object",
|
|
543
570
|
properties: {
|
|
544
571
|
transactionId: {
|
|
545
|
-
type:
|
|
546
|
-
description:
|
|
572
|
+
type: "string",
|
|
573
|
+
description: "The transaction ID to execute the query within",
|
|
547
574
|
},
|
|
548
575
|
query: {
|
|
549
|
-
type:
|
|
550
|
-
description:
|
|
576
|
+
type: "string",
|
|
577
|
+
description: "SQL query to execute within the transaction",
|
|
551
578
|
},
|
|
552
579
|
params: {
|
|
553
|
-
type:
|
|
554
|
-
description:
|
|
580
|
+
type: "array",
|
|
581
|
+
description: "Optional array of parameters for parameterized queries",
|
|
555
582
|
items: {},
|
|
556
583
|
},
|
|
557
584
|
},
|
|
558
|
-
required: [
|
|
585
|
+
required: ["transactionId", "query"],
|
|
559
586
|
},
|
|
560
587
|
},
|
|
561
588
|
// Stored Procedure Tools
|
|
562
589
|
{
|
|
563
|
-
name:
|
|
564
|
-
description:
|
|
590
|
+
name: "list_stored_procedures",
|
|
591
|
+
description: "Lists all stored procedures in the specified database.",
|
|
565
592
|
inputSchema: {
|
|
566
|
-
type:
|
|
593
|
+
type: "object",
|
|
567
594
|
properties: {
|
|
568
595
|
database: {
|
|
569
|
-
type:
|
|
570
|
-
description:
|
|
596
|
+
type: "string",
|
|
597
|
+
description: "Optional: specific database name to list procedures from",
|
|
571
598
|
},
|
|
572
599
|
},
|
|
573
600
|
},
|
|
574
601
|
},
|
|
575
602
|
{
|
|
576
|
-
name:
|
|
577
|
-
description:
|
|
603
|
+
name: "get_stored_procedure_info",
|
|
604
|
+
description: "Gets detailed information about a specific stored procedure including parameters and metadata.",
|
|
578
605
|
inputSchema: {
|
|
579
|
-
type:
|
|
606
|
+
type: "object",
|
|
580
607
|
properties: {
|
|
581
608
|
procedure_name: {
|
|
582
|
-
type:
|
|
583
|
-
description:
|
|
609
|
+
type: "string",
|
|
610
|
+
description: "Name of the stored procedure to get information for",
|
|
584
611
|
},
|
|
585
612
|
database: {
|
|
586
|
-
type:
|
|
587
|
-
description:
|
|
613
|
+
type: "string",
|
|
614
|
+
description: "Optional: specific database name",
|
|
588
615
|
},
|
|
589
616
|
},
|
|
590
|
-
required: [
|
|
617
|
+
required: ["procedure_name"],
|
|
591
618
|
},
|
|
592
619
|
},
|
|
593
620
|
{
|
|
594
|
-
name:
|
|
595
|
-
description:
|
|
621
|
+
name: "execute_stored_procedure",
|
|
622
|
+
description: "Executes a stored procedure with optional parameters.",
|
|
596
623
|
inputSchema: {
|
|
597
|
-
type:
|
|
624
|
+
type: "object",
|
|
598
625
|
properties: {
|
|
599
626
|
procedure_name: {
|
|
600
|
-
type:
|
|
601
|
-
description:
|
|
627
|
+
type: "string",
|
|
628
|
+
description: "Name of the stored procedure to execute",
|
|
602
629
|
},
|
|
603
630
|
parameters: {
|
|
604
|
-
type:
|
|
605
|
-
description:
|
|
631
|
+
type: "array",
|
|
632
|
+
description: "Optional array of parameters to pass to the stored procedure",
|
|
606
633
|
items: {},
|
|
607
634
|
},
|
|
608
635
|
database: {
|
|
609
|
-
type:
|
|
610
|
-
description:
|
|
636
|
+
type: "string",
|
|
637
|
+
description: "Optional: specific database name",
|
|
611
638
|
},
|
|
612
639
|
},
|
|
613
|
-
required: [
|
|
640
|
+
required: ["procedure_name"],
|
|
614
641
|
},
|
|
615
642
|
},
|
|
616
643
|
{
|
|
617
|
-
name:
|
|
618
|
-
description:
|
|
644
|
+
name: "create_stored_procedure",
|
|
645
|
+
description: "Creates a new stored procedure with the specified parameters and body.",
|
|
619
646
|
inputSchema: {
|
|
620
|
-
type:
|
|
647
|
+
type: "object",
|
|
621
648
|
properties: {
|
|
622
649
|
procedure_name: {
|
|
623
|
-
type:
|
|
624
|
-
description:
|
|
650
|
+
type: "string",
|
|
651
|
+
description: "Name of the stored procedure to create",
|
|
625
652
|
},
|
|
626
653
|
parameters: {
|
|
627
|
-
type:
|
|
628
|
-
description:
|
|
654
|
+
type: "array",
|
|
655
|
+
description: "Optional array of parameter definitions",
|
|
629
656
|
items: {
|
|
630
|
-
type:
|
|
657
|
+
type: "object",
|
|
631
658
|
properties: {
|
|
632
|
-
name: { type:
|
|
633
|
-
mode: {
|
|
634
|
-
|
|
659
|
+
name: { type: "string", description: "Parameter name" },
|
|
660
|
+
mode: {
|
|
661
|
+
type: "string",
|
|
662
|
+
enum: ["IN", "OUT", "INOUT"],
|
|
663
|
+
description: "Parameter mode",
|
|
664
|
+
},
|
|
665
|
+
data_type: {
|
|
666
|
+
type: "string",
|
|
667
|
+
description: "MySQL data type (e.g., VARCHAR(255), INT)",
|
|
668
|
+
},
|
|
635
669
|
},
|
|
636
|
-
required: [
|
|
670
|
+
required: ["name", "mode", "data_type"],
|
|
637
671
|
},
|
|
638
672
|
},
|
|
639
673
|
body: {
|
|
640
|
-
type:
|
|
641
|
-
description:
|
|
674
|
+
type: "string",
|
|
675
|
+
description: "SQL body of the stored procedure",
|
|
642
676
|
},
|
|
643
677
|
comment: {
|
|
644
|
-
type:
|
|
645
|
-
description:
|
|
678
|
+
type: "string",
|
|
679
|
+
description: "Optional comment for the stored procedure",
|
|
646
680
|
},
|
|
647
681
|
database: {
|
|
648
|
-
type:
|
|
649
|
-
description:
|
|
682
|
+
type: "string",
|
|
683
|
+
description: "Optional: specific database name",
|
|
650
684
|
},
|
|
651
685
|
},
|
|
652
|
-
required: [
|
|
686
|
+
required: ["procedure_name", "body"],
|
|
653
687
|
},
|
|
654
688
|
},
|
|
655
689
|
{
|
|
656
|
-
name:
|
|
657
|
-
description:
|
|
690
|
+
name: "drop_stored_procedure",
|
|
691
|
+
description: "Drops (deletes) a stored procedure. WARNING: This is irreversible!",
|
|
658
692
|
inputSchema: {
|
|
659
|
-
type:
|
|
693
|
+
type: "object",
|
|
660
694
|
properties: {
|
|
661
695
|
procedure_name: {
|
|
662
|
-
type:
|
|
663
|
-
description:
|
|
696
|
+
type: "string",
|
|
697
|
+
description: "Name of the stored procedure to drop",
|
|
664
698
|
},
|
|
665
699
|
if_exists: {
|
|
666
|
-
type:
|
|
667
|
-
description:
|
|
700
|
+
type: "boolean",
|
|
701
|
+
description: "If true, will not error if procedure does not exist",
|
|
668
702
|
},
|
|
669
703
|
database: {
|
|
670
|
-
type:
|
|
671
|
-
description:
|
|
704
|
+
type: "string",
|
|
705
|
+
description: "Optional: specific database name",
|
|
672
706
|
},
|
|
673
707
|
},
|
|
674
|
-
required: [
|
|
708
|
+
required: ["procedure_name"],
|
|
675
709
|
},
|
|
676
710
|
},
|
|
677
711
|
{
|
|
678
|
-
name:
|
|
679
|
-
description:
|
|
712
|
+
name: "show_create_procedure",
|
|
713
|
+
description: "Shows the CREATE statement for a stored procedure.",
|
|
680
714
|
inputSchema: {
|
|
681
|
-
type:
|
|
715
|
+
type: "object",
|
|
682
716
|
properties: {
|
|
683
717
|
procedure_name: {
|
|
684
|
-
type:
|
|
685
|
-
description:
|
|
718
|
+
type: "string",
|
|
719
|
+
description: "Name of the stored procedure to show CREATE statement for",
|
|
686
720
|
},
|
|
687
721
|
database: {
|
|
688
|
-
type:
|
|
689
|
-
description:
|
|
722
|
+
type: "string",
|
|
723
|
+
description: "Optional: specific database name",
|
|
690
724
|
},
|
|
691
725
|
},
|
|
692
|
-
required: [
|
|
726
|
+
required: ["procedure_name"],
|
|
693
727
|
},
|
|
694
728
|
},
|
|
695
729
|
// Data Export Tools
|
|
696
730
|
{
|
|
697
|
-
name:
|
|
698
|
-
description:
|
|
731
|
+
name: "export_table_to_csv",
|
|
732
|
+
description: "Export table data to CSV format with optional filtering, pagination, and sorting.",
|
|
699
733
|
inputSchema: {
|
|
700
|
-
type:
|
|
734
|
+
type: "object",
|
|
701
735
|
properties: {
|
|
702
736
|
table_name: {
|
|
703
|
-
type:
|
|
704
|
-
description:
|
|
737
|
+
type: "string",
|
|
738
|
+
description: "Name of the table to export",
|
|
705
739
|
},
|
|
706
740
|
filters: {
|
|
707
|
-
type:
|
|
708
|
-
description:
|
|
741
|
+
type: "array",
|
|
742
|
+
description: "Array of filter conditions",
|
|
709
743
|
items: {
|
|
710
|
-
type:
|
|
744
|
+
type: "object",
|
|
711
745
|
properties: {
|
|
712
|
-
field: { type:
|
|
746
|
+
field: { type: "string" },
|
|
713
747
|
operator: {
|
|
714
|
-
type:
|
|
715
|
-
enum: [
|
|
748
|
+
type: "string",
|
|
749
|
+
enum: ["eq", "neq", "gt", "gte", "lt", "lte", "like", "in"],
|
|
716
750
|
},
|
|
717
751
|
value: {
|
|
718
|
-
description: 'Value to compare against (can be string, number, boolean, or array for "in" operator)'
|
|
752
|
+
description: 'Value to compare against (can be string, number, boolean, or array for "in" operator)',
|
|
719
753
|
},
|
|
720
754
|
},
|
|
721
|
-
required: [
|
|
755
|
+
required: ["field", "operator", "value"],
|
|
722
756
|
},
|
|
723
757
|
},
|
|
724
758
|
pagination: {
|
|
725
|
-
type:
|
|
759
|
+
type: "object",
|
|
726
760
|
properties: {
|
|
727
|
-
page: {
|
|
728
|
-
|
|
761
|
+
page: {
|
|
762
|
+
type: "number",
|
|
763
|
+
description: "Page number (starting from 1)",
|
|
764
|
+
},
|
|
765
|
+
limit: {
|
|
766
|
+
type: "number",
|
|
767
|
+
description: "Number of records per page",
|
|
768
|
+
},
|
|
729
769
|
},
|
|
730
770
|
},
|
|
731
771
|
sorting: {
|
|
732
|
-
type:
|
|
772
|
+
type: "object",
|
|
733
773
|
properties: {
|
|
734
|
-
field: { type:
|
|
735
|
-
direction: { type:
|
|
774
|
+
field: { type: "string", description: "Field name to sort by" },
|
|
775
|
+
direction: { type: "string", enum: ["asc", "desc"] },
|
|
736
776
|
},
|
|
737
777
|
},
|
|
738
778
|
include_headers: {
|
|
739
|
-
type:
|
|
740
|
-
description:
|
|
779
|
+
type: "boolean",
|
|
780
|
+
description: "Whether to include column headers in the CSV output",
|
|
741
781
|
},
|
|
742
782
|
},
|
|
743
|
-
required: [
|
|
783
|
+
required: ["table_name"],
|
|
744
784
|
},
|
|
745
785
|
},
|
|
746
786
|
{
|
|
747
|
-
name:
|
|
748
|
-
description:
|
|
787
|
+
name: "export_query_to_csv",
|
|
788
|
+
description: "Export the results of a SELECT query to CSV format.",
|
|
749
789
|
inputSchema: {
|
|
750
|
-
type:
|
|
790
|
+
type: "object",
|
|
751
791
|
properties: {
|
|
752
792
|
query: {
|
|
753
|
-
type:
|
|
754
|
-
description:
|
|
793
|
+
type: "string",
|
|
794
|
+
description: "SQL SELECT query to execute and export",
|
|
755
795
|
},
|
|
756
796
|
params: {
|
|
757
|
-
type:
|
|
758
|
-
description:
|
|
797
|
+
type: "array",
|
|
798
|
+
description: "Optional array of parameters for parameterized queries",
|
|
759
799
|
items: {},
|
|
760
800
|
},
|
|
761
801
|
include_headers: {
|
|
762
|
-
type:
|
|
763
|
-
description:
|
|
802
|
+
type: "boolean",
|
|
803
|
+
description: "Whether to include column headers in the CSV output",
|
|
764
804
|
},
|
|
765
805
|
},
|
|
766
|
-
required: [
|
|
806
|
+
required: ["query"],
|
|
767
807
|
},
|
|
768
808
|
},
|
|
769
809
|
];
|
|
770
810
|
// Create the MCP server
|
|
771
811
|
const server = new index_js_1.Server({
|
|
772
|
-
name:
|
|
773
|
-
version:
|
|
812
|
+
name: "mysql-mcp-server",
|
|
813
|
+
version: "1.4.4",
|
|
774
814
|
}, {
|
|
775
815
|
capabilities: {
|
|
776
816
|
tools: {},
|
|
@@ -788,114 +828,114 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
788
828
|
try {
|
|
789
829
|
let result;
|
|
790
830
|
switch (name) {
|
|
791
|
-
case
|
|
831
|
+
case "list_databases":
|
|
792
832
|
result = await mysqlMCP.listDatabases();
|
|
793
833
|
break;
|
|
794
|
-
case
|
|
834
|
+
case "list_tables":
|
|
795
835
|
result = await mysqlMCP.listTables((args || {}));
|
|
796
836
|
break;
|
|
797
|
-
case
|
|
837
|
+
case "read_table_schema":
|
|
798
838
|
result = await mysqlMCP.readTableSchema((args || {}));
|
|
799
839
|
break;
|
|
800
|
-
case
|
|
840
|
+
case "create_record":
|
|
801
841
|
result = await mysqlMCP.createRecord((args || {}));
|
|
802
842
|
break;
|
|
803
|
-
case
|
|
843
|
+
case "read_records":
|
|
804
844
|
result = await mysqlMCP.readRecords((args || {}));
|
|
805
845
|
break;
|
|
806
|
-
case
|
|
846
|
+
case "update_record":
|
|
807
847
|
result = await mysqlMCP.updateRecord((args || {}));
|
|
808
848
|
break;
|
|
809
|
-
case
|
|
849
|
+
case "delete_record":
|
|
810
850
|
result = await mysqlMCP.deleteRecord((args || {}));
|
|
811
851
|
break;
|
|
812
|
-
case
|
|
852
|
+
case "bulk_insert":
|
|
813
853
|
result = await mysqlMCP.bulkInsert((args || {}));
|
|
814
854
|
break;
|
|
815
|
-
case
|
|
855
|
+
case "bulk_update":
|
|
816
856
|
result = await mysqlMCP.bulkUpdate((args || {}));
|
|
817
857
|
break;
|
|
818
|
-
case
|
|
858
|
+
case "bulk_delete":
|
|
819
859
|
result = await mysqlMCP.bulkDelete((args || {}));
|
|
820
860
|
break;
|
|
821
|
-
case
|
|
861
|
+
case "run_query":
|
|
822
862
|
result = await mysqlMCP.runQuery((args || {}));
|
|
823
863
|
break;
|
|
824
|
-
case
|
|
864
|
+
case "execute_sql":
|
|
825
865
|
result = await mysqlMCP.executeSql((args || {}));
|
|
826
866
|
break;
|
|
827
|
-
case
|
|
867
|
+
case "create_table":
|
|
828
868
|
result = await mysqlMCP.createTable(args || {});
|
|
829
869
|
break;
|
|
830
|
-
case
|
|
870
|
+
case "alter_table":
|
|
831
871
|
result = await mysqlMCP.alterTable(args || {});
|
|
832
872
|
break;
|
|
833
|
-
case
|
|
873
|
+
case "drop_table":
|
|
834
874
|
result = await mysqlMCP.dropTable(args || {});
|
|
835
875
|
break;
|
|
836
|
-
case
|
|
876
|
+
case "execute_ddl":
|
|
837
877
|
result = await mysqlMCP.executeDdl((args || {}));
|
|
838
878
|
break;
|
|
839
|
-
case
|
|
879
|
+
case "describe_connection":
|
|
840
880
|
result = await mysqlMCP.describeConnection();
|
|
841
881
|
break;
|
|
842
|
-
case
|
|
882
|
+
case "test_connection":
|
|
843
883
|
result = await mysqlMCP.testConnection();
|
|
844
884
|
break;
|
|
845
|
-
case
|
|
885
|
+
case "get_table_relationships":
|
|
846
886
|
result = await mysqlMCP.getTableRelationships((args || {}));
|
|
847
887
|
break;
|
|
848
888
|
// Transaction Tools
|
|
849
|
-
case
|
|
889
|
+
case "begin_transaction":
|
|
850
890
|
result = await mysqlMCP.beginTransaction((args || {}));
|
|
851
891
|
break;
|
|
852
|
-
case
|
|
892
|
+
case "commit_transaction":
|
|
853
893
|
result = await mysqlMCP.commitTransaction((args || {}));
|
|
854
894
|
break;
|
|
855
|
-
case
|
|
895
|
+
case "rollback_transaction":
|
|
856
896
|
result = await mysqlMCP.rollbackTransaction((args || {}));
|
|
857
897
|
break;
|
|
858
|
-
case
|
|
898
|
+
case "get_transaction_status":
|
|
859
899
|
result = await mysqlMCP.getTransactionStatus();
|
|
860
900
|
break;
|
|
861
|
-
case
|
|
901
|
+
case "execute_in_transaction":
|
|
862
902
|
result = await mysqlMCP.executeInTransaction((args || {}));
|
|
863
903
|
break;
|
|
864
904
|
// Stored Procedure Tools
|
|
865
|
-
case
|
|
905
|
+
case "list_stored_procedures":
|
|
866
906
|
result = await mysqlMCP.listStoredProcedures((args || {}));
|
|
867
907
|
break;
|
|
868
|
-
case
|
|
908
|
+
case "get_stored_procedure_info":
|
|
869
909
|
result = await mysqlMCP.getStoredProcedureInfo((args || {}));
|
|
870
910
|
break;
|
|
871
|
-
case
|
|
911
|
+
case "execute_stored_procedure":
|
|
872
912
|
result = await mysqlMCP.executeStoredProcedure((args || {}));
|
|
873
913
|
break;
|
|
874
|
-
case
|
|
914
|
+
case "create_stored_procedure":
|
|
875
915
|
result = await mysqlMCP.createStoredProcedure((args || {}));
|
|
876
916
|
break;
|
|
877
|
-
case
|
|
917
|
+
case "drop_stored_procedure":
|
|
878
918
|
result = await mysqlMCP.dropStoredProcedure((args || {}));
|
|
879
919
|
break;
|
|
880
|
-
case
|
|
920
|
+
case "show_create_procedure":
|
|
881
921
|
result = await mysqlMCP.showCreateProcedure((args || {}));
|
|
882
922
|
break;
|
|
883
923
|
// Data Export Tools
|
|
884
|
-
case
|
|
924
|
+
case "export_table_to_csv":
|
|
885
925
|
result = await mysqlMCP.exportTableToCSV((args || {}));
|
|
886
926
|
break;
|
|
887
|
-
case
|
|
927
|
+
case "export_query_to_csv":
|
|
888
928
|
result = await mysqlMCP.exportQueryToCSV((args || {}));
|
|
889
929
|
break;
|
|
890
930
|
default:
|
|
891
931
|
throw new Error(`Unknown tool: ${name}`);
|
|
892
932
|
}
|
|
893
933
|
// Handle the result based on status
|
|
894
|
-
if (result.status ===
|
|
934
|
+
if (result.status === "error") {
|
|
895
935
|
return {
|
|
896
936
|
content: [
|
|
897
937
|
{
|
|
898
|
-
type:
|
|
938
|
+
type: "text",
|
|
899
939
|
text: `Error: ${result.error}`,
|
|
900
940
|
},
|
|
901
941
|
],
|
|
@@ -904,23 +944,23 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
904
944
|
}
|
|
905
945
|
// Return successful result - handle different result types
|
|
906
946
|
let responseData;
|
|
907
|
-
if (
|
|
947
|
+
if ("data" in result) {
|
|
908
948
|
// Standard result with data property
|
|
909
949
|
responseData = result.data;
|
|
910
950
|
}
|
|
911
|
-
else if (
|
|
951
|
+
else if ("transactionId" in result) {
|
|
912
952
|
// Transaction result
|
|
913
953
|
responseData = {
|
|
914
|
-
transactionId: result.transactionId
|
|
954
|
+
transactionId: result.transactionId,
|
|
915
955
|
};
|
|
916
|
-
if (
|
|
956
|
+
if ("message" in result && result.message) {
|
|
917
957
|
responseData.message = result.message;
|
|
918
958
|
}
|
|
919
|
-
if (
|
|
959
|
+
if ("activeTransactions" in result && result.activeTransactions) {
|
|
920
960
|
responseData.activeTransactions = result.activeTransactions;
|
|
921
961
|
}
|
|
922
962
|
}
|
|
923
|
-
else if (
|
|
963
|
+
else if ("message" in result) {
|
|
924
964
|
// Simple message result
|
|
925
965
|
responseData = { message: result.message };
|
|
926
966
|
}
|
|
@@ -931,7 +971,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
931
971
|
return {
|
|
932
972
|
content: [
|
|
933
973
|
{
|
|
934
|
-
type:
|
|
974
|
+
type: "text",
|
|
935
975
|
text: JSON.stringify(responseData, null, 2),
|
|
936
976
|
},
|
|
937
977
|
],
|
|
@@ -939,11 +979,11 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
939
979
|
}
|
|
940
980
|
catch (error) {
|
|
941
981
|
// Check if this is a permission error
|
|
942
|
-
if (error.message && error.message.includes(
|
|
982
|
+
if (error.message && error.message.includes("Permission denied")) {
|
|
943
983
|
return {
|
|
944
984
|
content: [
|
|
945
985
|
{
|
|
946
|
-
type:
|
|
986
|
+
type: "text",
|
|
947
987
|
text: `❌ ${error.message}`,
|
|
948
988
|
},
|
|
949
989
|
],
|
|
@@ -954,7 +994,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
954
994
|
return {
|
|
955
995
|
content: [
|
|
956
996
|
{
|
|
957
|
-
type:
|
|
997
|
+
type: "text",
|
|
958
998
|
text: `Error executing tool: ${error.message}`,
|
|
959
999
|
},
|
|
960
1000
|
],
|
|
@@ -966,10 +1006,20 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
966
1006
|
async function main() {
|
|
967
1007
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
968
1008
|
await server.connect(transport);
|
|
1009
|
+
// Initialize the MySQL MCP instance AFTER transport is connected
|
|
1010
|
+
// This ensures the database connection pool is created when the server is ready
|
|
1011
|
+
mysqlMCP = new index_js_2.MySQLMCP(permissions);
|
|
1012
|
+
// Log the effective permissions to stderr
|
|
1013
|
+
if (permissions) {
|
|
1014
|
+
console.error(`Active permissions: ${permissions}`);
|
|
1015
|
+
}
|
|
1016
|
+
else {
|
|
1017
|
+
console.error("Active permissions: all (default)");
|
|
1018
|
+
}
|
|
969
1019
|
// Log to stderr (not stdout, which is used for MCP protocol)
|
|
970
|
-
console.error(
|
|
1020
|
+
console.error("MySQL MCP Server running on stdio");
|
|
971
1021
|
}
|
|
972
1022
|
main().catch((error) => {
|
|
973
|
-
console.error(
|
|
1023
|
+
console.error("Fatal error in main():", error);
|
|
974
1024
|
process.exit(1);
|
|
975
1025
|
});
|