@berthojoris/mcp-mysql-server 1.44.0 → 1.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/DOCUMENTATIONS.md +680 -524
- package/README.md +473 -382
- package/bin/mcp-mysql.js +49 -3
- package/dist/config/featureConfig.js +5 -5
- package/dist/config/runtimeConfig.d.ts +50 -0
- package/dist/config/runtimeConfig.js +173 -0
- package/dist/db/connection.d.ts +32 -0
- package/dist/db/connection.js +169 -8
- package/dist/mcp-server.js +224 -83
- package/dist/optimization/queryOptimizer.d.ts +13 -5
- package/dist/optimization/queryOptimizer.js +85 -58
- package/dist/security/grantInspector.d.ts +5 -0
- package/dist/security/grantInspector.js +32 -0
- package/dist/security/securityLayer.js +3 -2
- package/dist/server/auditLogger.d.ts +24 -0
- package/dist/server/auditLogger.js +60 -0
- package/dist/server/auth.d.ts +56 -0
- package/dist/server/auth.js +274 -0
- package/dist/server/httpServer.d.ts +22 -0
- package/dist/server/httpServer.js +320 -0
- package/dist/server/rateLimiter.d.ts +15 -0
- package/dist/server/rateLimiter.js +41 -0
- package/dist/server/requestContext.d.ts +12 -0
- package/dist/server/requestContext.js +9 -0
- package/dist/tools/maintenanceTools.d.ts +3 -1
- package/dist/tools/maintenanceTools.js +22 -10
- package/dist/tools/queryTools.js +9 -0
- package/dist/tools/toolAnnotations.d.ts +4 -0
- package/dist/tools/toolAnnotations.js +73 -0
- package/manifest.json +6 -10
- package/package.json +1 -1
package/DOCUMENTATIONS.md
CHANGED
|
@@ -1,524 +1,680 @@
|
|
|
1
|
-
# MySQL MCP Server - Documentation
|
|
2
|
-
|
|
3
|
-
**Last Updated:** 2026-10-26
|
|
4
|
-
**Version:** 1.
|
|
5
|
-
**Total Tools:** 88
|
|
6
|
-
|
|
7
|
-
Comprehensive documentation for the MySQL MCP Server. For quick start, see [README.md](README.md).
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Table of Contents
|
|
12
|
-
|
|
13
|
-
1. [Configuration](#configuration)
|
|
14
|
-
2. [
|
|
15
|
-
3. [Permission System](#permission-system)
|
|
16
|
-
4. [Tool Categories](#tool-categories)
|
|
17
|
-
5. [Core Operations](#core-operations)
|
|
18
|
-
6. [Advanced Features](#advanced-features)
|
|
19
|
-
7. [Security Features](#security-features)
|
|
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
|
-
**Layer
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
###
|
|
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
|
-
await mcp.call("
|
|
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
|
-
The
|
|
516
|
-
|
|
517
|
-
-
|
|
518
|
-
-
|
|
519
|
-
-
|
|
520
|
-
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
1
|
+
# MySQL MCP Server - Documentation
|
|
2
|
+
|
|
3
|
+
**Last Updated:** 2026-10-26 15:57:37
|
|
4
|
+
**Version:** 1.45.2
|
|
5
|
+
**Total Tools:** 88
|
|
6
|
+
|
|
7
|
+
Comprehensive documentation for the MySQL MCP Server. For quick start, see [README.md](README.md).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
1. [Configuration](#configuration)
|
|
14
|
+
2. [Remote Access: Streamable HTTP Transport](#remote-access-streamable-http-transport-v1450-2026-10-26-144606)
|
|
15
|
+
3. [Permission System](#permission-system)
|
|
16
|
+
4. [Tool Categories](#tool-categories)
|
|
17
|
+
5. [Core Operations](#core-operations)
|
|
18
|
+
6. [Advanced Features](#advanced-features)
|
|
19
|
+
7. [Security Features](#security-features)
|
|
20
|
+
8. [Troubleshooting](#troubleshooting)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Configuration
|
|
25
|
+
|
|
26
|
+
### Dual-Layer Access Control
|
|
27
|
+
|
|
28
|
+
Configure MySQL MCP with two access-control layers:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"mcpServers": {
|
|
33
|
+
"mysql": {
|
|
34
|
+
"command": "npx",
|
|
35
|
+
"type": "stdio",
|
|
36
|
+
"args": [
|
|
37
|
+
"-y",
|
|
38
|
+
"@berthojoris/mcp-mysql-server",
|
|
39
|
+
"mysql://user:password@localhost:3306/database",
|
|
40
|
+
"list,read,utility",
|
|
41
|
+
"database_discovery,custom_queries,analysis"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Layer 1 (Permissions)**: Broad operation control
|
|
49
|
+
**Layer 2 (Categories)**: Fine-grained tool filtering
|
|
50
|
+
|
|
51
|
+
> **Credentials with special characters**: if the username or password in the connection string contains URL-reserved characters (`@`, `:`, `/`, `?`, `#`, `%`, `&`, etc.), URL-encode them — e.g. the password `p@ss:w0rd` becomes `p%40ss%3Aw0rd`, giving `mysql://user:p%40ss%3Aw0rd@host:3306/db`. The server passes both the username and password through `decodeURIComponent()` before connecting, including when only one of the two is set.
|
|
52
|
+
|
|
53
|
+
### Environment Variables
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"env": {
|
|
58
|
+
"DB_HOST": "localhost",
|
|
59
|
+
"DB_PORT": "3306",
|
|
60
|
+
"DB_USER": "root",
|
|
61
|
+
"DB_PASSWORD": "your_password",
|
|
62
|
+
"DB_NAME": "your_database",
|
|
63
|
+
"MCP_PERMISSIONS": "list,read,utility",
|
|
64
|
+
"MCP_CATEGORIES": "database_discovery,custom_queries,analysis"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Defaults (v1.44.0, 2026-10-26 13:35:39)
|
|
70
|
+
|
|
71
|
+
- **Permissions**: when neither permissions nor categories are given, the server starts **read-only** with `list,read,utility`. Earlier versions enabled every tool. To enable everything, pass the full list: `list,read,create,update,delete,execute,ddl,utility,transaction,procedure`.
|
|
72
|
+
- **Database**: when the connection string has no database and `DB_NAME` is unset, no database is selected and database-scoped tools return "No database specified". Earlier versions fell back to the `mysql` system schema.
|
|
73
|
+
- **Query cache**: disabled by default. Set `CACHE_ENABLED=true` to opt in (`CACHE_TTL_MS`, default `60000`; `CACHE_MAX_SIZE`, default `100`; `CACHE_MAX_MEMORY_MB`, default `50`). When enabled, any statement that can change data (outside or inside a transaction) and every transaction commit clears the whole cache. Writes made by other clients are not detected, so cached results can lag by up to the TTL.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### Remote Access: Streamable HTTP Transport (v1.45.0, 2026-10-26 14:46:06)
|
|
78
|
+
|
|
79
|
+
The server uses **stdio by default**. A remote transport (MCP Streamable HTTP) for ChatGPT connectors / developer mode and other remote MCP clients is **opt-in**. Turn it on and off the same way as permissions, with a CLI argument or an environment variable. If you leave it unset, existing stdio setups keep working exactly as before.
|
|
80
|
+
|
|
81
|
+
| Setting | CLI flag | Values |
|
|
82
|
+
|---------|----------|--------|
|
|
83
|
+
| `MCP_TRANSPORT` | `--transport=stdio\|http` (or `--http`) | `stdio` (default) or `http` |
|
|
84
|
+
| `MCP_HTTP_HOST` | `--host=<addr>` | Bind address, default `127.0.0.1` |
|
|
85
|
+
| `MCP_HTTP_PORT` | `--port=<n>` | Default `3000` |
|
|
86
|
+
|
|
87
|
+
Flags can go anywhere on the command line. They are not mistaken for the positional permissions/categories arguments, and an unknown `--` option stops startup with an error. A CLI flag overrides the matching environment variable (including values from `.env`).
|
|
88
|
+
|
|
89
|
+
When the transport is `stdio`, every `MCP_HTTP_*` and `MCP_OAUTH_*` variable is ignored, so even an invalid value cannot affect a stdio setup. In HTTP mode, an invalid or unsafe value stops startup with a message that names the variable.
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Enable HTTP via CLI
|
|
93
|
+
npx -y @berthojoris/mcp-mysql-server mysql://reader:pass@localhost:3306/app "list,read,utility" --transport=http --port=3000
|
|
94
|
+
|
|
95
|
+
# Enable HTTP via environment; unset MCP_TRANSPORT (or set it to "stdio") to disable
|
|
96
|
+
MCP_TRANSPORT=http MCP_HTTP_AUTH=token MCP_HTTP_AUTH_TOKENS=<64-hex-token> \
|
|
97
|
+
npx -y @berthojoris/mcp-mysql-server mysql://reader:pass@localhost:3306/app
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The MCP endpoint is `http://<host>:<port>/mcp` (set by `MCP_HTTP_PATH`). `GET /health` returns `{"status":"ok"}` and needs no authentication.
|
|
101
|
+
|
|
102
|
+
#### HTTP settings
|
|
103
|
+
|
|
104
|
+
| Variable | Default | Description |
|
|
105
|
+
|----------|---------|-------------|
|
|
106
|
+
| `MCP_HTTP_PATH` | `/mcp` | Endpoint path |
|
|
107
|
+
| `MCP_HTTP_PUBLIC_URL` | – | Public base URL as clients see it, e.g. `https://mcp.example.com`. Required for `oauth`. Its host is added to the allowed hosts |
|
|
108
|
+
| `MCP_HTTP_AUTH` | `none` | `none`, `token`, or `oauth` |
|
|
109
|
+
| `MCP_HTTP_AUTH_TOKENS` | – | For `token` mode: comma-separated bearer tokens, each at least 32 characters (`openssl rand -hex 32`) |
|
|
110
|
+
| `MCP_OAUTH_ISSUER` | – | For `oauth` mode: issuer of the external authorization server (Auth0, Keycloak, Okta, Entra ID, ...) |
|
|
111
|
+
| `MCP_OAUTH_AUDIENCE` | resource URL | Expected `aud` claim. Defaults to `MCP_HTTP_PUBLIC_URL` + `MCP_HTTP_PATH` |
|
|
112
|
+
| `MCP_OAUTH_JWKS_URI` | discovered | JWKS URL. When unset, it is discovered from the issuer's OpenID / OAuth metadata |
|
|
113
|
+
| `MCP_OAUTH_REQUIRED_SCOPES` | – | Comma-separated scopes that every token must carry |
|
|
114
|
+
| `MCP_HTTP_ALLOWED_HOSTS` | see description | Comma-separated `Host` header names (without port), for DNS-rebinding protection. Requests with any other `Host` get `403`. When unset and bound to a loopback address, `localhost`, `127.0.0.1`, and `[::1]` are allowed. When unset and bound to another address (e.g. `0.0.0.0`) with no `MCP_HTTP_PUBLIC_URL`, the check is off and a startup warning is logged |
|
|
115
|
+
| `MCP_HTTP_ALLOWED_ORIGINS` | see description | Comma-separated browser `Origin` values (e.g. `https://app.example.com`). A request with any other `Origin` gets `403`. When unset, loopback origins are allowed if the server is bound to loopback, and every `Origin` is rejected otherwise. Requests without `Origin` (server-to-server, such as ChatGPT's backend) are always allowed |
|
|
116
|
+
| `MCP_HTTP_TRUST_PROXY` | `false` | Use the first `X-Forwarded-For` address as the client IP for audit logs and rate limits. Enable only behind a trusted reverse proxy |
|
|
117
|
+
| `MCP_HTTP_ALLOW_UNAUTHENTICATED` | `false` | Allow `MCP_HTTP_AUTH=none` on a non-loopback bind address or with non-loopback allowed hosts. Not recommended |
|
|
118
|
+
| `MCP_HTTP_MAX_SESSIONS` | `100` | Maximum concurrent sessions. New sessions get `503` with `Retry-After: 60` once the limit is reached. `0` means no limit |
|
|
119
|
+
| `MCP_HTTP_SESSION_IDLE_TIMEOUT_MS` | `1800000` | Idle sessions are closed after this time, and their open transactions are rolled back. `0` disables expiry |
|
|
120
|
+
| `MCP_HTTP_MAX_BODY_BYTES` | `1048576` | Maximum request body size. Larger bodies get `413`. `0` means no limit |
|
|
121
|
+
|
|
122
|
+
`GET /health` skips the `Host` check, so load balancers can probe the server by IP.
|
|
123
|
+
|
|
124
|
+
The server does not terminate TLS. Put it behind a reverse proxy or tunnel that serves HTTPS (ChatGPT only connects to public HTTPS URLs), and set `MCP_HTTP_PUBLIC_URL` to that HTTPS address.
|
|
125
|
+
|
|
126
|
+
#### Authentication
|
|
127
|
+
|
|
128
|
+
- **`none`**: no authentication. The server only starts in this mode when it is bound to a loopback address and every allowed host is a loopback name. A tunnel that forwards a public hostname is then rejected by the `Host` check. `MCP_HTTP_ALLOW_UNAUTHENTICATED=true` overrides this rule.
|
|
129
|
+
- **`token`**: static bearer tokens (`Authorization: Bearer <token>`), compared in constant time. Use this for clients that can send a custom header, such as Claude Code, Cursor, or scripts. Each token gets a stable client id `token-<sha256 prefix>`, used in audit logs and rate limits.
|
|
130
|
+
- **`oauth`** (OAuth 2.1 resource server): the server validates JWT access tokens issued by an external authorization server. It does not issue tokens itself.
|
|
131
|
+
- Supported algorithms are RS256/384/512, PS256/384/512, ES256/384/512, and EdDSA. `none` and HMAC algorithms are rejected.
|
|
132
|
+
- The server checks the token's claims. `iss` must equal `MCP_OAUTH_ISSUER` (a trailing slash is ignored), and `aud` must contain the audience. `exp` is required, and `exp`/`nbf` allow 60 seconds of clock skew. Every scope in `MCP_OAUTH_REQUIRED_SCOPES` must appear in `scope` or `scp`; a missing scope returns `403` with `error="insufficient_scope"`.
|
|
133
|
+
- The client id used for sessions, audit logs, and rate limits is taken from `client_id`, then `azp`, then `sub`.
|
|
134
|
+
- Signing keys come from `MCP_OAUTH_JWKS_URI`, or else from `jwks_uri` in `<issuer>/.well-known/openid-configuration`, then from the RFC 8414 `oauth-authorization-server` document. Keys are cached for 10 minutes. A token with an unknown `kid` triggers a refetch, at most once every 30 seconds, so key rotation is picked up.
|
|
135
|
+
- In `oauth` mode only, the server publishes Protected Resource Metadata (RFC 9728) at `/.well-known/oauth-protected-resource` and `/.well-known/oauth-protected-resource<path>`. `401` responses carry `WWW-Authenticate: Bearer resource_metadata="..."` so clients can discover the authorization server.
|
|
136
|
+
- For ChatGPT, the authorization server must support the flow ChatGPT uses: authorization code + PKCE, typically with dynamic client registration.
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
MCP_TRANSPORT=http
|
|
140
|
+
MCP_HTTP_HOST=127.0.0.1
|
|
141
|
+
MCP_HTTP_PUBLIC_URL=https://mcp.example.com
|
|
142
|
+
MCP_HTTP_AUTH=oauth
|
|
143
|
+
MCP_OAUTH_ISSUER=https://your-tenant.auth0.com/
|
|
144
|
+
MCP_OAUTH_REQUIRED_SCOPES=mysql:read
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Sessions
|
|
148
|
+
|
|
149
|
+
- Each client gets its own MCP session (`Mcp-Session-Id`), created by an `initialize` request. A session is bound to the identity that created it, and a request that presents another identity's session id is rejected with `403`. Other requests without a session id get `400`, and an unknown or expired session id gets `404`. `DELETE /mcp` ends a session.
|
|
150
|
+
- Transactions belong to the session that began them. Other sessions cannot see, use, commit, or roll them back; to them the transaction id does not exist. Transactions are rolled back when the session closes, expires, or the server shuts down (`SIGINT`/`SIGTERM`).
|
|
151
|
+
- A transaction id that is already in use is rejected instead of silently replacing the open transaction.
|
|
152
|
+
- Over stdio there is only one session, so behaviour does not change.
|
|
153
|
+
|
|
154
|
+
#### Protection settings (both transports)
|
|
155
|
+
|
|
156
|
+
These settings also apply to stdio, but there they default to **off**, so existing setups behave as before.
|
|
157
|
+
|
|
158
|
+
| Variable | stdio default | http default | Description |
|
|
159
|
+
|----------|---------------|--------------|-------------|
|
|
160
|
+
| `MCP_QUERY_TIMEOUT_MS` | `0` (off) | `30000` | Every SQL statement a tool runs is cancelled on the MySQL server with `KILL QUERY` once it runs longer than this. The tool returns `Query exceeded the <n> ms timeout and was cancelled`. If the statement is inside a transaction, that transaction is rolled back |
|
|
161
|
+
| `MCP_RATE_LIMIT_PER_MINUTE` | `0` (off) | `60` | Tool calls allowed per client in any 60-second window. The client is the auth identity, or the client IP when there is none (over stdio all calls share one bucket). Extra calls return a tool error with the retry delay |
|
|
162
|
+
| `MCP_MAX_RESULT_BYTES` | `0` (off) | `524288` | Maximum size of a tool result (its JSON text). Row arrays are cut to fit and wrapped as `{ rows, truncated, returned_rows, total_rows, message }`. Other oversized results return an error that asks for a narrower query |
|
|
163
|
+
| `MCP_AUDIT_LOG` | `off` | `stderr` | `off`, `stderr`, or a file path (relative paths resolve from the working directory; missing directories are created). See [Audit log](#audit-log) |
|
|
164
|
+
| `MCP_REQUIRE_READONLY_DB_USER` | `false` | `false` | When `true`, startup fails if the MySQL user holds any privilege beyond `SELECT`, `SHOW VIEW`, `SHOW DATABASES`, `PROCESS`, or `USAGE`. `WITH GRANT OPTION` and granted roles count as write privileges, because a role's privileges cannot be resolved |
|
|
165
|
+
|
|
166
|
+
In HTTP mode the server always runs `SHOW GRANTS` at startup and logs a warning if the MySQL user can write.
|
|
167
|
+
|
|
168
|
+
Query timeout details: the timed-out statement is cancelled through a separate short-lived connection that uses the same MySQL account (MySQL allows an account to kill its own threads). The pooled connection that ran the statement is then discarded rather than reused. With the timeout off, queries run on the pool exactly as before.
|
|
169
|
+
|
|
170
|
+
#### Audit log
|
|
171
|
+
|
|
172
|
+
Each line is a JSON object with a `time` and an `event`. Over `stderr`, lines are prefixed with `[audit] `. Nothing is ever written to stdout.
|
|
173
|
+
|
|
174
|
+
| Event | Fields |
|
|
175
|
+
|-------|--------|
|
|
176
|
+
| `tool_call` | `transport`, `session`, `client`, `ip`, `tool`, `args` (`names` of all arguments, plus `sql` truncated to 1000 characters when the call has a `query`/`sql` argument), `status` (`success`, `error`, `invalid`, `denied`, `rate_limited`), `durationMs`, `error` |
|
|
177
|
+
| `auth_failed` | `ip`, `reason` |
|
|
178
|
+
| `session_opened` | `session`, `client`, `ip` |
|
|
179
|
+
| `session_closed` | `session`, `client`, `reason` (`deleted by client`, `idle timeout`, `transport closed`, `server shutdown`) |
|
|
180
|
+
|
|
181
|
+
Argument values other than SQL text are not logged, because they can contain row data.
|
|
182
|
+
|
|
183
|
+
#### Recommended read-only database user
|
|
184
|
+
|
|
185
|
+
Permissions limit which tools are exposed. A read-only MySQL account limits what any SQL can do, even if a tool is misconfigured. For remote AI clients, connect with a dedicated account and keep the default `list,read,utility` permissions:
|
|
186
|
+
|
|
187
|
+
```sql
|
|
188
|
+
CREATE USER 'mcp_reader'@'%' IDENTIFIED BY '<strong password>';
|
|
189
|
+
GRANT SELECT, SHOW VIEW ON app.* TO 'mcp_reader'@'%';
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### Tool annotations
|
|
193
|
+
|
|
194
|
+
Every tool advertises MCP tool annotations: `title`, `readOnlyHint`, `destructiveHint`, `idempotentHint`, and `openWorldHint: false`. They appear in `tools/list` and in the `list_all_tools` catalog. Clients use them to tell read-only tools apart from tools that write or destroy data. ChatGPT uses `readOnlyHint` to decide when to ask the user for confirmation. Annotations are only hints and do not replace permissions.
|
|
195
|
+
|
|
196
|
+
| Class | Hints | Tools |
|
|
197
|
+
|-------|-------|-------|
|
|
198
|
+
| Read-only | `readOnlyHint: true` | Discovery, analysis, `read_records`, `run_select_query`, exports, `show_*`/`list_*`/`get_*`, `check_table`, `fulltext_search`, seed planning/preview tools |
|
|
199
|
+
| Write | `readOnlyHint: false`, `destructiveHint: false` | `create_record`, `bulk_insert`, `execute_seed_plan`, `begin_transaction`, `rollback_transaction`, `create_table`/`create_index`/`create_trigger`/`create_stored_procedure`/`create_fulltext_index`, `add_*` constraints; idempotent maintenance: `analyze_table`, `analyze_index`, `optimize_table`, `flush_table`, `optimize_fulltext` |
|
|
200
|
+
| Destructive | `destructiveHint: true` | `update_record`, `delete_record`, `bulk_update`, `bulk_delete`, `execute_write_query`, `execute_ddl`, `execute_in_transaction`, `commit_transaction`, `execute_stored_procedure`, `cursor_execute_request`, `alter_*`, `drop_*`, `create_view` (can replace a view), `repair_table`, `truncate_table` |
|
|
201
|
+
|
|
202
|
+
The full mapping is in `src/tools/toolAnnotations.ts`.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### Cursor Compatibility Bridge
|
|
207
|
+
|
|
208
|
+
Some Cursor MCP wrappers can call a tool by name but cannot pass `arguments`. For that flow, write a request file at `.cursor/mysql-mcp-request.json` and call the no-argument `cursor_execute_request` tool.
|
|
209
|
+
|
|
210
|
+
Execute any existing MCP tool:
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
{
|
|
214
|
+
"tool": "execute_ddl",
|
|
215
|
+
"arguments": {
|
|
216
|
+
"query": "DROP TABLE IF EXISTS spark_processes;"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Or execute SQL directly with automatic routing:
|
|
222
|
+
|
|
223
|
+
```json
|
|
224
|
+
{
|
|
225
|
+
"query": "DROP TABLE IF EXISTS spark_processes;",
|
|
226
|
+
"mode": "auto"
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Supported `mode` values are `auto`, `select`, `write`, and `ddl`. Set `MYSQL_MCP_CURSOR_REQUEST_FILE` (or its alias `MCP_MYSQL_REQUEST_FILE`) to override the request file path; relative paths resolve from the working directory.
|
|
231
|
+
|
|
232
|
+
The bridge requires `utility` permission and the `utilities` category when category filtering is enabled. The requested destination tool must also be enabled. Disabled tools cannot be called directly or through the bridge.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
### AI Agent Tool Discovery
|
|
237
|
+
|
|
238
|
+
Use `list_all_tools` first when connecting from Codex, Claude Code CLI, Cursor, Droid CLI, or other MCP agents. It returns the live runtime catalog from the server, enabled/disabled status for each tool, the active permission/category profile, and recommended workflows for common agent tasks.
|
|
239
|
+
|
|
240
|
+
For CSV exports, use `export_table_to_csv` for table-based exports and `export_query_to_csv` for SELECT query exports.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Permission System
|
|
245
|
+
|
|
246
|
+
### Available Permissions
|
|
247
|
+
|
|
248
|
+
| Permission | Operations | Example Tools |
|
|
249
|
+
|------------|------------|---------------|
|
|
250
|
+
| `list` | List/discover objects | `list_databases`, `list_tables` |
|
|
251
|
+
| `read` | Read data | `read_records`, `run_select_query` |
|
|
252
|
+
| `create` | Insert records and seed data | `create_record`, `bulk_insert`, `execute_seed_plan` |
|
|
253
|
+
| `update` | Update records | `update_record`, `bulk_update` |
|
|
254
|
+
| `delete` | Delete records | `delete_record`, `bulk_delete`, DELETE via `execute_write_query` (requires both `execute` and `delete`) |
|
|
255
|
+
| `execute` | Custom SQL (INSERT/UPDATE; not DELETE without `delete`) | `execute_write_query` |
|
|
256
|
+
| `ddl` | Schema changes; rebuilding, repairing or flushing tables | `create_table`, `alter_table`, `optimize_table`, `repair_table`, `flush_table`, `optimize_fulltext` |
|
|
257
|
+
| `utility` | Utility operations | `test_connection`, `analyze_table`, `check_table`, `analyze_index` |
|
|
258
|
+
| `transaction` | Transaction management | `begin_transaction`, `commit_transaction` |
|
|
259
|
+
| `procedure` | Stored procedures | `create_stored_procedure`, `execute_stored_procedure` |
|
|
260
|
+
|
|
261
|
+
### Filtering Logic
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
Tool enabled = (Has Permission) AND (Has Category OR No categories specified)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
With no permissions and no categories configured, the effective permissions are `list,read,utility` (read-only default since v1.44.0). Categories alone keep all permissions and filter by category.
|
|
268
|
+
|
|
269
|
+
CSV exports require both `utility` and `read` permissions; their category remains `utilities`.
|
|
270
|
+
|
|
271
|
+
`execute_in_transaction` requires `transaction` plus the permission for the SQL operation: `read` for SELECT, `create` or `execute` for INSERT, `update` or `execute` for UPDATE, and `delete` for DELETE. DDL also requires `ddl` and an enabled `execute_ddl` tool. Transaction permission alone does not authorize reading or modifying data.
|
|
272
|
+
|
|
273
|
+
Information queries such as SHOW/DESCRIBE/EXPLAIN require `list` or `read`. MySQL DDL may implicitly commit, even when called through a transaction tool.
|
|
274
|
+
|
|
275
|
+
`EXPLAIN ANALYZE` (MySQL 8.0.18+) executes the statement it wraps, including multi-table UPDATE/DELETE, so it is authorized as that inner statement: `read` for SELECT, `update` or `execute` for UPDATE, and `delete` for DELETE. Plan-only `EXPLAIN` (without ANALYZE) remains an information query and only requires `list` or `read` (2026-10-12 20:39:13).
|
|
276
|
+
|
|
277
|
+
`optimize_table`, `repair_table`, `flush_table`, and `optimize_fulltext` rebuild, repair, or flush tables, so they require `ddl` instead of `utility` and are no longer part of the read-only default. `flush_table` only flushes tables in the connected database (all of them when `table_name` is omitted) and rejects `with_read_lock`, because the lock would stay held on a pooled connection after the call returns. `analyze_table`, `check_table`, and `analyze_index` remain `utility` tools (2026-10-26 16:39:47).
|
|
278
|
+
|
|
279
|
+
`run_select_query` optimizer `hints` are added to the SQL after it is validated, so every hint value is checked first: table and index names must be plain identifiers, `SEMIJOIN`/`SUBQUERY` strategies must be MySQL strategy names, `MAX_EXECUTION_TIME` must be a positive integer, and `SET_VAR` must be `name=value`. Invalid values are dropped, and the query with hints applied is validated again before it runs (2026-10-26 16:39:47).
|
|
280
|
+
|
|
281
|
+
Schema-qualified names are matched with any whitespace around the dot, so `mysql . user` is blocked like `mysql.user`, and `information_schema . tables` still requires `execute` (2026-10-26 16:39:47).
|
|
282
|
+
|
|
283
|
+
`execute_write_query` accepts only INSERT, UPDATE, and DELETE. Schema changes must use enabled DDL tools, even when `execute` and `ddl` permissions are both present.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Tool Categories
|
|
288
|
+
|
|
289
|
+
### 1. Database Discovery (4 tools)
|
|
290
|
+
- `list_databases` - List all databases
|
|
291
|
+
- `list_tables` - List tables in database
|
|
292
|
+
- `read_table_schema` - Get table structure
|
|
293
|
+
- `get_all_tables_relationships` - Get all FK relationships
|
|
294
|
+
|
|
295
|
+
### 2. Analysis (7 tools)
|
|
296
|
+
- `get_database_summary` - Database overview with statistics
|
|
297
|
+
- `get_schema_erd` - Generate Mermaid.js ER diagram
|
|
298
|
+
- `get_schema_rag_context` - Compact schema for LLM context, with optional comments and keyword filtering
|
|
299
|
+
- `get_column_statistics` - Column data profiling
|
|
300
|
+
- `find_tables_by_keyword` - Ranked schema keyword search across table names, column names, and comments
|
|
301
|
+
- `search_schema` - Unified discovery for “where is X?” questions using schema metadata and optional sample-data search
|
|
302
|
+
- `search_data_across_tables` - Guarded read-only keyword search across text-like data columns
|
|
303
|
+
|
|
304
|
+
### 3. Data Operations (7 tools)
|
|
305
|
+
- `create_record` - Insert single record
|
|
306
|
+
- `read_records` - Query with filtering/pagination
|
|
307
|
+
- `update_record` - Update records
|
|
308
|
+
- `delete_record` - Delete records
|
|
309
|
+
- `bulk_insert` - Batch insert (performance)
|
|
310
|
+
- `bulk_update` - Batch update (performance)
|
|
311
|
+
- `bulk_delete` - Batch delete (performance)
|
|
312
|
+
|
|
313
|
+
### 4. Seed Operations (6 tools)
|
|
314
|
+
- `plan_seed_data` - Build FK-aware relational seed plans
|
|
315
|
+
- `generate_seed_preview` - Preview deterministic dummy rows without writing
|
|
316
|
+
- `execute_seed_plan` - Execute confirmed seed plans with transaction and rollback safety
|
|
317
|
+
- `validate_seed_integrity` - Validate row counts, FK orphans, required columns, and unique collisions
|
|
318
|
+
- `infer_seed_rules` - Infer advanced generators from schema, samples, unique indexes, and domain presets
|
|
319
|
+
- `seed_from_template` - Create reusable plan-first seed workflows for ecommerce, POS, and CRM domains
|
|
320
|
+
|
|
321
|
+
### 5. Query Management (2 tools)
|
|
322
|
+
- `run_select_query` - Execute SELECT queries
|
|
323
|
+
- `execute_write_query` - Execute INSERT/UPDATE (DELETE requires the `delete` permission)
|
|
324
|
+
|
|
325
|
+
### 6. Schema Management (4 tools)
|
|
326
|
+
- `create_table` - Create new tables
|
|
327
|
+
- `alter_table` - Modify table structure
|
|
328
|
+
- `drop_table` - Delete tables
|
|
329
|
+
- `execute_ddl` - Execute raw DDL
|
|
330
|
+
|
|
331
|
+
### 7. Data Export (2 tools)
|
|
332
|
+
- `export_table_to_csv` - Export table data to CSV
|
|
333
|
+
- `export_query_to_csv` - Export SELECT query results to CSV
|
|
334
|
+
|
|
335
|
+
### 8. Index Management (11 tools)
|
|
336
|
+
- `list_indexes` - List table indexes
|
|
337
|
+
- `get_index_info` - Get index details
|
|
338
|
+
- `create_index` - Create indexes
|
|
339
|
+
- `drop_index` - Drop indexes
|
|
340
|
+
- `analyze_index` - Analyze and update index statistics
|
|
341
|
+
- `create_fulltext_index` - Create FULLTEXT indexes for text search
|
|
342
|
+
- `fulltext_search` - Perform full-text search with MATCH AGAINST
|
|
343
|
+
- `get_fulltext_info` - Get FULLTEXT index information
|
|
344
|
+
- `drop_fulltext_index` - Drop FULLTEXT indexes
|
|
345
|
+
- `get_fulltext_stats` - Get FULLTEXT index statistics
|
|
346
|
+
- `optimize_fulltext` - Optimize FULLTEXT indexes (requires `ddl`)
|
|
347
|
+
|
|
348
|
+
### 9. Constraint Management (7 tools)
|
|
349
|
+
- `list_foreign_keys` - List foreign keys
|
|
350
|
+
- `list_constraints` - List all constraints
|
|
351
|
+
- `add_foreign_key` - Add foreign key
|
|
352
|
+
- `drop_foreign_key` - Remove foreign key
|
|
353
|
+
- `add_unique_constraint` - Add unique constraint
|
|
354
|
+
- `drop_constraint` - Remove constraint
|
|
355
|
+
- `add_check_constraint` - Add check constraint
|
|
356
|
+
|
|
357
|
+
### 10. Stored Procedures (6 tools)
|
|
358
|
+
- `list_stored_procedures` - List procedures
|
|
359
|
+
- `get_stored_procedure_info` - Get procedure details
|
|
360
|
+
- `execute_stored_procedure` - Execute procedures
|
|
361
|
+
- `create_stored_procedure` - Create procedures
|
|
362
|
+
- `drop_stored_procedure` - Remove procedures
|
|
363
|
+
- `show_create_procedure` - Show CREATE statement
|
|
364
|
+
|
|
365
|
+
### 11. Views Management (6 tools)
|
|
366
|
+
- `list_views` - List views
|
|
367
|
+
- `get_view_info` - Get view details
|
|
368
|
+
- `create_view` - Create views
|
|
369
|
+
- `alter_view` - Modify views
|
|
370
|
+
- `drop_view` - Remove views
|
|
371
|
+
- `show_create_view` - Show CREATE statement
|
|
372
|
+
|
|
373
|
+
### 12. Triggers Management (5 tools)
|
|
374
|
+
- `list_triggers` - List triggers
|
|
375
|
+
- `get_trigger_info` - Get trigger details
|
|
376
|
+
- `create_trigger` - Create triggers
|
|
377
|
+
- `drop_trigger` - Remove triggers
|
|
378
|
+
- `show_create_trigger` - Show CREATE statement
|
|
379
|
+
|
|
380
|
+
### 13. Table Maintenance (8 tools)
|
|
381
|
+
- `analyze_table` - Update statistics
|
|
382
|
+
- `optimize_table` - Reclaim space (requires `ddl`)
|
|
383
|
+
- `check_table` - Check for errors
|
|
384
|
+
- `repair_table` - Repair corrupted tables (requires `ddl`)
|
|
385
|
+
- `truncate_table` - Remove all rows
|
|
386
|
+
- `get_table_status` - Get table statistics
|
|
387
|
+
- `flush_table` - Close/reopen tables in the connected database (requires `ddl`)
|
|
388
|
+
- `get_table_size` - Get size information
|
|
389
|
+
|
|
390
|
+
### 14. Transaction Management (5 tools)
|
|
391
|
+
- `begin_transaction` - Start transaction
|
|
392
|
+
- `commit_transaction` - Commit transaction
|
|
393
|
+
- `rollback_transaction` - Rollback transaction
|
|
394
|
+
- `get_transaction_status` - Check transaction state
|
|
395
|
+
- `execute_in_transaction` - Execute within transaction
|
|
396
|
+
|
|
397
|
+
### 15. Query Optimization (3 tools)
|
|
398
|
+
- `analyze_query` - Analyze query performance
|
|
399
|
+
- `get_optimization_hints` - Get optimizer hints
|
|
400
|
+
- `repair_query` - Repair broken SQL queries
|
|
401
|
+
|
|
402
|
+
### 16. Utilities (5 tools)
|
|
403
|
+
- `test_connection` - Test connectivity
|
|
404
|
+
- `describe_connection` - Connection info
|
|
405
|
+
- `read_changelog` - Read changelog
|
|
406
|
+
- `cursor_execute_request` - Execute a file-backed request for clients that cannot send MCP arguments
|
|
407
|
+
- `list_all_tools` - Runtime tool catalog with agent guidance
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## Core Operations
|
|
412
|
+
|
|
413
|
+
### Database Discovery
|
|
414
|
+
|
|
415
|
+
Start with these tools to explore any database:
|
|
416
|
+
|
|
417
|
+
```javascript
|
|
418
|
+
// List all databases
|
|
419
|
+
await mcp.call("list_databases", {});
|
|
420
|
+
|
|
421
|
+
// List tables in current database
|
|
422
|
+
await mcp.call("list_tables", {});
|
|
423
|
+
|
|
424
|
+
// Get comprehensive overview
|
|
425
|
+
await mcp.call("get_database_summary", {
|
|
426
|
+
max_tables: 50,
|
|
427
|
+
include_relationships: true
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// Visualize relationships
|
|
431
|
+
await mcp.call("get_schema_erd", {});
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### Schema & Data Discovery
|
|
435
|
+
|
|
436
|
+
Use these tools when users ask natural-language questions like “which table stores survey data?” or “where is customer feedback saved?”:
|
|
437
|
+
|
|
438
|
+
```javascript
|
|
439
|
+
// Fast metadata search across table names, column names, and comments
|
|
440
|
+
await mcp.call("find_tables_by_keyword", {
|
|
441
|
+
keyword: "survey",
|
|
442
|
+
search_in: "all",
|
|
443
|
+
limit: 20
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// Unified discovery with optional guarded sample-data scan
|
|
447
|
+
await mcp.call("search_schema", {
|
|
448
|
+
query: "survey",
|
|
449
|
+
modes: ["table_names", "column_names", "comments", "sample_data"],
|
|
450
|
+
max_results: 20
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// Direct bounded data scan when the keyword may only exist in row values
|
|
454
|
+
await mcp.call("search_data_across_tables", {
|
|
455
|
+
keyword: "survey",
|
|
456
|
+
max_tables: 20,
|
|
457
|
+
limit_per_table: 3
|
|
458
|
+
});
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
`find_tables_by_keyword` requires `list`; `search_data_across_tables` requires `read`; `search_schema` uses `list` and requires `read` only when `sample_data` mode is enabled.
|
|
462
|
+
|
|
463
|
+
### Data Operations
|
|
464
|
+
|
|
465
|
+
Basic CRUD operations:
|
|
466
|
+
|
|
467
|
+
```javascript
|
|
468
|
+
// Create record
|
|
469
|
+
await mcp.call("create_record", {
|
|
470
|
+
table_name: "users",
|
|
471
|
+
data: { name: "John", email: "john@example.com" }
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// Read with filtering
|
|
475
|
+
await mcp.call("read_records", {
|
|
476
|
+
table_name: "users",
|
|
477
|
+
filters: [{ field: "status", operator: "eq", value: "active" }],
|
|
478
|
+
pagination: { page: 1, limit: 10 }
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// Update records
|
|
482
|
+
await mcp.call("update_record", {
|
|
483
|
+
table_name: "users",
|
|
484
|
+
data: { status: "inactive" },
|
|
485
|
+
conditions: [{ field: "last_login", operator: "lt", value: "2024-01-01" }]
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// Delete records
|
|
489
|
+
await mcp.call("delete_record", {
|
|
490
|
+
table_name: "users",
|
|
491
|
+
conditions: [{ field: "status", operator: "eq", value: "deleted" }]
|
|
492
|
+
});
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### Performance Operations
|
|
496
|
+
|
|
497
|
+
```javascript
|
|
498
|
+
// Analyze slow query
|
|
499
|
+
await mcp.call("analyze_query", {
|
|
500
|
+
query: "SELECT * FROM users WHERE email LIKE '%@gmail.com'"
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
// Get optimization hints
|
|
504
|
+
await mcp.call("get_optimization_hints", {
|
|
505
|
+
goal: "SPEED"
|
|
506
|
+
});
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
## Advanced Features
|
|
512
|
+
|
|
513
|
+
### Analysis
|
|
514
|
+
|
|
515
|
+
The server includes analysis tools for database insights:
|
|
516
|
+
|
|
517
|
+
- **Database Summary**: Provides readable overviews with statistics
|
|
518
|
+
- **ER Diagram Generation**: Automatic Mermaid.js diagrams
|
|
519
|
+
- **RAG Context**: Compact schema for LLM prompts, with optional `TABLE_COMMENT` / `COLUMN_COMMENT` inclusion and keyword filtering
|
|
520
|
+
- **Column Profiling**: Data quality and distribution analysis
|
|
521
|
+
- **Schema Keyword Discovery**: Ranked search for concepts across table names, column names, and metadata comments
|
|
522
|
+
- **Unified Search**: One entry point for schema and bounded sample-data discovery
|
|
523
|
+
- **Guarded Data Search**: Read-only LIKE scans across text-like columns with strict table/result limits
|
|
524
|
+
|
|
525
|
+
### Bulk Operations
|
|
526
|
+
|
|
527
|
+
For high-performance operations with large datasets:
|
|
528
|
+
|
|
529
|
+
- **Bulk Insert**: Handle thousands of records efficiently
|
|
530
|
+
- **Bulk Update**: Update multiple records with different conditions
|
|
531
|
+
- **Bulk Delete**: Delete multiple record sets in batches
|
|
532
|
+
|
|
533
|
+
### Relational Data Seeder
|
|
534
|
+
|
|
535
|
+
For dummy data on related tables, use the seed workflow:
|
|
536
|
+
|
|
537
|
+
```javascript
|
|
538
|
+
const plan = await mcp.call("plan_seed_data", {
|
|
539
|
+
target_tables: ["orders"],
|
|
540
|
+
rows_per_table: 20,
|
|
541
|
+
include_dependencies: true,
|
|
542
|
+
include_children: true,
|
|
543
|
+
random_seed: 42
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
await mcp.call("generate_seed_preview", {
|
|
547
|
+
plan_id: plan.plan_id,
|
|
548
|
+
max_preview_rows_per_table: 3
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
await mcp.call("execute_seed_plan", {
|
|
552
|
+
plan_id: plan.plan_id,
|
|
553
|
+
dry_run: false,
|
|
554
|
+
confirm_token: plan.confirm_token
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
await mcp.call("validate_seed_integrity", {
|
|
558
|
+
plan_id: plan.plan_id
|
|
559
|
+
});
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
`execute_seed_plan` defaults to dry-run, requires confirmation for writes, blocks production-like database names unless explicitly allowed, and uses transaction rollback on errors.
|
|
563
|
+
|
|
564
|
+
Composite FK/PK support resolves multi-column parent tuples together, so relations such as `(tenant_id, region_id)` or `(tenant_id, region_id, order_id)` are not mixed across different parent rows.
|
|
565
|
+
|
|
566
|
+
Advanced rule inference and templates:
|
|
567
|
+
|
|
568
|
+
```javascript
|
|
569
|
+
await mcp.call("infer_seed_rules", {
|
|
570
|
+
tables: ["orders", "order_items"],
|
|
571
|
+
domain: "ecommerce",
|
|
572
|
+
sample_size: 25
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
await mcp.call("seed_from_template", {
|
|
576
|
+
template: "ecommerce",
|
|
577
|
+
scale: "small",
|
|
578
|
+
random_seed: 42
|
|
579
|
+
});
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
`seed_from_template` is plan-first and does not write data directly. Review its plan/preview, then execute with `execute_seed_plan`.
|
|
583
|
+
|
|
584
|
+
### Transaction Management
|
|
585
|
+
|
|
586
|
+
ACID transactions run on a dedicated connection. Run statements inside a transaction with `execute_in_transaction`; other tools such as `create_record` run outside it.
|
|
587
|
+
|
|
588
|
+
```javascript
|
|
589
|
+
const { transactionId } = await mcp.call("begin_transaction", {});
|
|
590
|
+
await mcp.call("execute_in_transaction", {
|
|
591
|
+
transactionId,
|
|
592
|
+
query: "INSERT INTO orders (customer_id, total) VALUES (?, ?)",
|
|
593
|
+
params: [42, 99.5]
|
|
594
|
+
});
|
|
595
|
+
await mcp.call("execute_in_transaction", {
|
|
596
|
+
transactionId,
|
|
597
|
+
query: "UPDATE inventory SET stock = stock - 1 WHERE product_id = ?",
|
|
598
|
+
params: [7]
|
|
599
|
+
});
|
|
600
|
+
await mcp.call("commit_transaction", { transactionId }); // or rollback_transaction
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
- `begin_transaction` accepts an optional `transactionId`. An id that is already in use is rejected (v1.45.0).
|
|
604
|
+
- `get_transaction_status` returns `activeTransactions`, the ids open in the caller's session (v1.45.0; earlier versions returned only a count message).
|
|
605
|
+
- Open transactions are rolled back after 30 minutes of inactivity or 1 hour in total. Over HTTP they are also rolled back when their session ends (see [Sessions](#sessions)).
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## Security Features
|
|
610
|
+
|
|
611
|
+
### Permission-Based Access Control
|
|
612
|
+
|
|
613
|
+
- **Layer 1**: Broad permission categories (list, read, create, etc.)
|
|
614
|
+
- **Layer 2**: Fine-grained tool category filtering
|
|
615
|
+
- **Tool-level**: Each tool requires specific permissions
|
|
616
|
+
- **Execution-time enforcement**: Tool permissions and categories are checked for every call, including file-backed Cursor requests.
|
|
617
|
+
- **Mandatory SQL restrictions**: File access, account/privilege changes, dangerous server operations, comments, and multiple statements remain blocked even with `execute`. Execute permission permits advanced SELECT features, not bypassing these restrictions.
|
|
618
|
+
- **Quoted content (v1.44.0)**: Comment, statement-separator, and keyword checks ignore the contents of string literals and quoted identifiers, so values such as `'#fff'`, `'a;b'`, or `'x -- y'` are accepted. A literal containing a backslash is lexed differently depending on `NO_BACKSLASH_ESCAPES`, so such queries are checked strictly against the raw text.
|
|
619
|
+
- **Common table expressions (v1.44.0)**: `WITH ... SELECT/UPDATE/DELETE` is authorized as its main statement. Like derived tables and UNION, a CTE in a read query requires `execute`. A `WITH` clause that cannot be parsed is rejected.
|
|
620
|
+
|
|
621
|
+
### Vulnerability Reporting
|
|
622
|
+
|
|
623
|
+
Suspected security issues must be reported privately via GitHub Private Vulnerability Reporting; see `SECURITY.md` for the policy, reporting requirements, and disclosure timeline (added 2026-10-12 21:16:54).
|
|
624
|
+
|
|
625
|
+
### Data Protection
|
|
626
|
+
|
|
627
|
+
- **Query Validation**: Input validation and SQL injection prevention
|
|
628
|
+
- **No result masking**: Query and export results are returned unmasked. Restrict sensitive columns with database privileges or views.
|
|
629
|
+
|
|
630
|
+
### Remote Access Security (v1.45.0)
|
|
631
|
+
|
|
632
|
+
- **Opt-in HTTP**: the Streamable HTTP transport is off unless `MCP_TRANSPORT=http` or `--transport=http` is set. See [Remote Access](#remote-access-streamable-http-transport-v1450-2026-10-26-144606).
|
|
633
|
+
- **Authentication**: bearer tokens or OAuth 2.1 JWT validation. Unauthenticated mode is restricted to loopback.
|
|
634
|
+
- **DNS-rebinding protection**: `Host` and `Origin` headers are checked against allowlists.
|
|
635
|
+
- **Session isolation**: sessions are bound to their identity, and transactions to their session.
|
|
636
|
+
- **Database protection**: query timeout with server-side cancellation, a per-client rate limit, a result size limit, and an audit log.
|
|
637
|
+
|
|
638
|
+
### Connection Security
|
|
639
|
+
|
|
640
|
+
- **Environment Variables**: Secure credential management
|
|
641
|
+
- **Connection Testing**: Validation before operations
|
|
642
|
+
- **Error Handling**: Comprehensive error reporting
|
|
643
|
+
|
|
644
|
+
---
|
|
645
|
+
|
|
646
|
+
---
|
|
647
|
+
|
|
648
|
+
## Troubleshooting
|
|
649
|
+
|
|
650
|
+
### Common Issues
|
|
651
|
+
|
|
652
|
+
1. **Permission Denied**: Check both permission layers in error messages
|
|
653
|
+
2. **Connection Failed**: Verify database credentials and network
|
|
654
|
+
3. **Query Errors**: Use `repair_query` for diagnosis
|
|
655
|
+
4. **Performance Issues**: Use `analyze_query` and optimization hints
|
|
656
|
+
|
|
657
|
+
### MCP error `-32000: Connection closed` (local server)
|
|
658
|
+
|
|
659
|
+
If your client reports `MCP error -32000: Connection closed`, the server process is usually crashing on startup.
|
|
660
|
+
|
|
661
|
+
If you see `ReferenceError: exports is not defined in ES module scope` in the server stderr logs, update to **v1.33.2+** (fixes an ESM/CJS mismatch that caused the MCP process to exit immediately).
|
|
662
|
+
|
|
663
|
+
### Development
|
|
664
|
+
|
|
665
|
+
- `npm run build` removes `dist/` before compiling, so files deleted from `src/` are never published.
|
|
666
|
+
- `npm run dev` runs `src/mcp-server.ts` with ts-node (fixed in v1.44.0).
|
|
667
|
+
- `npm test` runs the Jest suite in `src/__tests__/` (SQL validator, permission defaults, cache invalidation; since v1.45.0 also runtime config, bearer/OAuth authentication, the Streamable HTTP server, tool annotations, grant inspection, and rate limiting). None of these tests need a database.
|
|
668
|
+
|
|
669
|
+
### Error Messages
|
|
670
|
+
|
|
671
|
+
The system provides detailed error messages indicating:
|
|
672
|
+
|
|
673
|
+
- Which permission layer blocked access
|
|
674
|
+
- Required permissions vs current permissions
|
|
675
|
+
- Specific category requirements
|
|
676
|
+
- SQL syntax and logic errors
|
|
677
|
+
|
|
678
|
+
---
|
|
679
|
+
|
|
680
|
+
*For detailed examples and advanced usage patterns, see the project README.md.*
|