@adevguide/mcp-database-server 1.0.2 β 1.0.3
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/README.md +1180 -1049
- package/dist/index.js +658 -23
- package/dist/index.js.map +1 -1
- package/mcp-database-server.config.example +59 -59
- package/package.json +78 -79
package/README.md
CHANGED
|
@@ -1,1050 +1,1181 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
β
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
|
185
|
-
|
|
186
|
-
| `
|
|
187
|
-
| `
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
**
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
|
202
|
-
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
|
|
206
|
-
**
|
|
207
|
-
- **
|
|
208
|
-
- **
|
|
209
|
-
- **
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
"
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
"
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
"
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
"id": "
|
|
320
|
-
"type": "
|
|
321
|
-
"
|
|
322
|
-
"readOnly":
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
mysql://user:pass@host:3306/
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
**
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
|
545
|
-
|
|
546
|
-
| `
|
|
547
|
-
| `
|
|
548
|
-
| `
|
|
549
|
-
| `
|
|
550
|
-
| `
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
```
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
**
|
|
770
|
-
```json
|
|
771
|
-
{
|
|
772
|
-
"
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
{
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
"
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
-
|
|
1028
|
-
-
|
|
1029
|
-
-
|
|
1030
|
-
-
|
|
1031
|
-
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1
|
+
# @adevguide/mcp-database-server
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@adevguide/mcp-database-server)
|
|
4
|
+
[](https://www.npmjs.com/package/@adevguide/mcp-database-server)
|
|
5
|
+
|
|
6
|
+
Production-grade Model Context Protocol (MCP) server for unified SQL database access. Connect multiple databases through a single MCP server with schema discovery, relationship mapping, caching, and safety controls.
|
|
7
|
+
|
|
8
|
+
- npm: https://www.npmjs.com/package/@adevguide/mcp-database-server
|
|
9
|
+
- GitHub: https://github.com/iPraBhu/mcp-database-server
|
|
10
|
+
|
|
11
|
+
## Contents
|
|
12
|
+
|
|
13
|
+
- [Features](#features)
|
|
14
|
+
- [Why this exists](#why-this-exists)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Configuration](#configuration)
|
|
17
|
+
- [MCP client integration](#mcp-client-integration)
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Multi-database support: PostgreSQL, MySQL/MariaDB, SQLite, SQL Server, Oracle
|
|
22
|
+
- Automatic schema discovery: tables, columns, indexes, foreign keys, relationships
|
|
23
|
+
- Persistent schema caching: TTL + versioning, manual refresh, cache stats
|
|
24
|
+
- Relationship inference: foreign keys + heuristics
|
|
25
|
+
- Query intelligence: tracking, statistics, timeouts
|
|
26
|
+
- Join assistance: suggested join paths based on relationship graphs
|
|
27
|
+
- Safety controls: read-only mode, allow/deny write operations, secret redaction
|
|
28
|
+
- **Query optimization**: index recommendations, performance profiling, slow query detection
|
|
29
|
+
- **Performance monitoring**: detailed execution analytics, bottleneck identification
|
|
30
|
+
- **Query rewriting**: automated optimization suggestions with performance impact estimates
|
|
31
|
+
|
|
32
|
+
## Why this exists
|
|
33
|
+
|
|
34
|
+
This project was originally vibe-coded to solve real issues I was facing when wiring LLM tools to multiple SQL databases (consistent connectivity, schema discovery, and safe query execution). It has since been hardened into a reusable MCP server with caching and security defaults.
|
|
35
|
+
|
|
36
|
+
## Architecture
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
40
|
+
β MCP Client β
|
|
41
|
+
β (Claude Desktop, IDEs, etc.) β
|
|
42
|
+
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
|
|
43
|
+
β JSON-RPC over stdio
|
|
44
|
+
ββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
|
|
45
|
+
β MCP Database Server β
|
|
46
|
+
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
|
47
|
+
β β Schema Cache (TTL + Versioning) β β
|
|
48
|
+
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
|
49
|
+
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
|
50
|
+
β β Query Tracker (History + Statistics) β β
|
|
51
|
+
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
|
52
|
+
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
|
53
|
+
β β Security Layer (Read-only, Operation Controls) β β
|
|
54
|
+
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
|
55
|
+
ββββββ¬ββββββββββ¬ββββββββββ¬βββββββββββ¬βββββββββββ¬ββββββββββ
|
|
56
|
+
β β β β β
|
|
57
|
+
ββββββΌββββ ββββΌβββββ ββββΌββββββ ββββΌβββββββ ββΌβββββββββ
|
|
58
|
+
βPostgresβ β MySQL β β SQLite β β MSSQL β β Oracle β
|
|
59
|
+
ββββββββββ βββββββββ ββββββββββ βββββββββββ βββββββββββ
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Supported Databases
|
|
63
|
+
|
|
64
|
+
| Database | Driver | Status | Notes |
|
|
65
|
+
|----------|--------|--------|-------|
|
|
66
|
+
| PostgreSQL | `pg` | β
Full Support | Includes CockroachDB compatibility |
|
|
67
|
+
| MySQL/MariaDB | `mysql2` | β
Full Support | Includes Amazon Aurora MySQL compatibility |
|
|
68
|
+
| SQLite | `better-sqlite3` | β
Full Support | File-based databases |
|
|
69
|
+
| SQL Server | `tedious` | β
Full Support | Microsoft SQL Server / Azure SQL |
|
|
70
|
+
| Oracle | `oracledb` | β οΈ Stub | Requires Oracle Instant Client |
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
### Global install (recommended)
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm install -g @adevguide/mcp-database-server
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Run:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
mcp-database-server --config /absolute/path/to/.mcp-database-server.config
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Run via npx (no global install)
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npx -y @adevguide/mcp-database-server --config /absolute/path/to/.mcp-database-server.config
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Install from source
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
git clone https://github.com/iPraBhu/mcp-database-server.git
|
|
96
|
+
cd mcp-database-server
|
|
97
|
+
npm install
|
|
98
|
+
npm run build
|
|
99
|
+
node dist/index.js --config ./.mcp-database-server.config
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
Create a `.mcp-database-server.config` file in your project root:
|
|
105
|
+
|
|
106
|
+
> **Note:** The config file is automatically discovered! If you don't specify `--config`, the tool first tries to locate your project root (by looking for `package.json`, `.git`, etc.) and searches for `.mcp-database-server.config` starting from there and moving up. If no project root is found, it searches from the current directory. This means you can run the tool from any subdirectory of your project and it will find the config file.
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"databases": [
|
|
111
|
+
{
|
|
112
|
+
"id": "postgres-main",
|
|
113
|
+
"type": "postgres",
|
|
114
|
+
"url": "${DB_URL_POSTGRES}",
|
|
115
|
+
"readOnly": false,
|
|
116
|
+
"pool": {
|
|
117
|
+
"min": 2,
|
|
118
|
+
"max": 10,
|
|
119
|
+
"idleTimeoutMillis": 30000
|
|
120
|
+
},
|
|
121
|
+
"introspection": {
|
|
122
|
+
"includeViews": true,
|
|
123
|
+
"excludeSchemas": ["pg_catalog"]
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"id": "sqlite-local",
|
|
128
|
+
"type": "sqlite",
|
|
129
|
+
"path": "./data/app.db"
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
"cache": {
|
|
133
|
+
"directory": ".sql-mcp-cache",
|
|
134
|
+
"ttlMinutes": 10
|
|
135
|
+
},
|
|
136
|
+
"security": {
|
|
137
|
+
"allowWrite": false,
|
|
138
|
+
"allowedWriteOperations": ["INSERT", "UPDATE"],
|
|
139
|
+
"disableDangerousOperations": true,
|
|
140
|
+
"redactSecrets": true
|
|
141
|
+
},
|
|
142
|
+
"logging": {
|
|
143
|
+
"level": "info",
|
|
144
|
+
"pretty": false
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Configuration Reference
|
|
150
|
+
|
|
151
|
+
#### Database Configuration
|
|
152
|
+
|
|
153
|
+
Each database in the `databases` array represents a connection to a SQL database.
|
|
154
|
+
|
|
155
|
+
##### Core Properties
|
|
156
|
+
|
|
157
|
+
| Property | Type | Required | Default | Description |
|
|
158
|
+
|----------|------|----------|---------|-------------|
|
|
159
|
+
| `id` | string | β
Yes | - | Unique identifier for this database connection. Used in all MCP tool calls. Must be unique across all databases. |
|
|
160
|
+
| `type` | enum | β
Yes | - | Database system type. Valid values: `postgres`, `mysql`, `sqlite`, `mssql`, `oracle` |
|
|
161
|
+
| `url` | string | Conditional* | - | Database connection string. Required for all databases except SQLite. Supports environment variable interpolation: `${DB_URL}` |
|
|
162
|
+
| `path` | string | Conditional** | - | Filesystem path to SQLite database file. Required only for `type: sqlite`. Can be relative or absolute. |
|
|
163
|
+
| `readOnly` | boolean | No | `true` | When `true`, blocks all write operations (INSERT, UPDATE, DELETE, etc.). Recommended for production safety. |
|
|
164
|
+
| `eagerConnect` | boolean | No | `false` | When `true`, connects to database immediately at startup (fail-fast). When `false`, connects on first query (lazy loading). |
|
|
165
|
+
|
|
166
|
+
<sub>* Required for postgres, mysql, mssql, oracle</sub>
|
|
167
|
+
<sub>** Required for sqlite only</sub>
|
|
168
|
+
|
|
169
|
+
**Connection String Formats:**
|
|
170
|
+
```
|
|
171
|
+
PostgreSQL: postgresql://username:password@host:5432/database
|
|
172
|
+
MySQL: mysql://username:password@host:3306/database
|
|
173
|
+
SQL Server: Server=host,1433;Database=dbname;User Id=user;Password=pass
|
|
174
|
+
SQLite: (use path property instead)
|
|
175
|
+
Oracle: username/password@host:1521/servicename
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
##### Connection Pool Configuration
|
|
179
|
+
|
|
180
|
+
The `pool` object controls connection pooling behavior. Improves performance by reusing database connections.
|
|
181
|
+
|
|
182
|
+
| Property | Type | Required | Default | Description |
|
|
183
|
+
|----------|------|----------|---------|-------------|
|
|
184
|
+
| `min` | number | No | `2` | Minimum number of connections to maintain in the pool. Kept alive even when idle. |
|
|
185
|
+
| `max` | number | No | `10` | Maximum number of concurrent connections. Do not exceed your database's connection limit. |
|
|
186
|
+
| `idleTimeoutMillis` | number | No | `30000` | Time (ms) to keep idle connections alive before closing. Example: `60000` = 1 minute. |
|
|
187
|
+
| `connectionTimeoutMillis` | number | No | `10000` | Time (ms) to wait when establishing a connection before timing out. Fail-fast if database is unreachable. |
|
|
188
|
+
|
|
189
|
+
**Recommendations:**
|
|
190
|
+
- **Development:** `min: 1`, `max: 5`
|
|
191
|
+
- **Production (Low Traffic):** `min: 2`, `max: 10`
|
|
192
|
+
- **Production (High Traffic):** `min: 5`, `max: 20`
|
|
193
|
+
|
|
194
|
+
##### Introspection Configuration
|
|
195
|
+
|
|
196
|
+
The `introspection` object controls schema discovery behavior. Determines what database objects are analyzed.
|
|
197
|
+
|
|
198
|
+
| Property | Type | Required | Default | Description |
|
|
199
|
+
|----------|------|----------|---------|-------------|
|
|
200
|
+
| `includeViews` | boolean | No | `true` | Include database views in schema discovery. Set to `false` if views cause performance issues. |
|
|
201
|
+
| `includeRoutines` | boolean | No | `false` | Include stored procedures and functions. (Not fully implemented - planned feature) |
|
|
202
|
+
| `maxTables` | number | No | unlimited | Limit introspection to first N tables. Useful for databases with 1000+ tables. May result in incomplete relationship discovery. |
|
|
203
|
+
| `includeSchemas` | string[] | No | all | Whitelist of schemas to introspect. Only applicable to PostgreSQL and SQL Server. Example: `["public", "app"]` |
|
|
204
|
+
| `excludeSchemas` | string[] | No | none | Blacklist of schemas to skip. Common values: `["pg_catalog", "information_schema", "sys"]` |
|
|
205
|
+
|
|
206
|
+
**Schema vs Database:**
|
|
207
|
+
- **PostgreSQL/SQL Server:** Support multiple schemas per database. Use `includeSchemas`/`excludeSchemas`.
|
|
208
|
+
- **MySQL/MariaDB:** Schema = database. Use database name in connection string.
|
|
209
|
+
- **SQLite:** Single-file database, no schema concept.
|
|
210
|
+
|
|
211
|
+
#### Cache Configuration
|
|
212
|
+
|
|
213
|
+
Controls schema metadata caching to improve startup performance and reduce database load.
|
|
214
|
+
|
|
215
|
+
| Property | Type | Required | Default | Description |
|
|
216
|
+
|----------|------|----------|---------|-------------|
|
|
217
|
+
| `directory` | string | No | `.sql-mcp-cache` | Directory path where cached schema files are stored. One JSON file per database. |
|
|
218
|
+
| `ttlMinutes` | number | No | `10` | Time-To-Live in minutes. How long cached schema is considered valid before automatic refresh. |
|
|
219
|
+
|
|
220
|
+
**Cache Behavior:**
|
|
221
|
+
- **On Startup:** Loads schema from cache if available and not expired
|
|
222
|
+
- **After TTL Expiry:** Next query triggers automatic re-introspection
|
|
223
|
+
- **Manual Refresh:** Use `clear_cache` tool or `introspect_schema` with `forceRefresh: true`
|
|
224
|
+
- **Cache Files:** Stored as `{database-id}.json` (e.g., `postgres-main.json`)
|
|
225
|
+
|
|
226
|
+
**Recommended TTL Values:**
|
|
227
|
+
- **Development:** `5` minutes (schema changes frequently)
|
|
228
|
+
- **Staging:** `30-60` minutes
|
|
229
|
+
- **Production (Static):** `1440` minutes (24 hours)
|
|
230
|
+
- **Production (Active):** `60-240` minutes (1-4 hours)
|
|
231
|
+
|
|
232
|
+
#### Security Configuration
|
|
233
|
+
|
|
234
|
+
Comprehensive security controls to protect your databases from unauthorized or dangerous operations.
|
|
235
|
+
|
|
236
|
+
| Property | Type | Required | Default | Description |
|
|
237
|
+
|----------|------|----------|---------|-------------|
|
|
238
|
+
| `allowWrite` | boolean | No | `false` | Master switch for write operations. When `false`, all writes are blocked across all databases. |
|
|
239
|
+
| `allowedWriteOperations` | string[] | No | all | Whitelist of allowed SQL operations when `allowWrite: true`. Valid values: `INSERT`, `UPDATE`, `DELETE`, `CREATE`, `ALTER`, `DROP`, `TRUNCATE`, `REPLACE`, `MERGE` |
|
|
240
|
+
| `disableDangerousOperations` | boolean | No | `true` | **Extra safety layer.** When `true`, blocks `DELETE`, `TRUNCATE`, and `DROP` operations even if writes are allowed. Prevents accidental data loss. |
|
|
241
|
+
| `redactSecrets` | boolean | No | `true` | Automatically redact passwords and credentials in logs and error messages. |
|
|
242
|
+
|
|
243
|
+
**Security Layers (Evaluated in Order):**
|
|
244
|
+
|
|
245
|
+
1. **Database-level `readOnly`** β Blocks all writes for specific database
|
|
246
|
+
2. **Global `allowWrite`** β Master switch for all databases
|
|
247
|
+
3. **`disableDangerousOperations`** β Blocks DELETE/TRUNCATE/DROP specifically
|
|
248
|
+
4. **`allowedWriteOperations`** β Whitelist of permitted operations
|
|
249
|
+
|
|
250
|
+
**Example Configurations:**
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
// Read-only access (default - safest)
|
|
254
|
+
{
|
|
255
|
+
"allowWrite": false
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Allow INSERT and UPDATE only (no deletes)
|
|
259
|
+
{
|
|
260
|
+
"allowWrite": true,
|
|
261
|
+
"allowedWriteOperations": ["INSERT", "UPDATE"],
|
|
262
|
+
"disableDangerousOperations": true
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Full write access (development only - dangerous!)
|
|
266
|
+
{
|
|
267
|
+
"allowWrite": true,
|
|
268
|
+
"disableDangerousOperations": false
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
#### Logging Configuration
|
|
273
|
+
|
|
274
|
+
Controls log output verbosity and formatting.
|
|
275
|
+
|
|
276
|
+
| Property | Type | Required | Default | Description |
|
|
277
|
+
|----------|------|----------|---------|-------------|
|
|
278
|
+
| `level` | enum | No | `info` | Log level. Valid values: `trace`, `debug`, `info`, `warn`, `error`. Lower levels include higher levels. |
|
|
279
|
+
| `pretty` | boolean | No | `false` | When `true`, formats logs as human-readable text. When `false`, outputs structured JSON (better for production log aggregation). |
|
|
280
|
+
|
|
281
|
+
**Log Levels:**
|
|
282
|
+
- **`trace`:** Everything (extremely verbose - use for debugging only)
|
|
283
|
+
- **`debug`:** Detailed diagnostic information
|
|
284
|
+
- **`info`:** General informational messages (recommended for production)
|
|
285
|
+
- **`warn`:** Warning messages that don't prevent operation
|
|
286
|
+
- **`error`:** Error messages only
|
|
287
|
+
|
|
288
|
+
**Recommendations:**
|
|
289
|
+
- **Development:** `level: "debug"`, `pretty: true`
|
|
290
|
+
- **Production:** `level: "info"`, `pretty: false`
|
|
291
|
+
- **Troubleshooting:** `level: "trace"`, `pretty: true`
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
### Complete Configuration Example
|
|
296
|
+
|
|
297
|
+
```json
|
|
298
|
+
{
|
|
299
|
+
"databases": [
|
|
300
|
+
{
|
|
301
|
+
"id": "postgres-production",
|
|
302
|
+
"type": "postgres",
|
|
303
|
+
"url": "${DATABASE_URL}",
|
|
304
|
+
"readOnly": true,
|
|
305
|
+
"pool": {
|
|
306
|
+
"min": 5,
|
|
307
|
+
"max": 20,
|
|
308
|
+
"idleTimeoutMillis": 60000,
|
|
309
|
+
"connectionTimeoutMillis": 5000
|
|
310
|
+
},
|
|
311
|
+
"introspection": {
|
|
312
|
+
"includeViews": true,
|
|
313
|
+
"includeRoutines": false,
|
|
314
|
+
"excludeSchemas": ["pg_catalog", "information_schema"]
|
|
315
|
+
},
|
|
316
|
+
"eagerConnect": true
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"id": "mysql-analytics",
|
|
320
|
+
"type": "mysql",
|
|
321
|
+
"url": "${MYSQL_URL}",
|
|
322
|
+
"readOnly": true,
|
|
323
|
+
"pool": {
|
|
324
|
+
"min": 2,
|
|
325
|
+
"max": 10
|
|
326
|
+
},
|
|
327
|
+
"introspection": {
|
|
328
|
+
"includeViews": true,
|
|
329
|
+
"maxTables": 100
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
"id": "sqlite-local",
|
|
334
|
+
"type": "sqlite",
|
|
335
|
+
"path": "./data/app.db",
|
|
336
|
+
"readOnly": false
|
|
337
|
+
}
|
|
338
|
+
],
|
|
339
|
+
"cache": {
|
|
340
|
+
"directory": ".sql-mcp-cache",
|
|
341
|
+
"ttlMinutes": 60
|
|
342
|
+
},
|
|
343
|
+
"security": {
|
|
344
|
+
"allowWrite": false,
|
|
345
|
+
"allowedWriteOperations": ["INSERT", "UPDATE"],
|
|
346
|
+
"disableDangerousOperations": true,
|
|
347
|
+
"redactSecrets": true
|
|
348
|
+
},
|
|
349
|
+
"logging": {
|
|
350
|
+
"level": "info",
|
|
351
|
+
"pretty": false
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
### Environment Variables
|
|
359
|
+
|
|
360
|
+
**Secure Configuration with Environment Variables:**
|
|
361
|
+
|
|
362
|
+
The server supports environment variable interpolation using `${VARIABLE_NAME}` syntax. This is the recommended approach for managing sensitive credentials.
|
|
363
|
+
|
|
364
|
+
**Example Configuration:**
|
|
365
|
+
```json
|
|
366
|
+
{
|
|
367
|
+
"databases": [
|
|
368
|
+
{
|
|
369
|
+
"id": "production-db",
|
|
370
|
+
"type": "postgres",
|
|
371
|
+
"url": "${DATABASE_URL}"
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
**Environment File (`.env`):**
|
|
378
|
+
```env
|
|
379
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
|
|
380
|
+
DB_URL_MYSQL=mysql://user:password@localhost:3306/dbname
|
|
381
|
+
DB_URL_MSSQL=Server=host,1433;Database=db;User Id=sa;Password=pass
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
**Best Practices:**
|
|
385
|
+
- β
Store `.env` file outside version control (add to `.gitignore`)
|
|
386
|
+
- β
Use different `.env` files for each environment (dev, staging, prod)
|
|
387
|
+
- β
Never commit credentials to git repositories
|
|
388
|
+
- β
Use secret management services (AWS Secrets Manager, HashiCorp Vault) in production
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
### Connection String Reference
|
|
393
|
+
|
|
394
|
+
| Database | Format | Example |
|
|
395
|
+
|----------|--------|---------|
|
|
396
|
+
| **PostgreSQL** | `postgresql://user:pass@host:port/db` | `postgresql://admin:secret@localhost:5432/myapp` |
|
|
397
|
+
| **MySQL** | `mysql://user:pass@host:port/db` | `mysql://root:password@localhost:3306/myapp` |
|
|
398
|
+
| **SQL Server** | `Server=host,port;Database=db;User Id=user;Password=pass` | `Server=localhost,1433;Database=myapp;User Id=sa;Password=secret` |
|
|
399
|
+
| **SQLite** | Use `path` property | `"path": "./data/app.db"` or `"path": "/var/db/app.sqlite"` |
|
|
400
|
+
| **Oracle** | `user/pass@host:port/service` | `admin/secret@localhost:1521/XEPDB1` |
|
|
401
|
+
|
|
402
|
+
**Additional Parameters:**
|
|
403
|
+
|
|
404
|
+
**PostgreSQL:**
|
|
405
|
+
```
|
|
406
|
+
postgresql://user:pass@host:5432/db?sslmode=require&connect_timeout=10
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
**MySQL:**
|
|
410
|
+
```
|
|
411
|
+
mysql://user:pass@host:3306/db?charset=utf8mb4&timezone=Z
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**SQL Server:**
|
|
415
|
+
```
|
|
416
|
+
Server=host;Database=db;User Id=user;Password=pass;Encrypt=true;TrustServerCertificate=false
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
## MCP Client Integration
|
|
422
|
+
|
|
423
|
+
### Configuration File Locations
|
|
424
|
+
|
|
425
|
+
| MCP Client | Configuration File Path |
|
|
426
|
+
|------------|------------------------|
|
|
427
|
+
| **Claude Desktop** (macOS) | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
428
|
+
| **Claude Desktop** (Windows) | `%APPDATA%\Claude\claude_desktop_config.json` |
|
|
429
|
+
| **Cline** (VS Code) | VS Code settings β MCP Servers |
|
|
430
|
+
| **Other Clients** | Refer to client-specific documentation |
|
|
431
|
+
|
|
432
|
+
### Setup Methods
|
|
433
|
+
|
|
434
|
+
#### Method 1: Global npm Installation
|
|
435
|
+
|
|
436
|
+
**Configuration:**
|
|
437
|
+
```json
|
|
438
|
+
{
|
|
439
|
+
"mcpServers": {
|
|
440
|
+
"database": {
|
|
441
|
+
"command": "mcp-database-server",
|
|
442
|
+
"args": ["--config", "/absolute/path/to/.mcp-database-server.config"],
|
|
443
|
+
"env": {
|
|
444
|
+
"DATABASE_URL": "postgresql://user:pass@localhost:5432/db"
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
#### Method 2: Source Installation
|
|
452
|
+
|
|
453
|
+
**Configuration:**
|
|
454
|
+
```json
|
|
455
|
+
{
|
|
456
|
+
"mcpServers": {
|
|
457
|
+
"database": {
|
|
458
|
+
"command": "node",
|
|
459
|
+
"args": [
|
|
460
|
+
"/absolute/path/to/mcp-database-server/dist/index.js",
|
|
461
|
+
"--config",
|
|
462
|
+
"/absolute/path/to/.mcp-database-server.config"
|
|
463
|
+
],
|
|
464
|
+
"env": {
|
|
465
|
+
"DATABASE_URL": "postgresql://user:pass@localhost:5432/db"
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
### Configuration Properties
|
|
473
|
+
|
|
474
|
+
| Property | Description | Example |
|
|
475
|
+
|----------|-------------|---------|
|
|
476
|
+
| `command` | Executable to run. Use `mcp-database-server` for npm install, `node` for source install. | `"mcp-database-server"` |
|
|
477
|
+
| `args` | Array of command-line arguments. First arg is usually `--config` followed by config file path. | `["--config", "/path/to/config"]` |
|
|
478
|
+
| `env` | Environment variables passed to the server. Used for secure credential management. | `{"DATABASE_URL": "..."}` |
|
|
479
|
+
|
|
480
|
+
**Finding Absolute Paths:**
|
|
481
|
+
```bash
|
|
482
|
+
# macOS/Linux
|
|
483
|
+
cd /path/to/mcp-database-server
|
|
484
|
+
pwd # prints: /Users/username/projects/mcp-database-server
|
|
485
|
+
|
|
486
|
+
# Windows (PowerShell)
|
|
487
|
+
cd C:\path\to\mcp-database-server
|
|
488
|
+
$PWD.Path # prints: C:\Users\username\projects\mcp-database-server
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
## Available MCP Tools
|
|
494
|
+
|
|
495
|
+
This server provides 14 tools for comprehensive database interaction and optimization.
|
|
496
|
+
|
|
497
|
+
### Tool Reference
|
|
498
|
+
|
|
499
|
+
| Tool | Purpose | Write Access | Cached Data |
|
|
500
|
+
|------|---------|--------------|-------------|
|
|
501
|
+
| `list_databases` | List all configured databases with status | No | Uses cache |
|
|
502
|
+
| `introspect_schema` | Discover and cache database schema | No | Writes cache |
|
|
503
|
+
| `get_schema` | Retrieve cached schema metadata | No | Reads cache |
|
|
504
|
+
| `run_query` | Execute SQL queries with safety controls | Conditional* | Updates stats |
|
|
505
|
+
| `explain_query` | Analyze query execution plans | No | No cache |
|
|
506
|
+
| `suggest_joins` | Get intelligent join path recommendations | No | Uses cache |
|
|
507
|
+
| `clear_cache` | Clear schema cache and statistics | No | Clears cache |
|
|
508
|
+
| `cache_status` | View cache health and statistics | No | Reads cache |
|
|
509
|
+
| `health_check` | Test database connectivity | No | No cache |
|
|
510
|
+
| `analyze_performance` | Get detailed performance analytics | No | Uses stats |
|
|
511
|
+
| `suggest_indexes` | Analyze queries and recommend indexes | No | Uses stats |
|
|
512
|
+
| `detect_slow_queries` | Identify and alert on slow queries | No | Uses stats |
|
|
513
|
+
| `rewrite_query` | Suggest optimized query versions | No | Uses cache |
|
|
514
|
+
| `profile_query` | Profile query performance with bottlenecks | No | No cache |
|
|
515
|
+
|
|
516
|
+
<sub>* Requires `allowWrite: true` and respects security settings</sub>
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
### 1. list_databases
|
|
521
|
+
|
|
522
|
+
Lists all configured databases with their connection status and cache information.
|
|
523
|
+
|
|
524
|
+
**Input Parameters:**
|
|
525
|
+
|
|
526
|
+
None required.
|
|
527
|
+
|
|
528
|
+
**Response:**
|
|
529
|
+
```json
|
|
530
|
+
[
|
|
531
|
+
{
|
|
532
|
+
"id": "postgres-main",
|
|
533
|
+
"type": "postgres",
|
|
534
|
+
"connected": true,
|
|
535
|
+
"cached": true,
|
|
536
|
+
"cacheAge": 45000,
|
|
537
|
+
"version": "abc123"
|
|
538
|
+
}
|
|
539
|
+
]
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
**Response Fields:**
|
|
543
|
+
|
|
544
|
+
| Field | Type | Description |
|
|
545
|
+
|-------|------|-------------|
|
|
546
|
+
| `id` | string | Database identifier from configuration |
|
|
547
|
+
| `type` | string | Database type (postgres, mysql, sqlite, mssql, oracle) |
|
|
548
|
+
| `connected` | boolean | Whether database connection is active |
|
|
549
|
+
| `cached` | boolean | Whether schema is currently cached |
|
|
550
|
+
| `cacheAge` | number | Age of cached schema in milliseconds (if cached) |
|
|
551
|
+
| `version` | string | Cache version hash (if cached) |
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
### 2. introspect_schema
|
|
556
|
+
|
|
557
|
+
Discovers and caches complete database schema including tables, columns, indexes, foreign keys, and relationships.
|
|
558
|
+
|
|
559
|
+
**Input Parameters:**
|
|
560
|
+
|
|
561
|
+
| Parameter | Type | Required | Description |
|
|
562
|
+
|-----------|------|----------|-------------|
|
|
563
|
+
| `dbId` | string | Yes | Database identifier to introspect |
|
|
564
|
+
| `forceRefresh` | boolean | No | Force re-introspection even if cache is valid (default: `false`) |
|
|
565
|
+
| `schemaFilter` | object | No | Filter which objects to introspect |
|
|
566
|
+
| `schemaFilter.includeSchemas` | string[] | No | Only introspect these schemas (PostgreSQL/SQL Server) |
|
|
567
|
+
| `schemaFilter.excludeSchemas` | string[] | No | Skip these schemas during introspection |
|
|
568
|
+
| `schemaFilter.includeViews` | boolean | No | Include database views (default: `true`) |
|
|
569
|
+
| `schemaFilter.maxTables` | number | No | Limit to first N tables |
|
|
570
|
+
|
|
571
|
+
**Example Request:**
|
|
572
|
+
```json
|
|
573
|
+
{
|
|
574
|
+
"dbId": "postgres-main",
|
|
575
|
+
"forceRefresh": false,
|
|
576
|
+
"schemaFilter": {
|
|
577
|
+
"includeSchemas": ["public"],
|
|
578
|
+
"excludeSchemas": ["temp"],
|
|
579
|
+
"includeViews": true,
|
|
580
|
+
"maxTables": 100
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
**Response:**
|
|
586
|
+
```json
|
|
587
|
+
{
|
|
588
|
+
"dbId": "postgres-main",
|
|
589
|
+
"version": "a1b2c3d4",
|
|
590
|
+
"introspectedAt": "2026-01-26T10:00:00.000Z",
|
|
591
|
+
"schemas": [
|
|
592
|
+
{
|
|
593
|
+
"name": "public",
|
|
594
|
+
"tableCount": 15,
|
|
595
|
+
"viewCount": 3
|
|
596
|
+
}
|
|
597
|
+
],
|
|
598
|
+
"totalTables": 15,
|
|
599
|
+
"totalRelationships": 12
|
|
600
|
+
}
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
### 3. get_schema
|
|
606
|
+
|
|
607
|
+
Retrieves detailed schema metadata from cache without querying the database.
|
|
608
|
+
|
|
609
|
+
**Input Parameters:**
|
|
610
|
+
|
|
611
|
+
| Parameter | Type | Required | Description |
|
|
612
|
+
|-----------|------|----------|-------------|
|
|
613
|
+
| `dbId` | string | Yes | Database identifier |
|
|
614
|
+
| `schema` | string | No | Filter to specific schema name |
|
|
615
|
+
| `table` | string | No | Filter to specific table name |
|
|
616
|
+
|
|
617
|
+
**Example Request:**
|
|
618
|
+
```json
|
|
619
|
+
{
|
|
620
|
+
"dbId": "postgres-main",
|
|
621
|
+
"schema": "public",
|
|
622
|
+
"table": "users"
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
**Response:** Complete schema metadata including tables, columns, data types, indexes, foreign keys, and inferred relationships.
|
|
627
|
+
|
|
628
|
+
---
|
|
629
|
+
|
|
630
|
+
### 4. run_query
|
|
631
|
+
|
|
632
|
+
Executes SQL queries with automatic schema caching, relationship annotation, and comprehensive security controls.
|
|
633
|
+
|
|
634
|
+
**Input Parameters:**
|
|
635
|
+
|
|
636
|
+
| Parameter | Type | Required | Description |
|
|
637
|
+
|-----------|------|----------|-------------|
|
|
638
|
+
| `dbId` | string | Yes | Database identifier to query |
|
|
639
|
+
| `sql` | string | Yes | SQL query to execute |
|
|
640
|
+
| `params` | array | No | Parameterized query values (prevents SQL injection) |
|
|
641
|
+
| `limit` | number | No | Maximum number of rows to return |
|
|
642
|
+
| `timeoutMs` | number | No | Query timeout in milliseconds |
|
|
643
|
+
|
|
644
|
+
**Example Request:**
|
|
645
|
+
```json
|
|
646
|
+
{
|
|
647
|
+
"dbId": "postgres-main",
|
|
648
|
+
"sql": "SELECT * FROM users WHERE active = $1 LIMIT $2",
|
|
649
|
+
"params": [true, 10],
|
|
650
|
+
"timeoutMs": 5000
|
|
651
|
+
}
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
**Response:**
|
|
655
|
+
```json
|
|
656
|
+
{
|
|
657
|
+
"rows": [
|
|
658
|
+
{"id": 1, "name": "Alice", "email": "alice@example.com", "active": true},
|
|
659
|
+
{"id": 2, "name": "Bob", "email": "bob@example.com", "active": true}
|
|
660
|
+
],
|
|
661
|
+
"columns": ["id", "name", "email", "active"],
|
|
662
|
+
"rowCount": 2,
|
|
663
|
+
"executionTimeMs": 15,
|
|
664
|
+
"metadata": {
|
|
665
|
+
"relationships": [...],
|
|
666
|
+
"queryStats": {
|
|
667
|
+
"totalQueries": 10,
|
|
668
|
+
"avgExecutionTime": 20,
|
|
669
|
+
"errorCount": 0
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
**Security Controls:**
|
|
676
|
+
- β
Write operations blocked by default (`allowWrite: false`)
|
|
677
|
+
- β
Dangerous operations (DELETE, TRUNCATE, DROP) disabled by default
|
|
678
|
+
- β
Specific operations can be whitelisted via `allowedWriteOperations`
|
|
679
|
+
- β
Per-database `readOnly` mode
|
|
680
|
+
|
|
681
|
+
---
|
|
682
|
+
|
|
683
|
+
### 5. explain_query
|
|
684
|
+
|
|
685
|
+
Retrieves database query execution plan without executing the query.
|
|
686
|
+
|
|
687
|
+
**Input Parameters:**
|
|
688
|
+
|
|
689
|
+
| Parameter | Type | Required | Description |
|
|
690
|
+
|-----------|------|----------|-------------|
|
|
691
|
+
| `dbId` | string | Yes | Database identifier |
|
|
692
|
+
| `sql` | string | Yes | SQL query to analyze |
|
|
693
|
+
| `params` | array | No | Query parameters (for parameterized queries) |
|
|
694
|
+
|
|
695
|
+
**Example Request:**
|
|
696
|
+
```json
|
|
697
|
+
{
|
|
698
|
+
"dbId": "postgres-main",
|
|
699
|
+
"sql": "SELECT * FROM users JOIN orders ON users.id = orders.user_id WHERE users.active = $1",
|
|
700
|
+
"params": [true]
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
**Response:** Database-native execution plan (format varies by database type).
|
|
705
|
+
|
|
706
|
+
---
|
|
707
|
+
|
|
708
|
+
### 6. suggest_joins
|
|
709
|
+
|
|
710
|
+
Analyzes relationship graph to recommend optimal join paths between multiple tables.
|
|
711
|
+
|
|
712
|
+
**Input Parameters:**
|
|
713
|
+
|
|
714
|
+
| Parameter | Type | Required | Description |
|
|
715
|
+
|-----------|------|----------|-------------|
|
|
716
|
+
| `dbId` | string | Yes | Database identifier |
|
|
717
|
+
| `tables` | string[] | Yes | Array of table names to join (2-10 tables) |
|
|
718
|
+
|
|
719
|
+
**Example Request:**
|
|
720
|
+
```json
|
|
721
|
+
{
|
|
722
|
+
"dbId": "postgres-main",
|
|
723
|
+
"tables": ["users", "orders", "products"]
|
|
724
|
+
}
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
**Response:**
|
|
728
|
+
```json
|
|
729
|
+
[
|
|
730
|
+
{
|
|
731
|
+
"tables": ["users", "orders", "products"],
|
|
732
|
+
"joins": [
|
|
733
|
+
{
|
|
734
|
+
"fromTable": "users",
|
|
735
|
+
"toTable": "orders",
|
|
736
|
+
"relationship": {
|
|
737
|
+
"type": "one-to-many",
|
|
738
|
+
"confidence": 1.0
|
|
739
|
+
},
|
|
740
|
+
"joinCondition": "users.id = orders.user_id"
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
"fromTable": "orders",
|
|
744
|
+
"toTable": "products",
|
|
745
|
+
"relationship": {
|
|
746
|
+
"type": "many-to-one",
|
|
747
|
+
"confidence": 1.0
|
|
748
|
+
},
|
|
749
|
+
"joinCondition": "orders.product_id = products.id"
|
|
750
|
+
}
|
|
751
|
+
],
|
|
752
|
+
"sql": "FROM users JOIN orders ON users.id = orders.user_id JOIN products ON orders.product_id = products.id"
|
|
753
|
+
}
|
|
754
|
+
]
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
---
|
|
758
|
+
|
|
759
|
+
### 7. clear_cache
|
|
760
|
+
|
|
761
|
+
Clears schema cache and query statistics for one or all databases.
|
|
762
|
+
|
|
763
|
+
**Input Parameters:**
|
|
764
|
+
|
|
765
|
+
| Parameter | Type | Required | Description |
|
|
766
|
+
|-----------|------|----------|-------------|
|
|
767
|
+
| `dbId` | string | No | Database to clear (omit to clear all) |
|
|
768
|
+
|
|
769
|
+
**Example Request:**
|
|
770
|
+
```json
|
|
771
|
+
{
|
|
772
|
+
"dbId": "postgres-main"
|
|
773
|
+
}
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
**Response:** Confirmation message.
|
|
777
|
+
|
|
778
|
+
---
|
|
779
|
+
|
|
780
|
+
### 8. cache_status
|
|
781
|
+
|
|
782
|
+
Retrieves detailed cache statistics and health information.
|
|
783
|
+
|
|
784
|
+
**Input Parameters:**
|
|
785
|
+
|
|
786
|
+
None required.
|
|
787
|
+
|
|
788
|
+
**Response:**
|
|
789
|
+
```json
|
|
790
|
+
{
|
|
791
|
+
"directory": ".sql-mcp-cache",
|
|
792
|
+
"ttlMinutes": 10,
|
|
793
|
+
"databases": [
|
|
794
|
+
{
|
|
795
|
+
"dbId": "postgres-main",
|
|
796
|
+
"cached": true,
|
|
797
|
+
"version": "abc123",
|
|
798
|
+
"age": 120000,
|
|
799
|
+
"expired": false,
|
|
800
|
+
"tableCount": 15,
|
|
801
|
+
"sizeBytes": 45678
|
|
802
|
+
}
|
|
803
|
+
]
|
|
804
|
+
}
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
---
|
|
808
|
+
|
|
809
|
+
### 9. health_check
|
|
810
|
+
|
|
811
|
+
Tests database connectivity and returns status information.
|
|
812
|
+
|
|
813
|
+
**Input Parameters:**
|
|
814
|
+
|
|
815
|
+
| Parameter | Type | Required | Description |
|
|
816
|
+
|-----------|------|----------|-------------|
|
|
817
|
+
| `dbId` | string | No | Database to check (omit to check all) |
|
|
818
|
+
|
|
819
|
+
**Response:**
|
|
820
|
+
```json
|
|
821
|
+
{
|
|
822
|
+
"databases": [
|
|
823
|
+
{
|
|
824
|
+
"dbId": "postgres-main",
|
|
825
|
+
"healthy": true,
|
|
826
|
+
"connected": true,
|
|
827
|
+
"version": "PostgreSQL 15.3",
|
|
828
|
+
"responseTimeMs": 12
|
|
829
|
+
}
|
|
830
|
+
]
|
|
831
|
+
}
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
---
|
|
835
|
+
|
|
836
|
+
### 10. analyze_performance
|
|
837
|
+
|
|
838
|
+
Get comprehensive performance analytics across all queries for a database.
|
|
839
|
+
|
|
840
|
+
**Input Parameters:**
|
|
841
|
+
|
|
842
|
+
| Parameter | Type | Required | Description |
|
|
843
|
+
|-----------|------|----------|-------------|
|
|
844
|
+
| `dbId` | string | Yes | Database to analyze |
|
|
845
|
+
|
|
846
|
+
**Response:**
|
|
847
|
+
```json
|
|
848
|
+
{
|
|
849
|
+
"totalQueries": 1250,
|
|
850
|
+
"slowQueries": 23,
|
|
851
|
+
"avgExecutionTime": 45.67,
|
|
852
|
+
"p95ExecutionTime": 234.5,
|
|
853
|
+
"errorRate": 1.2,
|
|
854
|
+
"mostFrequentTables": [
|
|
855
|
+
{ "table": "users", "count": 456 },
|
|
856
|
+
{ "table": "orders", "count": 234 }
|
|
857
|
+
],
|
|
858
|
+
"performanceTrend": "improving"
|
|
859
|
+
}
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
---
|
|
863
|
+
|
|
864
|
+
### 11. suggest_indexes
|
|
865
|
+
|
|
866
|
+
Analyze query patterns and recommend optimal database indexes.
|
|
867
|
+
|
|
868
|
+
**Input Parameters:**
|
|
869
|
+
|
|
870
|
+
| Parameter | Type | Required | Description |
|
|
871
|
+
|-----------|------|----------|-------------|
|
|
872
|
+
| `dbId` | string | Yes | Database to analyze |
|
|
873
|
+
|
|
874
|
+
**Response:**
|
|
875
|
+
```json
|
|
876
|
+
[
|
|
877
|
+
{
|
|
878
|
+
"table": "orders",
|
|
879
|
+
"columns": ["customer_id", "order_date"],
|
|
880
|
+
"type": "composite",
|
|
881
|
+
"reason": "Frequently used in WHERE and JOIN conditions",
|
|
882
|
+
"impact": "high"
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
"table": "products",
|
|
886
|
+
"columns": ["category_id"],
|
|
887
|
+
"type": "single",
|
|
888
|
+
"reason": "Column category_id is frequently queried",
|
|
889
|
+
"impact": "medium"
|
|
890
|
+
}
|
|
891
|
+
]
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
---
|
|
895
|
+
|
|
896
|
+
### 12. detect_slow_queries
|
|
897
|
+
|
|
898
|
+
Identify queries that exceed performance thresholds and provide alerts.
|
|
899
|
+
|
|
900
|
+
**Input Parameters:**
|
|
901
|
+
|
|
902
|
+
| Parameter | Type | Required | Description |
|
|
903
|
+
|-----------|------|----------|-------------|
|
|
904
|
+
| `dbId` | string | Yes | Database to analyze |
|
|
905
|
+
|
|
906
|
+
**Response:**
|
|
907
|
+
```json
|
|
908
|
+
[
|
|
909
|
+
{
|
|
910
|
+
"dbId": "postgres-main",
|
|
911
|
+
"queryId": "a1b2c3",
|
|
912
|
+
"sql": "SELECT * FROM large_table WHERE slow_column = ?",
|
|
913
|
+
"executionTimeMs": 2500,
|
|
914
|
+
"thresholdMs": 1000,
|
|
915
|
+
"timestamp": "2024-01-27T10:30:00Z",
|
|
916
|
+
"frequency": 5,
|
|
917
|
+
"recommendations": [
|
|
918
|
+
{
|
|
919
|
+
"type": "add_index",
|
|
920
|
+
"description": "Add index on slow_column for better performance",
|
|
921
|
+
"impact": "high",
|
|
922
|
+
"effort": "medium"
|
|
923
|
+
}
|
|
924
|
+
]
|
|
925
|
+
}
|
|
926
|
+
]
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
---
|
|
930
|
+
|
|
931
|
+
### 13. rewrite_query
|
|
932
|
+
|
|
933
|
+
Suggest optimized versions of SQL queries with performance improvements.
|
|
934
|
+
|
|
935
|
+
**Input Parameters:**
|
|
936
|
+
|
|
937
|
+
| Parameter | Type | Required | Description |
|
|
938
|
+
|-----------|------|----------|-------------|
|
|
939
|
+
| `dbId` | string | Yes | Database ID |
|
|
940
|
+
| `sql` | string | Yes | SQL query to optimize |
|
|
941
|
+
|
|
942
|
+
**Response:**
|
|
943
|
+
```json
|
|
944
|
+
{
|
|
945
|
+
"originalQuery": "SELECT * FROM users WHERE active = 1",
|
|
946
|
+
"optimizedQuery": "SELECT id, name, email FROM users WHERE active = 1 LIMIT 1000",
|
|
947
|
+
"improvements": [
|
|
948
|
+
"Removed unnecessary SELECT *",
|
|
949
|
+
"Added LIMIT clause to prevent large result sets"
|
|
950
|
+
],
|
|
951
|
+
"performanceGain": 35,
|
|
952
|
+
"confidence": "high"
|
|
953
|
+
}
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
---
|
|
957
|
+
|
|
958
|
+
### 14. profile_query
|
|
959
|
+
|
|
960
|
+
Profile a specific query's performance with detailed bottleneck analysis.
|
|
961
|
+
|
|
962
|
+
**Input Parameters:**
|
|
963
|
+
|
|
964
|
+
| Parameter | Type | Required | Description |
|
|
965
|
+
|-----------|------|----------|-------------|
|
|
966
|
+
| `dbId` | string | Yes | Database ID |
|
|
967
|
+
| `sql` | string | Yes | SQL query to profile |
|
|
968
|
+
| `params` | array | No | Query parameters |
|
|
969
|
+
|
|
970
|
+
**Response:**
|
|
971
|
+
```json
|
|
972
|
+
{
|
|
973
|
+
"queryId": "def456",
|
|
974
|
+
"sql": "SELECT u.name, COUNT(o.id) FROM users u JOIN orders o ON u.id = o.user_id GROUP BY u.id",
|
|
975
|
+
"executionTimeMs": 1250,
|
|
976
|
+
"rowCount": 5000,
|
|
977
|
+
"bottlenecks": [
|
|
978
|
+
{
|
|
979
|
+
"type": "join",
|
|
980
|
+
"severity": "high",
|
|
981
|
+
"description": "Nested loop join on large tables",
|
|
982
|
+
"estimatedCost": 150
|
|
983
|
+
}
|
|
984
|
+
],
|
|
985
|
+
"recommendations": [
|
|
986
|
+
{
|
|
987
|
+
"type": "add_index",
|
|
988
|
+
"description": "Add index on orders.user_id",
|
|
989
|
+
"impact": "high",
|
|
990
|
+
"effort": "low"
|
|
991
|
+
}
|
|
992
|
+
],
|
|
993
|
+
"overallScore": 65
|
|
994
|
+
}
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
## Resources
|
|
998
|
+
|
|
999
|
+
The server exposes cached schemas as MCP resources:
|
|
1000
|
+
|
|
1001
|
+
- **URI:** `schema://{dbId}`
|
|
1002
|
+
- **MIME Type:** `application/json`
|
|
1003
|
+
- **Content:** Complete cached schema metadata
|
|
1004
|
+
|
|
1005
|
+
## Schema Introspection
|
|
1006
|
+
|
|
1007
|
+
### Automatic Discovery
|
|
1008
|
+
|
|
1009
|
+
The server automatically discovers:
|
|
1010
|
+
|
|
1011
|
+
1. **Tables and Views**: All user tables and optionally views
|
|
1012
|
+
2. **Columns**: Name, data type, nullability, defaults, auto-increment
|
|
1013
|
+
3. **Indexes**: Including primary keys and unique constraints
|
|
1014
|
+
4. **Foreign Keys**: Explicit relationship metadata
|
|
1015
|
+
5. **Relationships**: Both explicit and inferred
|
|
1016
|
+
|
|
1017
|
+
### Relationship Inference
|
|
1018
|
+
|
|
1019
|
+
When foreign keys are not defined, the server infers relationships using heuristics:
|
|
1020
|
+
|
|
1021
|
+
- Column names matching `{table}_id` or `{table}Id`
|
|
1022
|
+
- Data type compatibility with target primary key
|
|
1023
|
+
- Confidence scoring for inferred relationships
|
|
1024
|
+
|
|
1025
|
+
### Caching Strategy
|
|
1026
|
+
|
|
1027
|
+
- **Memory + Disk**: Dual-layer caching for performance
|
|
1028
|
+
- **TTL-based**: Configurable time-to-live
|
|
1029
|
+
- **Version Tracking**: Content-based versioning (hash)
|
|
1030
|
+
- **Concurrency Safe**: Prevents duplicate introspection
|
|
1031
|
+
- **On-Demand Refresh**: Manual or automatic refresh
|
|
1032
|
+
|
|
1033
|
+
## Query Tracking
|
|
1034
|
+
|
|
1035
|
+
The server maintains per-database query history:
|
|
1036
|
+
|
|
1037
|
+
- Timestamp and SQL text
|
|
1038
|
+
- Execution time and row count
|
|
1039
|
+
- Referenced tables (best-effort extraction)
|
|
1040
|
+
- Error tracking
|
|
1041
|
+
- Aggregate statistics
|
|
1042
|
+
|
|
1043
|
+
Use this data to:
|
|
1044
|
+
- Monitor query performance
|
|
1045
|
+
- Identify frequently accessed tables
|
|
1046
|
+
- Detect query patterns
|
|
1047
|
+
- Debug issues
|
|
1048
|
+
|
|
1049
|
+
## Development
|
|
1050
|
+
|
|
1051
|
+
```bash
|
|
1052
|
+
# Install dependencies
|
|
1053
|
+
npm install
|
|
1054
|
+
|
|
1055
|
+
# Run in development mode
|
|
1056
|
+
npm run dev
|
|
1057
|
+
|
|
1058
|
+
# Build
|
|
1059
|
+
npm run build
|
|
1060
|
+
|
|
1061
|
+
# Run tests
|
|
1062
|
+
npm test
|
|
1063
|
+
|
|
1064
|
+
# Run tests with coverage
|
|
1065
|
+
npm run test:coverage
|
|
1066
|
+
|
|
1067
|
+
# Lint
|
|
1068
|
+
npm run lint
|
|
1069
|
+
|
|
1070
|
+
# Format code
|
|
1071
|
+
npm run format
|
|
1072
|
+
|
|
1073
|
+
# Type check
|
|
1074
|
+
npm run typecheck
|
|
1075
|
+
```
|
|
1076
|
+
|
|
1077
|
+
## Project Structure
|
|
1078
|
+
|
|
1079
|
+
```
|
|
1080
|
+
src/
|
|
1081
|
+
βββ adapters/ # Database adapters
|
|
1082
|
+
β βββ base.ts # Base adapter class
|
|
1083
|
+
β βββ postgres.ts # PostgreSQL adapter
|
|
1084
|
+
β βββ mysql.ts # MySQL adapter
|
|
1085
|
+
β βββ sqlite.ts # SQLite adapter
|
|
1086
|
+
β βββ mssql.ts # SQL Server adapter
|
|
1087
|
+
β βββ oracle.ts # Oracle adapter (stub)
|
|
1088
|
+
β βββ index.ts # Adapter factory
|
|
1089
|
+
βββ cache.ts # Schema caching
|
|
1090
|
+
βββ config.ts # Configuration loader
|
|
1091
|
+
βββ database-manager.ts # Database orchestration
|
|
1092
|
+
βββ logger.ts # Logging setup
|
|
1093
|
+
βββ mcp-server.ts # MCP server implementation
|
|
1094
|
+
βββ query-tracker.ts # Query history tracking
|
|
1095
|
+
βββ types.ts # TypeScript types
|
|
1096
|
+
βββ utils.ts # Utility functions
|
|
1097
|
+
βββ index.ts # Entry point
|
|
1098
|
+
```
|
|
1099
|
+
|
|
1100
|
+
## Adding New Database Adapters
|
|
1101
|
+
|
|
1102
|
+
1. Implement the `DatabaseAdapter` interface in `src/adapters/`
|
|
1103
|
+
2. Follow the pattern from existing adapters
|
|
1104
|
+
3. Add to adapter factory in `src/adapters/index.ts`
|
|
1105
|
+
4. Update type definitions if needed
|
|
1106
|
+
5. Add tests
|
|
1107
|
+
|
|
1108
|
+
Example:
|
|
1109
|
+
|
|
1110
|
+
```typescript
|
|
1111
|
+
import { BaseAdapter } from './base.js';
|
|
1112
|
+
|
|
1113
|
+
export class CustomAdapter extends BaseAdapter {
|
|
1114
|
+
async connect(): Promise<void> { /* ... */ }
|
|
1115
|
+
async disconnect(): Promise<void> { /* ... */ }
|
|
1116
|
+
async introspect(): Promise<DatabaseSchema> { /* ... */ }
|
|
1117
|
+
async query(): Promise<QueryResult> { /* ... */ }
|
|
1118
|
+
async explain(): Promise<ExplainResult> { /* ... */ }
|
|
1119
|
+
async testConnection(): Promise<boolean> { /* ... */ }
|
|
1120
|
+
async getVersion(): Promise<string> { /* ... */ }
|
|
1121
|
+
}
|
|
1122
|
+
```
|
|
1123
|
+
|
|
1124
|
+
## Troubleshooting
|
|
1125
|
+
|
|
1126
|
+
### Connection Issues
|
|
1127
|
+
|
|
1128
|
+
- Verify connection strings and credentials
|
|
1129
|
+
- Check network connectivity and firewall rules
|
|
1130
|
+
- Enable debug logging: `"logging": { "level": "debug" }`
|
|
1131
|
+
- Use `health_check` tool to test connectivity
|
|
1132
|
+
|
|
1133
|
+
### Cache Issues
|
|
1134
|
+
|
|
1135
|
+
- Clear cache: Use `clear_cache` tool
|
|
1136
|
+
- Check cache directory permissions
|
|
1137
|
+
- Verify TTL settings
|
|
1138
|
+
- Review cache status with `cache_status` tool
|
|
1139
|
+
|
|
1140
|
+
### Performance
|
|
1141
|
+
|
|
1142
|
+
- Adjust connection pool settings
|
|
1143
|
+
- Use `maxTables` to limit introspection scope
|
|
1144
|
+
- Set appropriate cache TTL
|
|
1145
|
+
- Enable read-only mode when possible
|
|
1146
|
+
|
|
1147
|
+
### Oracle Setup
|
|
1148
|
+
|
|
1149
|
+
The Oracle adapter requires additional setup:
|
|
1150
|
+
|
|
1151
|
+
1. Install Oracle Instant Client
|
|
1152
|
+
2. Set environment variables (`LD_LIBRARY_PATH` or `PATH`)
|
|
1153
|
+
3. Install `oracledb` package
|
|
1154
|
+
4. Implement stub methods in `src/adapters/oracle.ts`
|
|
1155
|
+
|
|
1156
|
+
## Security Considerations
|
|
1157
|
+
|
|
1158
|
+
- Always use read-only mode in production unless write access is required
|
|
1159
|
+
- Use environment variables for credentials, never hardcode
|
|
1160
|
+
- Enable secret redaction in logs
|
|
1161
|
+
- Restrict write operations with `allowedWriteOperations`
|
|
1162
|
+
- Use connection string encryption where supported
|
|
1163
|
+
- Regular security audits of configurations
|
|
1164
|
+
|
|
1165
|
+
## License
|
|
1166
|
+
|
|
1167
|
+
MIT
|
|
1168
|
+
|
|
1169
|
+
## Contributing
|
|
1170
|
+
|
|
1171
|
+
Contributions welcome! Please:
|
|
1172
|
+
|
|
1173
|
+
1. Fork the repository
|
|
1174
|
+
2. Create a feature branch
|
|
1175
|
+
3. Add tests for new functionality
|
|
1176
|
+
4. Ensure all tests pass
|
|
1177
|
+
5. Submit a pull request
|
|
1178
|
+
|
|
1179
|
+
## Support
|
|
1180
|
+
|
|
1050
1181
|
For issues, questions, or feature requests, please open an issue on GitHub.
|