@berthojoris/mcp-mysql-server 1.0.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.
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UtilityTools = void 0;
7
+ const connection_1 = __importDefault(require("../db/connection"));
8
+ const config_1 = require("../config/config");
9
+ const schemas_1 = require("../validation/schemas");
10
+ class UtilityTools {
11
+ constructor() {
12
+ this.db = connection_1.default.getInstance();
13
+ }
14
+ /**
15
+ * Returns the current database connection info
16
+ */
17
+ async describeConnection() {
18
+ try {
19
+ // Return connection info without sensitive data
20
+ const connectionInfo = {
21
+ host: config_1.dbConfig.host,
22
+ port: config_1.dbConfig.port,
23
+ user: config_1.dbConfig.user,
24
+ database: config_1.dbConfig.database,
25
+ // Exclude password for security
26
+ };
27
+ return {
28
+ status: 'success',
29
+ data: connectionInfo
30
+ };
31
+ }
32
+ catch (error) {
33
+ return {
34
+ status: 'error',
35
+ error: error.message
36
+ };
37
+ }
38
+ }
39
+ /**
40
+ * Tests the DB connection and returns latency
41
+ */
42
+ async testConnection() {
43
+ try {
44
+ const result = await this.db.testConnection();
45
+ return {
46
+ status: result.connected ? 'success' : 'error',
47
+ data: {
48
+ connected: result.connected,
49
+ latency: result.latency
50
+ }
51
+ };
52
+ }
53
+ catch (error) {
54
+ return {
55
+ status: 'error',
56
+ error: error.message
57
+ };
58
+ }
59
+ }
60
+ /**
61
+ * Detects and describes foreign key relationships between tables
62
+ */
63
+ async getTableRelationships(params) {
64
+ // Validate input
65
+ if (!(0, schemas_1.validateGetTableRelationships)(params)) {
66
+ return {
67
+ status: 'error',
68
+ error: 'Invalid parameters: ' + JSON.stringify(schemas_1.validateGetTableRelationships.errors)
69
+ };
70
+ }
71
+ try {
72
+ const { table_name } = params;
73
+ // Query to get foreign keys where this table is the parent
74
+ const parentQuery = `
75
+ SELECT
76
+ TABLE_NAME as child_table,
77
+ COLUMN_NAME as child_column,
78
+ REFERENCED_TABLE_NAME as parent_table,
79
+ REFERENCED_COLUMN_NAME as parent_column,
80
+ CONSTRAINT_NAME as constraint_name
81
+ FROM
82
+ INFORMATION_SCHEMA.KEY_COLUMN_USAGE
83
+ WHERE
84
+ REFERENCED_TABLE_NAME = ?
85
+ AND REFERENCED_TABLE_SCHEMA = DATABASE()
86
+ `;
87
+ // Query to get foreign keys where this table is the child
88
+ const childQuery = `
89
+ SELECT
90
+ TABLE_NAME as child_table,
91
+ COLUMN_NAME as child_column,
92
+ REFERENCED_TABLE_NAME as parent_table,
93
+ REFERENCED_COLUMN_NAME as parent_column,
94
+ CONSTRAINT_NAME as constraint_name
95
+ FROM
96
+ INFORMATION_SCHEMA.KEY_COLUMN_USAGE
97
+ WHERE
98
+ TABLE_NAME = ?
99
+ AND REFERENCED_TABLE_NAME IS NOT NULL
100
+ AND TABLE_SCHEMA = DATABASE()
101
+ `;
102
+ // Execute both queries
103
+ const parentRelationships = await this.db.query(parentQuery, [table_name]);
104
+ const childRelationships = await this.db.query(childQuery, [table_name]);
105
+ return {
106
+ status: 'success',
107
+ data: {
108
+ as_parent: parentRelationships,
109
+ as_child: childRelationships
110
+ }
111
+ };
112
+ }
113
+ catch (error) {
114
+ return {
115
+ status: 'error',
116
+ error: error.message
117
+ };
118
+ }
119
+ }
120
+ }
121
+ exports.UtilityTools = UtilityTools;
@@ -0,0 +1,423 @@
1
+ export interface TableInfo {
2
+ table_name: string;
3
+ }
4
+ export interface ColumnInfo {
5
+ column_name: string;
6
+ data_type: string;
7
+ is_nullable: string;
8
+ column_key: string;
9
+ column_default: string | null;
10
+ extra: string;
11
+ }
12
+ export interface FilterCondition {
13
+ field: string;
14
+ operator: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'in';
15
+ value: any;
16
+ }
17
+ export interface Pagination {
18
+ page: number;
19
+ limit: number;
20
+ }
21
+ export interface Sorting {
22
+ field: string;
23
+ direction: 'asc' | 'desc';
24
+ }
25
+ export declare const listTablesSchema: {
26
+ type: string;
27
+ properties: {
28
+ database: {
29
+ type: string;
30
+ nullable: boolean;
31
+ };
32
+ };
33
+ additionalProperties: boolean;
34
+ };
35
+ export declare const readTableSchemaSchema: {
36
+ type: string;
37
+ required: string[];
38
+ properties: {
39
+ table_name: {
40
+ type: string;
41
+ };
42
+ };
43
+ additionalProperties: boolean;
44
+ };
45
+ export declare const createRecordSchema: {
46
+ type: string;
47
+ required: string[];
48
+ properties: {
49
+ table_name: {
50
+ type: string;
51
+ };
52
+ data: {
53
+ type: string;
54
+ additionalProperties: boolean;
55
+ };
56
+ };
57
+ additionalProperties: boolean;
58
+ };
59
+ export declare const readRecordsSchema: {
60
+ type: string;
61
+ required: string[];
62
+ properties: {
63
+ table_name: {
64
+ type: string;
65
+ };
66
+ filters: {
67
+ type: string;
68
+ items: {
69
+ type: string;
70
+ required: string[];
71
+ properties: {
72
+ field: {
73
+ type: string;
74
+ };
75
+ operator: {
76
+ type: string;
77
+ enum: string[];
78
+ };
79
+ value: {};
80
+ };
81
+ };
82
+ nullable: boolean;
83
+ };
84
+ pagination: {
85
+ type: string;
86
+ properties: {
87
+ page: {
88
+ type: string;
89
+ minimum: number;
90
+ };
91
+ limit: {
92
+ type: string;
93
+ minimum: number;
94
+ maximum: number;
95
+ };
96
+ };
97
+ required: string[];
98
+ nullable: boolean;
99
+ };
100
+ sorting: {
101
+ type: string;
102
+ properties: {
103
+ field: {
104
+ type: string;
105
+ };
106
+ direction: {
107
+ type: string;
108
+ enum: string[];
109
+ };
110
+ };
111
+ required: string[];
112
+ nullable: boolean;
113
+ };
114
+ };
115
+ additionalProperties: boolean;
116
+ };
117
+ export declare const updateRecordSchema: {
118
+ type: string;
119
+ required: string[];
120
+ properties: {
121
+ table_name: {
122
+ type: string;
123
+ };
124
+ data: {
125
+ type: string;
126
+ additionalProperties: boolean;
127
+ };
128
+ conditions: {
129
+ type: string;
130
+ items: {
131
+ type: string;
132
+ required: string[];
133
+ properties: {
134
+ field: {
135
+ type: string;
136
+ };
137
+ operator: {
138
+ type: string;
139
+ enum: string[];
140
+ };
141
+ value: {};
142
+ };
143
+ };
144
+ };
145
+ };
146
+ additionalProperties: boolean;
147
+ };
148
+ export declare const deleteRecordSchema: {
149
+ type: string;
150
+ required: string[];
151
+ properties: {
152
+ table_name: {
153
+ type: string;
154
+ };
155
+ conditions: {
156
+ type: string;
157
+ items: {
158
+ type: string;
159
+ required: string[];
160
+ properties: {
161
+ field: {
162
+ type: string;
163
+ };
164
+ operator: {
165
+ type: string;
166
+ enum: string[];
167
+ };
168
+ value: {};
169
+ };
170
+ };
171
+ };
172
+ };
173
+ additionalProperties: boolean;
174
+ };
175
+ export declare const runQuerySchema: {
176
+ type: string;
177
+ required: string[];
178
+ properties: {
179
+ query: {
180
+ type: string;
181
+ };
182
+ params: {
183
+ type: string;
184
+ items: {};
185
+ nullable: boolean;
186
+ };
187
+ };
188
+ additionalProperties: boolean;
189
+ };
190
+ export declare const getTableRelationshipsSchema: {
191
+ type: string;
192
+ required: string[];
193
+ properties: {
194
+ table_name: {
195
+ type: string;
196
+ };
197
+ };
198
+ additionalProperties: boolean;
199
+ };
200
+ export declare const beginTransactionSchema: {
201
+ type: string;
202
+ properties: {
203
+ transactionId: {
204
+ type: string;
205
+ nullable: boolean;
206
+ };
207
+ };
208
+ additionalProperties: boolean;
209
+ };
210
+ export declare const commitTransactionSchema: {
211
+ type: string;
212
+ required: string[];
213
+ properties: {
214
+ transactionId: {
215
+ type: string;
216
+ };
217
+ };
218
+ additionalProperties: boolean;
219
+ };
220
+ export declare const rollbackTransactionSchema: {
221
+ type: string;
222
+ required: string[];
223
+ properties: {
224
+ transactionId: {
225
+ type: string;
226
+ };
227
+ };
228
+ additionalProperties: boolean;
229
+ };
230
+ export declare const getTransactionStatusSchema: {
231
+ type: string;
232
+ properties: {};
233
+ additionalProperties: boolean;
234
+ };
235
+ export declare const executeInTransactionSchema: {
236
+ type: string;
237
+ required: string[];
238
+ properties: {
239
+ transactionId: {
240
+ type: string;
241
+ };
242
+ query: {
243
+ type: string;
244
+ };
245
+ params: {
246
+ type: string;
247
+ items: {};
248
+ nullable: boolean;
249
+ };
250
+ };
251
+ additionalProperties: boolean;
252
+ };
253
+ export declare const listStoredProceduresSchema: {
254
+ type: string;
255
+ properties: {
256
+ database: {
257
+ type: string;
258
+ nullable: boolean;
259
+ };
260
+ };
261
+ additionalProperties: boolean;
262
+ };
263
+ export declare const getStoredProcedureInfoSchema: {
264
+ type: string;
265
+ required: string[];
266
+ properties: {
267
+ procedure_name: {
268
+ type: string;
269
+ };
270
+ database: {
271
+ type: string;
272
+ nullable: boolean;
273
+ };
274
+ };
275
+ additionalProperties: boolean;
276
+ };
277
+ export declare const executeStoredProcedureSchema: {
278
+ type: string;
279
+ required: string[];
280
+ properties: {
281
+ procedure_name: {
282
+ type: string;
283
+ };
284
+ parameters: {
285
+ type: string;
286
+ items: {};
287
+ nullable: boolean;
288
+ };
289
+ database: {
290
+ type: string;
291
+ nullable: boolean;
292
+ };
293
+ };
294
+ additionalProperties: boolean;
295
+ };
296
+ export declare const createStoredProcedureSchema: {
297
+ type: string;
298
+ required: string[];
299
+ properties: {
300
+ procedure_name: {
301
+ type: string;
302
+ };
303
+ parameters: {
304
+ type: string;
305
+ items: {
306
+ type: string;
307
+ required: string[];
308
+ properties: {
309
+ name: {
310
+ type: string;
311
+ };
312
+ mode: {
313
+ type: string;
314
+ enum: string[];
315
+ };
316
+ data_type: {
317
+ type: string;
318
+ };
319
+ };
320
+ };
321
+ nullable: boolean;
322
+ };
323
+ body: {
324
+ type: string;
325
+ };
326
+ comment: {
327
+ type: string;
328
+ nullable: boolean;
329
+ };
330
+ database: {
331
+ type: string;
332
+ nullable: boolean;
333
+ };
334
+ };
335
+ additionalProperties: boolean;
336
+ };
337
+ export declare const dropStoredProcedureSchema: {
338
+ type: string;
339
+ required: string[];
340
+ properties: {
341
+ procedure_name: {
342
+ type: string;
343
+ };
344
+ if_exists: {
345
+ type: string;
346
+ nullable: boolean;
347
+ };
348
+ database: {
349
+ type: string;
350
+ nullable: boolean;
351
+ };
352
+ };
353
+ additionalProperties: boolean;
354
+ };
355
+ export declare const showCreateProcedureSchema: {
356
+ type: string;
357
+ required: string[];
358
+ properties: {
359
+ procedure_name: {
360
+ type: string;
361
+ };
362
+ database: {
363
+ type: string;
364
+ nullable: boolean;
365
+ };
366
+ };
367
+ additionalProperties: boolean;
368
+ };
369
+ export declare const validateListTables: import("ajv").ValidateFunction<{
370
+ database: unknown;
371
+ } & {}>;
372
+ export declare const validateReadTableSchema: import("ajv").ValidateFunction<{
373
+ [x: string]: {};
374
+ }>;
375
+ export declare const validateCreateRecord: import("ajv").ValidateFunction<{
376
+ [x: string]: {};
377
+ }>;
378
+ export declare const validateReadRecords: import("ajv").ValidateFunction<{
379
+ [x: string]: {};
380
+ }>;
381
+ export declare const validateUpdateRecord: import("ajv").ValidateFunction<{
382
+ [x: string]: {};
383
+ }>;
384
+ export declare const validateDeleteRecord: import("ajv").ValidateFunction<{
385
+ [x: string]: {};
386
+ }>;
387
+ export declare const validateRunQuery: import("ajv").ValidateFunction<{
388
+ [x: string]: {};
389
+ }>;
390
+ export declare const validateGetTableRelationships: import("ajv").ValidateFunction<{
391
+ [x: string]: {};
392
+ }>;
393
+ export declare const validateBeginTransaction: import("ajv").ValidateFunction<{
394
+ transactionId: unknown;
395
+ } & {}>;
396
+ export declare const validateCommitTransaction: import("ajv").ValidateFunction<{
397
+ [x: string]: {};
398
+ }>;
399
+ export declare const validateRollbackTransaction: import("ajv").ValidateFunction<{
400
+ [x: string]: {};
401
+ }>;
402
+ export declare const validateGetTransactionStatus: import("ajv").ValidateFunction<{} & {}>;
403
+ export declare const validateExecuteInTransaction: import("ajv").ValidateFunction<{
404
+ [x: string]: {};
405
+ }>;
406
+ export declare const validateListStoredProcedures: import("ajv").ValidateFunction<{
407
+ database: unknown;
408
+ } & {}>;
409
+ export declare const validateGetStoredProcedureInfo: import("ajv").ValidateFunction<{
410
+ [x: string]: {};
411
+ }>;
412
+ export declare const validateStoredProcedureExecution: import("ajv").ValidateFunction<{
413
+ [x: string]: {};
414
+ }>;
415
+ export declare const validateStoredProcedureCreation: import("ajv").ValidateFunction<{
416
+ [x: string]: {};
417
+ }>;
418
+ export declare const validateDropStoredProcedure: import("ajv").ValidateFunction<{
419
+ [x: string]: {};
420
+ }>;
421
+ export declare const validateShowCreateProcedure: import("ajv").ValidateFunction<{
422
+ [x: string]: {};
423
+ }>;