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