@berthojoris/mcp-mysql-server 1.43.5 → 1.45.2

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/DOCUMENTATIONS.md +674 -508
  3. package/README.md +468 -376
  4. package/bin/mcp-mysql.js +214 -168
  5. package/dist/cache/queryCache.js +1 -1
  6. package/dist/config/config.js +2 -1
  7. package/dist/config/featureConfig.d.ts +5 -0
  8. package/dist/config/featureConfig.js +11 -13
  9. package/dist/config/runtimeConfig.d.ts +50 -0
  10. package/dist/config/runtimeConfig.js +173 -0
  11. package/dist/db/connection.d.ts +40 -1
  12. package/dist/db/connection.js +188 -22
  13. package/dist/mcp-server.js +248 -375
  14. package/dist/security/grantInspector.d.ts +5 -0
  15. package/dist/security/grantInspector.js +32 -0
  16. package/dist/security/securityLayer.d.ts +21 -2
  17. package/dist/security/securityLayer.js +151 -21
  18. package/dist/server/auditLogger.d.ts +24 -0
  19. package/dist/server/auditLogger.js +60 -0
  20. package/dist/server/auth.d.ts +56 -0
  21. package/dist/server/auth.js +274 -0
  22. package/dist/server/httpServer.d.ts +22 -0
  23. package/dist/server/httpServer.js +320 -0
  24. package/dist/server/rateLimiter.d.ts +15 -0
  25. package/dist/server/rateLimiter.js +41 -0
  26. package/dist/server/requestContext.d.ts +12 -0
  27. package/dist/server/requestContext.js +9 -0
  28. package/dist/tools/toolAnnotations.d.ts +4 -0
  29. package/dist/tools/toolAnnotations.js +73 -0
  30. package/dist/tools/toolArgumentValidation.js +22 -22
  31. package/dist/tools/toolRegistry.d.ts +1 -1
  32. package/dist/tools/toolRegistry.js +7 -1
  33. package/manifest.json +1 -1
  34. package/package.json +86 -78
  35. package/dist/auth/authService.d.ts +0 -29
  36. package/dist/auth/authService.js +0 -114
  37. package/dist/tools/backupRestoreTools.d.ts +0 -18
  38. package/dist/tools/backupRestoreTools.js +0 -70
  39. package/dist/tools/documentationGeneratorTools.d.ts +0 -145
  40. package/dist/tools/documentationGeneratorTools.js +0 -820
  41. package/dist/tools/forecastingTools.d.ts +0 -36
  42. package/dist/tools/forecastingTools.js +0 -256
  43. package/dist/tools/functionTools.d.ts +0 -87
  44. package/dist/tools/functionTools.js +0 -358
  45. package/dist/tools/indexRecommendationTools.d.ts +0 -50
  46. package/dist/tools/indexRecommendationTools.js +0 -451
  47. package/dist/tools/intelligentQueryTools.d.ts +0 -94
  48. package/dist/tools/intelligentQueryTools.js +0 -713
  49. package/dist/tools/performanceTools.d.ts +0 -76
  50. package/dist/tools/performanceTools.js +0 -505
  51. package/dist/tools/processTools.d.ts +0 -61
  52. package/dist/tools/processTools.js +0 -181
  53. package/dist/tools/queryVisualizationTools.d.ts +0 -22
  54. package/dist/tools/queryVisualizationTools.js +0 -155
  55. package/dist/tools/schemaDesignTools.d.ts +0 -67
  56. package/dist/tools/schemaDesignTools.js +0 -359
  57. package/dist/tools/schemaPatternTools.d.ts +0 -19
  58. package/dist/tools/schemaPatternTools.js +0 -253
  59. package/dist/tools/schemaVersioningTools.d.ts +0 -138
  60. package/dist/tools/schemaVersioningTools.js +0 -1008
  61. package/dist/tools/securityAuditTools.d.ts +0 -39
  62. package/dist/tools/securityAuditTools.js +0 -319
  63. package/dist/tools/smartDiscoveryTools.d.ts +0 -163
  64. package/dist/tools/smartDiscoveryTools.js +0 -750
  65. package/dist/tools/testDataTools.d.ts +0 -26
  66. package/dist/tools/testDataTools.js +0 -325
package/README.md CHANGED
@@ -1,376 +1,468 @@
1
- # MySQL MCP Server
2
-
3
- <div align="center">
4
-
5
- **A production-ready Model Context Protocol (MCP) server for MySQL database integration with AI agents**
6
-
7
- **Last Updated:** 2026-10-22 19:50:16
8
-
9
- [![npm version](https://img.shields.io/npm/v/@berthojoris/mcp-mysql-server)](https://www.npmjs.com/package/@berthojoris/mcp-mysql-server)
10
- [![npm downloads](https://img.shields.io/npm/dm/@berthojoris/mcp-mysql-server)](https://www.npmjs.com/package/@berthojoris/mcp-mysql-server)
11
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
12
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
13
- [![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-green.svg)](https://modelcontextprotocol.io/)
14
-
15
- [Installation](#-installation) · [Quick Start](#-quick-start) · [Configuration](#-ai-agent-configuration) · [Permissions](#-permission-system) · [Tools](#-available-tools) · [Documentation](DOCUMENTATIONS.md)
16
-
17
- </div>
18
-
19
- ---
20
-
21
- ## TL;DR - Quick Setup
22
-
23
- Run directly with `npx`:
24
-
25
- ```bash
26
- npx @berthojoris/mcp-mysql-server mysql://user:pass@localhost:3306/mydb "list,read,utility"
27
- ```
28
-
29
- Add to your AI agent config (`.mcp.json`, `.cursor/mcp.json`, etc.):
30
-
31
- ```json
32
- {
33
- "mcpServers": {
34
- "mysql": {
35
- "command": "npx",
36
- "type": "stdio",
37
- "args": [
38
- "-y",
39
- "@berthojoris/mcp-mysql-server",
40
- "mysql://user:pass@localhost:3306/mydb",
41
- "list,read,utility"
42
- ]
43
- }
44
- }
45
- }
46
- ```
47
-
48
- For agent-specific examples (Codex TOML, Zed, local path, multi-DB), see **[DOCUMENTATIONS.md → Setup & Configuration](DOCUMENTATIONS.md#setup--configuration-extended)**.
49
-
50
- ---
51
-
52
- ## Installation
53
-
54
- ### Option 1: Quick Start with npx (Recommended)
55
-
56
- No installation required - run directly:
57
-
58
- ```bash
59
- npx @berthojoris/mcp-mysql-server mysql://user:pass@localhost:3306/db "list,read,utility"
60
- ```
61
-
62
- ### Option 2: Global Installation
63
-
64
- ```bash
65
- npm install -g @berthojoris/mcp-mysql-server
66
- mcp-mysql mysql://user:pass@localhost:3306/db "list,read,utility"
67
- ```
68
-
69
- > **Credentials with special characters**: if your username or password contains characters that have a special meaning in URLs (`@`, `:`, `/`, `?`, `#`, `%`, `&`, etc.), URL-encode them before putting them in the connection string. For example, the password `p@ss:w0rd` becomes `p%40ss%3Aw0rd`, giving `mysql://user:p%40ss%3Aw0rd@host:3306/db`. The server decodes both the username and password before connecting.
70
-
71
- ---
72
-
73
- ## Quick Start
74
-
75
- ### 1. Set Up Environment (Optional)
76
-
77
- Create `.env` file for local development:
78
-
79
- ```env
80
- DB_HOST=localhost
81
- DB_PORT=3306
82
- DB_USER=root
83
- DB_PASSWORD=yourpassword
84
- DB_NAME=yourdatabase
85
- MCP_CONFIG=list,read,utility
86
- ```
87
-
88
- ### 2. Build Project (If Cloned Locally)
89
-
90
- ```bash
91
- npm install
92
- npm run build
93
- ```
94
-
95
- ### 3. Configure Your AI Agent
96
-
97
- See [AI Agent Configuration](#-ai-agent-configuration) section below.
98
-
99
- ### 4. Restart Your AI Agent
100
-
101
- Completely restart your AI agent application to load the MCP server.
102
-
103
- ### 5. Test It!
104
-
105
- Try asking your AI:
106
-
107
- > "What databases are available?"
108
- > "Show me all tables in my database"
109
- > "What's the structure of the users table?"
110
- > "Show me the first 5 records from users"
111
-
112
- ---
113
-
114
- ## AI Agent Configuration
115
-
116
- ### Standard JSON Configuration
117
-
118
- Most AI agents use a similar JSON configuration format (the file location varies by tool).
119
-
120
- If you want ready-to-copy snippets per client (Claude Code/Cursor/Windsurf/Cline/Codex/Zed), see **[DOCUMENTATIONS.md → Agent Configuration Examples](DOCUMENTATIONS.md#agent-configuration-examples)**.
121
-
122
- **Universal Configuration Template:**
123
-
124
- **Option 1: Single-Layer (Permissions Only) - Simple Setup**
125
- ```json
126
- {
127
- "mcpServers": {
128
- "mysql": {
129
- "command": "npx",
130
- "type": "stdio",
131
- "args": [
132
- "-y",
133
- "@berthojoris/mcp-mysql-server",
134
- "mysql://user:password@localhost:3306/database",
135
- "list,read,utility,create,update,ddl"
136
- ]
137
- }
138
- }
139
- }
140
- ```
141
-
142
- **Option 2: Dual-Layer (Permissions + Categories) - Recommended for Fine Control**
143
- ```json
144
- {
145
- "mcpServers": {
146
- "mysql": {
147
- "command": "npx",
148
- "type": "stdio",
149
- "args": [
150
- "-y",
151
- "@berthojoris/mcp-mysql-server",
152
- "mysql://user:password@localhost:3306/database_name_here",
153
- "list,read,utility,create,update,ddl,transaction",
154
- "database_discovery,crud_operations,custom_queries,schema_management,index_management,constraint_management,table_maintenance,query_optimization,analysis,seed_operations"
155
- ]
156
- }
157
- }
158
- }
159
- ```
160
-
161
- > **💡 Tip:** The dual-layer approach provides granular control. The 4th argument (permissions) controls broad access levels, while the 5th argument (categories) fine-tunes which specific tools are available.
162
-
163
- ### Environment Variables Configuration
164
-
165
- Alternative approach using environment variables instead of connection string:
166
-
167
- **Option 1: Permissions Only (Simple)**
168
-
169
- ```json
170
- {
171
- "mcpServers": {
172
- "mysql": {
173
- "command": "npx",
174
- "type": "stdio",
175
- "args": ["-y", "@berthojoris/mcp-mysql-server"],
176
- "env": {
177
- "DB_HOST": "localhost",
178
- "DB_PORT": "3306",
179
- "DB_USER": "root",
180
- "DB_PASSWORD": "your_password",
181
- "DB_NAME": "your_database",
182
- "MCP_PERMISSIONS": "list,read,utility,create,update,delete"
183
- }
184
- }
185
- }
186
- }
187
- ```
188
-
189
- **Option 2: Permissions + Categories (Recommended)**
190
-
191
- ```json
192
- {
193
- "mcpServers": {
194
- "mysql": {
195
- "command": "npx",
196
- "type": "stdio",
197
- "args": ["-y", "@berthojoris/mcp-mysql-server"],
198
- "env": {
199
- "DB_HOST": "localhost",
200
- "DB_PORT": "3306",
201
- "DB_USER": "root",
202
- "DB_PASSWORD": "your_password",
203
- "DB_NAME": "your_database",
204
- "MCP_PERMISSIONS": "list,read,utility,create,update,delete",
205
- "MCP_CATEGORIES": "database_discovery,custom_queries,analysis"
206
- }
207
- }
208
- }
209
- }
210
- ```
211
-
212
- For more client-specific config snippets, see **[DOCUMENTATIONS.md → Setup & Configuration](DOCUMENTATIONS.md#setup--configuration-extended)**.
213
-
214
- ---
215
-
216
- ### Cursor Compatibility Bridge
217
-
218
- If a Cursor MCP wrapper can call tools but cannot send `arguments`, use the no-argument `cursor_execute_request` bridge. Create `.cursor/mysql-mcp-request.json` in the workspace, then call `cursor_execute_request`:
219
-
220
- ```json
221
- {
222
- "tool": "execute_ddl",
223
- "arguments": {
224
- "query": "DROP TABLE IF EXISTS spark_processes;"
225
- }
226
- }
227
- ```
228
-
229
- For direct SQL, the bridge can infer the right SQL tool:
230
-
231
- ```json
232
- {
233
- "query": "DROP TABLE IF EXISTS spark_processes;",
234
- "mode": "auto"
235
- }
236
- ```
237
-
238
- Set `MYSQL_MCP_CURSOR_REQUEST_FILE` to override the request file path.
239
-
240
- ---
241
-
242
- ### AI Agent Tool Discovery
243
-
244
- For Codex, Claude Code CLI, Cursor, Droid CLI, and other MCP agents, call `list_all_tools` first. It returns the live runtime catalog, enabled/disabled status, active permission/category profile, and recommended workflows for schema exploration, safe SELECT queries, CSV exports, transactions, and data changes.
245
-
246
- Use `export_table_to_csv` for table-based exports and `export_query_to_csv` for SELECT query exports.
247
-
248
- ---
249
-
250
- ## Permission System
251
-
252
- Control database access with a **dual-layer filtering system** that provides both broad and fine-grained control:
253
-
254
- - **Layer 1 (Permissions)**: Broad operation-level control using legacy categories
255
- - **Layer 2 (Categories)**: Optional fine-grained tool-level filtering using documentation categories
256
-
257
- **Filtering Logic**: `Tool enabled = (Has Permission) AND (Has Category OR No categories specified)`
258
-
259
- ### Permissions
260
-
261
- | Permission | Operations | Use Case |
262
- |------------|------------|----------|
263
- | `list` | List databases, tables, schemas | Database exploration |
264
- | `read` | SELECT queries, read data | Analytics, reporting |
265
- | `create` | INSERT new records | Data entry |
266
- | `update` | UPDATE existing records | Data maintenance |
267
- | `delete` | DELETE records | Data cleanup |
268
- | `execute` | Execute custom INSERT/UPDATE SQL (DELETE requires `delete` permission too) | Complex write operations |
269
- | `ddl` | CREATE/ALTER/DROP tables | Schema management |
270
- | `procedure` | Stored procedures (CREATE/DROP/EXECUTE) | Procedure management |
271
- | `transaction` | BEGIN, COMMIT, ROLLBACK | ACID operations |
272
- | `utility` | Connection testing, diagnostics | Troubleshooting |
273
-
274
- **Security changes in v1.43.4:**
275
- - `EXPLAIN ANALYZE` runs the statement it wraps (MySQL 8.0.18+), so it now requires that statement's permission: `delete` for DELETE, `update` or `execute` for UPDATE, `read` for SELECT. Plan-only `EXPLAIN` still needs just `list` or `read`.
276
-
277
- **Security changes in v1.43.3:**
278
- - CSV exports require both `utility` and `read`; enable the `utilities` category when filtering categories.
279
- - SQL within a transaction requires the corresponding operation permission. `transaction` alone does not permit reads or writes.
280
- - `execute_write_query` accepts only INSERT/UPDATE/DELETE. DDL requires enabled DDL tools.
281
- - Disabled tools cannot be called directly or through the Cursor bridge. The bridge requires `utility` and an enabled destination tool.
282
- - `execute` does not bypass mandatory SQL safety restrictions, including file access and account/privilege changes.
283
-
284
- Report suspected security issues privately via [Private Vulnerability Reporting](https://github.com/berthojoris/mysql-mcp/security/advisories/new); see [SECURITY.md](SECURITY.md) for the policy.
285
-
286
- Common configuration examples are documented in **[DOCUMENTATIONS.md → Category Filtering System](DOCUMENTATIONS.md#🆕-category-filtering-system)**.
287
-
288
- ---
289
-
290
- ### Documentation Categories (Recommended)
291
-
292
- Use documentation categories to fine-tune which tools are exposed (Layer 2):
293
-
294
- | Category List | Use Case | List Tools |
295
- |---------------|----------|-----------|
296
- | `database_discovery` | Explore databases, tables, and schema structure | `get_all_tables_relationships, list_databases, list_tables, read_table_schema` |
297
- | `crud_operations` | Create, read, update, delete operations on data | `create_record, delete_record, read_records, update_record` |
298
- | `bulk_operations` | High-performance batch processing operations | `bulk_delete, bulk_insert, bulk_update` |
299
- | `seed_operations` | FK-aware relational dummy data seeding | `execute_seed_plan, generate_seed_preview, infer_seed_rules, plan_seed_data, seed_from_template, validate_seed_integrity` |
300
- | `custom_queries` | Execute custom SQL queries and advanced operations | `execute_write_query, run_select_query` |
301
- | `schema_management` | Manage database schema, tables, and structure | `alter_table, create_table, drop_table, execute_ddl` |
302
- | `utilities` | Database utilities, diagnostics, and helper functions | `cursor_execute_request, describe_connection, export_query_to_csv, export_table_to_csv, list_all_tools, read_changelog, test_connection` |
303
- | `transaction_management` | Handle ACID transactions and rollback operations | `begin_transaction, commit_transaction, execute_in_transaction, get_transaction_status, rollback_transaction` |
304
- | `stored_procedures` | Create, execute, and manage stored procedures | `create_stored_procedure, drop_stored_procedure, execute_stored_procedure, get_stored_procedure_info, list_stored_procedures, show_create_procedure` |
305
- | `views_management` | Create and manage database views | `alter_view, create_view, drop_view, get_view_info, list_views, show_create_view` |
306
- | `triggers_management` | Create and manage database triggers | `create_trigger, drop_trigger, get_trigger_info, list_triggers, show_create_trigger` |
307
- | `index_management` | Optimize performance with index and fulltext management | `analyze_index, create_fulltext_index, create_index, drop_fulltext_index, drop_index, fulltext_search, get_fulltext_info, get_fulltext_stats, get_index_info, list_indexes, optimize_fulltext` |
308
- | `constraint_management` | Manage data integrity constraints | `add_check_constraint, add_foreign_key, add_unique_constraint, drop_constraint, drop_foreign_key, list_constraints, list_foreign_keys` |
309
- | `table_maintenance` | Table optimization, repair, and maintenance | `analyze_table, check_table, flush_table, get_table_size, get_table_status, optimize_table, repair_table, truncate_table` |
310
- | `query_optimization` | Analyze and optimize SQL queries | `analyze_query, get_optimization_hints, repair_query` |
311
- | `analysis` | Data analysis, schema discovery, and reporting tools | `find_tables_by_keyword, get_column_statistics, get_database_summary, get_schema_erd, get_schema_rag_context, search_data_across_tables, search_schema` |
312
-
313
- <details>
314
- <summary>Copy/paste list (comma-separated, no spaces)</summary>
315
-
316
- ```text
317
- database_discovery,crud_operations,bulk_operations,seed_operations,custom_queries,schema_management,utilities,transaction_management,stored_procedures,views_management,triggers_management,index_management,constraint_management,table_maintenance,query_optimization,analysis
318
- ```
319
-
320
- </details>
321
-
322
- Full category → tool mapping (and examples) lives in **[DOCUMENTATIONS.md → Category Filtering System](DOCUMENTATIONS.md#🆕-category-filtering-system)**.
323
-
324
- ---
325
-
326
- ## Available Tools
327
-
328
- The server exposes **88 tools** organized into categories (CRUD, seed, schema, discovery, and utilities).
329
-
330
- - Complete list of tools: **[DOCUMENTATIONS.md → Complete Tools Reference](DOCUMENTATIONS.md#🔧-complete-tools-reference)**
331
-
332
- ---
333
-
334
- ## Detailed Documentation
335
-
336
- For comprehensive documentation, see **[DOCUMENTATIONS.md](DOCUMENTATIONS.md)**:
337
-
338
- - **DDL Operations** - Create, alter, and drop tables
339
- - **Data Export Tools** - Export data to CSV format
340
- - **Relational Data Seeder** - Plan, preview, execute, validate, infer rules, and template FK-aware dummy data
341
- - **Full-Text Search** - Create and search FULLTEXT indexes with multiple search modes
342
- - **Transaction Management** - ACID transactions
343
- - **Stored Procedures** - Create and execute with IN/OUT/INOUT parameters
344
- - **Views & Triggers** - Manage database views and triggers
345
- - **Index & Constraint Management** - Optimize performance and enforce data integrity
346
- - **Table Maintenance** - Analyze, optimize, check, and repair tables
347
- - **Query Logging** - See all SQL queries executed automatically
348
- - **Security Features** - Built-in security and best practices
349
- - **Bulk Operations** - High-performance batch processing
350
- - **Troubleshooting** - Common issues and solutions
351
-
352
- ---
353
-
354
- ## MySQL MCP vs Manual Database Access
355
-
356
- This MySQL MCP is a **powerful intermediary layer** between AI assistants and MySQL databases.
357
-
358
- For full feature coverage and usage examples, see **[DOCUMENTATIONS.md](DOCUMENTATIONS.md)**.
359
-
360
- ---
361
-
362
- ## License
363
-
364
- MIT License - see [LICENSE](LICENSE) file for details.
365
-
366
- ---
367
-
368
- <div align="center">
369
-
370
- **Made with care for the AI development community**
371
-
372
- *Enabling AI agents to interact with MySQL databases safely and efficiently*
373
-
374
- [Report Bug](https://github.com/berthojoris/mysql-mcp/issues) · [Request Feature](https://github.com/berthojoris/mysql-mcp/issues) · [Documentation](DOCUMENTATIONS.md)
375
-
376
- </div>
1
+ # MySQL MCP Server
2
+
3
+ <div align="center">
4
+
5
+ **A production-ready Model Context Protocol (MCP) server for MySQL database integration with AI agents**
6
+
7
+ **Last Updated:** 2026-10-26 15:57:37
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@berthojoris/mcp-mysql-server)](https://www.npmjs.com/package/@berthojoris/mcp-mysql-server)
10
+ [![npm downloads](https://img.shields.io/npm/dm/@berthojoris/mcp-mysql-server)](https://www.npmjs.com/package/@berthojoris/mcp-mysql-server)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
12
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
13
+ [![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-green.svg)](https://modelcontextprotocol.io/)
14
+
15
+ [Installation](#installation) · [Quick Start](#quick-start) · [Configuration](#ai-agent-configuration) · [Remote Access](#remote-access-chatgpt--other-remote-mcp-clients) · [Permissions](#permission-system) · [Tools](#available-tools) · [Documentation](DOCUMENTATIONS.md)
16
+
17
+ </div>
18
+
19
+ ---
20
+
21
+ ## TL;DR - Quick Setup
22
+
23
+ Run directly with `npx`:
24
+
25
+ ```bash
26
+ npx @berthojoris/mcp-mysql-server mysql://user:pass@localhost:3306/mydb "list,read,utility"
27
+ ```
28
+
29
+ Add to your AI agent config (`.mcp.json`, `.cursor/mcp.json`, etc.):
30
+
31
+ ```json
32
+ {
33
+ "mcpServers": {
34
+ "mysql": {
35
+ "command": "npx",
36
+ "type": "stdio",
37
+ "args": [
38
+ "-y",
39
+ "@berthojoris/mcp-mysql-server",
40
+ "mysql://user:pass@localhost:3306/mydb",
41
+ "list,read,utility"
42
+ ]
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ For dual-layer and environment-variable configuration, see **[DOCUMENTATIONS.md → Configuration](DOCUMENTATIONS.md#configuration)**. To connect remote clients such as ChatGPT over HTTP, see [Remote Access](#remote-access-chatgpt--other-remote-mcp-clients).
49
+
50
+ ---
51
+
52
+ ## Installation
53
+
54
+ ### Option 1: Quick Start with npx (Recommended)
55
+
56
+ No installation required - run directly:
57
+
58
+ ```bash
59
+ npx @berthojoris/mcp-mysql-server mysql://user:pass@localhost:3306/db "list,read,utility"
60
+ ```
61
+
62
+ ### Option 2: Global Installation
63
+
64
+ ```bash
65
+ npm install -g @berthojoris/mcp-mysql-server
66
+ mcp-mysql mysql://user:pass@localhost:3306/db "list,read,utility"
67
+ ```
68
+
69
+ > **Credentials with special characters**: if your username or password contains characters that have a special meaning in URLs (`@`, `:`, `/`, `?`, `#`, `%`, `&`, etc.), URL-encode them before putting them in the connection string. For example, the password `p@ss:w0rd` becomes `p%40ss%3Aw0rd`, giving `mysql://user:p%40ss%3Aw0rd@host:3306/db`. The server decodes both the username and password before connecting.
70
+
71
+ ---
72
+
73
+ ## Quick Start
74
+
75
+ ### 1. Set Up Environment (Optional)
76
+
77
+ Create `.env` file for local development:
78
+
79
+ ```env
80
+ DB_HOST=localhost
81
+ DB_PORT=3306
82
+ DB_USER=root
83
+ DB_PASSWORD=yourpassword
84
+ DB_NAME=yourdatabase
85
+ MCP_CONFIG=list,read,utility
86
+ ```
87
+
88
+ ### 2. Build Project (If Cloned Locally)
89
+
90
+ ```bash
91
+ npm install
92
+ npm run build
93
+ ```
94
+
95
+ ### 3. Configure Your AI Agent
96
+
97
+ See [AI Agent Configuration](#ai-agent-configuration) section below.
98
+
99
+ ### 4. Restart Your AI Agent
100
+
101
+ Completely restart your AI agent application to load the MCP server.
102
+
103
+ ### 5. Test It!
104
+
105
+ Try asking your AI:
106
+
107
+ > "What databases are available?"
108
+ > "Show me all tables in my database"
109
+ > "What's the structure of the users table?"
110
+ > "Show me the first 5 records from users"
111
+
112
+ ---
113
+
114
+ ## AI Agent Configuration
115
+
116
+ ### Standard JSON Configuration
117
+
118
+ Most AI agents use a similar JSON configuration format (the file location varies by tool).
119
+
120
+ The examples below use the default stdio transport, where the AI agent starts the server itself. Remote clients connect over HTTP instead; see [Remote Access](#remote-access-chatgpt--other-remote-mcp-clients).
121
+
122
+ **Universal Configuration Template:**
123
+
124
+ **Option 1: Single-Layer (Permissions Only) - Simple Setup**
125
+ ```json
126
+ {
127
+ "mcpServers": {
128
+ "mysql": {
129
+ "command": "npx",
130
+ "type": "stdio",
131
+ "args": [
132
+ "-y",
133
+ "@berthojoris/mcp-mysql-server",
134
+ "mysql://user:password@localhost:3306/database",
135
+ "list,read,utility,create,update,ddl"
136
+ ]
137
+ }
138
+ }
139
+ }
140
+ ```
141
+
142
+ **Option 2: Dual-Layer (Permissions + Categories) - Recommended for Fine Control**
143
+ ```json
144
+ {
145
+ "mcpServers": {
146
+ "mysql": {
147
+ "command": "npx",
148
+ "type": "stdio",
149
+ "args": [
150
+ "-y",
151
+ "@berthojoris/mcp-mysql-server",
152
+ "mysql://user:password@localhost:3306/database_name_here",
153
+ "list,read,utility,create,update,ddl,transaction",
154
+ "database_discovery,crud_operations,custom_queries,schema_management,index_management,constraint_management,table_maintenance,query_optimization,analysis,seed_operations"
155
+ ]
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ > **💡 Tip:** The dual-layer approach provides granular control. The 4th argument (permissions) controls broad access levels, while the 5th argument (categories) fine-tunes which specific tools are available.
162
+
163
+ ### Environment Variables Configuration
164
+
165
+ Alternative approach using environment variables instead of connection string:
166
+
167
+ **Option 1: Permissions Only (Simple)**
168
+
169
+ ```json
170
+ {
171
+ "mcpServers": {
172
+ "mysql": {
173
+ "command": "npx",
174
+ "type": "stdio",
175
+ "args": ["-y", "@berthojoris/mcp-mysql-server"],
176
+ "env": {
177
+ "DB_HOST": "localhost",
178
+ "DB_PORT": "3306",
179
+ "DB_USER": "root",
180
+ "DB_PASSWORD": "your_password",
181
+ "DB_NAME": "your_database",
182
+ "MCP_PERMISSIONS": "list,read,utility,create,update,delete"
183
+ }
184
+ }
185
+ }
186
+ }
187
+ ```
188
+
189
+ **Option 2: Permissions + Categories (Recommended)**
190
+
191
+ ```json
192
+ {
193
+ "mcpServers": {
194
+ "mysql": {
195
+ "command": "npx",
196
+ "type": "stdio",
197
+ "args": ["-y", "@berthojoris/mcp-mysql-server"],
198
+ "env": {
199
+ "DB_HOST": "localhost",
200
+ "DB_PORT": "3306",
201
+ "DB_USER": "root",
202
+ "DB_PASSWORD": "your_password",
203
+ "DB_NAME": "your_database",
204
+ "MCP_PERMISSIONS": "list,read,utility,create,update,delete",
205
+ "MCP_CATEGORIES": "database_discovery,custom_queries,analysis"
206
+ }
207
+ }
208
+ }
209
+ }
210
+ ```
211
+
212
+ More configuration details are in **[DOCUMENTATIONS.md → Configuration](DOCUMENTATIONS.md#configuration)**.
213
+
214
+ ---
215
+
216
+ ### Cursor Compatibility Bridge
217
+
218
+ If a Cursor MCP wrapper can call tools but cannot send `arguments`, use the no-argument `cursor_execute_request` bridge. Create `.cursor/mysql-mcp-request.json` in the workspace, then call `cursor_execute_request`:
219
+
220
+ ```json
221
+ {
222
+ "tool": "execute_ddl",
223
+ "arguments": {
224
+ "query": "DROP TABLE IF EXISTS spark_processes;"
225
+ }
226
+ }
227
+ ```
228
+
229
+ For direct SQL, the bridge can infer the right SQL tool:
230
+
231
+ ```json
232
+ {
233
+ "query": "DROP TABLE IF EXISTS spark_processes;",
234
+ "mode": "auto"
235
+ }
236
+ ```
237
+
238
+ Set `MYSQL_MCP_CURSOR_REQUEST_FILE` to override the request file path.
239
+
240
+ ---
241
+
242
+ ### AI Agent Tool Discovery
243
+
244
+ For Codex, Claude Code CLI, Cursor, Droid CLI, and other MCP agents, call `list_all_tools` first. It returns the live runtime catalog, enabled/disabled status, active permission/category profile, and recommended workflows for schema exploration, safe SELECT queries, CSV exports, transactions, and data changes.
245
+
246
+ Use `export_table_to_csv` for table-based exports and `export_query_to_csv` for SELECT query exports.
247
+
248
+ ---
249
+
250
+ ### Remote Access (ChatGPT & other remote MCP clients)
251
+
252
+ stdio stays the default. For remote clients such as ChatGPT connectors / developer mode, you can enable the **Streamable HTTP** transport with a flag or an environment variable, the same way you set permissions. Remove the flag, or set `MCP_TRANSPORT=stdio`, to turn it off again.
253
+
254
+ ```bash
255
+ # Read-only MySQL account + bearer token, bound to localhost
256
+ export MCP_HTTP_AUTH=token
257
+ export MCP_HTTP_AUTH_TOKENS=$(openssl rand -hex 32) # give this token to your clients
258
+ npx -y @berthojoris/mcp-mysql-server mysql://mcp_reader:pass@localhost:3306/app "list,read,utility" --transport=http --port=3000
259
+ ```
260
+
261
+ - **Endpoint**: `http://127.0.0.1:3000/mcp`, plus `GET /health`. Publish it over HTTPS with a reverse proxy or tunnel, and set `MCP_HTTP_PUBLIC_URL`.
262
+ - **Auth**: `MCP_HTTP_AUTH=token` (bearer tokens) or `oauth` (OAuth 2.1 JWT validation against your authorization server, with RFC 9728 metadata, as needed by ChatGPT). `none` only works on loopback.
263
+ - **Isolation**: `Host`/`Origin` checks (DNS-rebinding protection). Each session is bound to its identity, and each transaction to its session. A session's open transactions are rolled back when it closes or expires.
264
+ - **Startup checks**: invalid or unsafe HTTP settings stop the server with an error. `MCP_HTTP_*` settings are ignored over stdio.
265
+ - **Tool annotations**: every tool reports `readOnlyHint` and `destructiveHint`.
266
+
267
+ #### Protection defaults
268
+
269
+ Protections are **on by default in HTTP mode and off by default over stdio**, so existing stdio setups behave as before. Every value can be overridden with an environment variable on either transport.
270
+
271
+ | Variable | stdio default | HTTP default | What it does |
272
+ |----------|---------------|--------------|--------------|
273
+ | `MCP_QUERY_TIMEOUT_MS` | `0` (off) | `30000` | Cancels longer statements on the MySQL server with `KILL QUERY`. A timed-out statement inside a transaction rolls that transaction back |
274
+ | `MCP_RATE_LIMIT_PER_MINUTE` | `0` (off) | `60` | Tool calls per client per minute. The client is the auth identity, or the IP when there is none |
275
+ | `MCP_MAX_RESULT_BYTES` | `0` (off) | `524288` | Maximum result size. Row arrays are truncated to fit; other oversized results return an error |
276
+ | `MCP_AUDIT_LOG` | `off` | `stderr` | `off`, `stderr`, or a file path. One JSON line per tool call, authentication failure, and session open/close. SQL text is logged; other argument values are not |
277
+ | `MCP_REQUIRE_READONLY_DB_USER` | `false` | `false` | `true` makes startup fail if the MySQL user can write. In HTTP mode a warning is always logged |
278
+
279
+ #### HTTP settings
280
+
281
+ | Variable / flag | Default | What it does |
282
+ |-----------------|---------|--------------|
283
+ | `MCP_TRANSPORT` / `--transport=stdio\|http`, `--http` | `stdio` | Turns the HTTP transport on or off |
284
+ | `MCP_HTTP_HOST` / `--host=` | `127.0.0.1` | Bind address |
285
+ | `MCP_HTTP_PORT` / `--port=` | `3000` | Port |
286
+ | `MCP_HTTP_PATH` | `/mcp` | Endpoint path |
287
+ | `MCP_HTTP_PUBLIC_URL` | – | Public HTTPS base URL. Required for `oauth` |
288
+ | `MCP_HTTP_AUTH` | `none` | `none` (loopback only), `token`, or `oauth` |
289
+ | `MCP_HTTP_AUTH_TOKENS` | – | Comma-separated bearer tokens, at least 32 characters each |
290
+ | `MCP_OAUTH_ISSUER` / `MCP_OAUTH_AUDIENCE` / `MCP_OAUTH_JWKS_URI` / `MCP_OAUTH_REQUIRED_SCOPES` | – / resource URL / discovered / – | OAuth 2.1 token validation |
291
+ | `MCP_HTTP_ALLOWED_HOSTS` | loopback names when bound to loopback | `Host` allowlist. Off (with a warning) when bound to a non-loopback address and neither this nor `MCP_HTTP_PUBLIC_URL` is set |
292
+ | `MCP_HTTP_ALLOWED_ORIGINS` | loopback origins when bound to loopback | Browser `Origin` allowlist. Requests without `Origin` are always allowed |
293
+ | `MCP_HTTP_TRUST_PROXY` | `false` | Take the client IP from `X-Forwarded-For` |
294
+ | `MCP_HTTP_ALLOW_UNAUTHENTICATED` | `false` | Allow `none` outside loopback (not recommended) |
295
+ | `MCP_HTTP_MAX_SESSIONS` | `100` | Maximum concurrent sessions (`0` = no limit) |
296
+ | `MCP_HTTP_SESSION_IDLE_TIMEOUT_MS` | `1800000` | Idle sessions close after this time, and their transactions roll back (`0` = never) |
297
+ | `MCP_HTTP_MAX_BODY_BYTES` | `1048576` | Maximum request body size (`0` = no limit) |
298
+
299
+ In HTTP mode the server runs as a standalone service, so put the settings in `.env` (or your process manager) instead of an MCP client's `command` config:
300
+
301
+ ```env
302
+ DB_HOST=localhost
303
+ DB_USER=mcp_reader
304
+ DB_PASSWORD=pass
305
+ DB_NAME=app
306
+ MCP_PERMISSIONS=list,read,utility
307
+ MCP_TRANSPORT=http
308
+ MCP_HTTP_PORT=3000
309
+ MCP_HTTP_AUTH=token
310
+ MCP_HTTP_AUTH_TOKENS=<64-hex-token>
311
+ MCP_QUERY_TIMEOUT_MS=15000
312
+ MCP_AUDIT_LOG=logs/mcp-audit.log
313
+ ```
314
+
315
+ From the directory that holds `.env`, start it with `node dist/mcp-server.js` (from a clone) or the `npx` command above (a connection string argument overrides the `DB_*` values). Then point clients that support remote MCP servers at the URL. For example, in Claude Code's `.mcp.json`:
316
+
317
+ ```json
318
+ {
319
+ "mcpServers": {
320
+ "mysql-remote": {
321
+ "type": "http",
322
+ "url": "http://127.0.0.1:3000/mcp",
323
+ "headers": { "Authorization": "Bearer <64-hex-token>" }
324
+ }
325
+ }
326
+ }
327
+ ```
328
+
329
+ Full details (OAuth setup, sessions, read-only user SQL) are in **[DOCUMENTATIONS.md → Remote Access](DOCUMENTATIONS.md#remote-access-streamable-http-transport-v1450-2026-10-26-144606)**.
330
+
331
+ ---
332
+
333
+ ## Permission System
334
+
335
+ Control database access with a **dual-layer filtering system** that provides both broad and fine-grained control:
336
+
337
+ - **Layer 1 (Permissions)**: Broad operation-level control using legacy categories
338
+ - **Layer 2 (Categories)**: Optional fine-grained tool-level filtering using documentation categories
339
+
340
+ **Filtering Logic**: `Tool enabled = (Has Permission) AND (Has Category OR No categories specified)`
341
+
342
+ ### Permissions
343
+
344
+ | Permission | Operations | Use Case |
345
+ |------------|------------|----------|
346
+ | `list` | List databases, tables, schemas | Database exploration |
347
+ | `read` | SELECT queries, read data | Analytics, reporting |
348
+ | `create` | INSERT new records | Data entry |
349
+ | `update` | UPDATE existing records | Data maintenance |
350
+ | `delete` | DELETE records | Data cleanup |
351
+ | `execute` | Execute custom INSERT/UPDATE SQL (DELETE requires `delete` permission too) | Complex write operations |
352
+ | `ddl` | CREATE/ALTER/DROP tables | Schema management |
353
+ | `procedure` | Stored procedures (CREATE/DROP/EXECUTE) | Procedure management |
354
+ | `transaction` | BEGIN, COMMIT, ROLLBACK | ACID operations |
355
+ | `utility` | Connection testing, diagnostics | Troubleshooting |
356
+
357
+ **Changes in v1.44.0 (review before upgrading):**
358
+ - **Read-only by default**: with no permissions and no categories, the server now enables only `list,read,utility` (previously every tool). To keep full access, pass `list,read,create,update,delete,execute,ddl,utility,transaction,procedure`.
359
+ - **No implicit `mysql` schema**: without a database in the connection string or `DB_NAME`, database-scoped tools report "No database specified" instead of using the `mysql` system schema.
360
+ - **Query cache off by default**: opt in with `CACHE_ENABLED=true`. Any write and every transaction commit now clears the cache.
361
+ - **SQL validation**: `#`, `;`, and `--` inside string values (e.g. `'#fff'`) are no longer rejected. `WITH` (CTE) queries are supported and, like derived tables, need `execute` in read queries.
362
+
363
+ **Security changes in v1.43.4:**
364
+ - `EXPLAIN ANALYZE` runs the statement it wraps (MySQL 8.0.18+), so it now requires that statement's permission: `delete` for DELETE, `update` or `execute` for UPDATE, `read` for SELECT. Plan-only `EXPLAIN` still needs just `list` or `read`.
365
+
366
+ **Security changes in v1.43.3:**
367
+ - CSV exports require both `utility` and `read`; enable the `utilities` category when filtering categories.
368
+ - SQL within a transaction requires the corresponding operation permission. `transaction` alone does not permit reads or writes.
369
+ - `execute_write_query` accepts only INSERT/UPDATE/DELETE. DDL requires enabled DDL tools.
370
+ - Disabled tools cannot be called directly or through the Cursor bridge. The bridge requires `utility` and an enabled destination tool.
371
+ - `execute` does not bypass mandatory SQL safety restrictions, including file access and account/privilege changes.
372
+
373
+ Report suspected security issues privately via [Private Vulnerability Reporting](https://github.com/berthojoris/mysql-mcp/security/advisories/new); see [SECURITY.md](SECURITY.md) for the policy.
374
+
375
+ Filtering rules and per-permission details are documented in **[DOCUMENTATIONS.md → Permission System](DOCUMENTATIONS.md#permission-system)**.
376
+
377
+ ---
378
+
379
+ ### Documentation Categories (Recommended)
380
+
381
+ Use documentation categories to fine-tune which tools are exposed (Layer 2):
382
+
383
+ | Category List | Use Case | List Tools |
384
+ |---------------|----------|-----------|
385
+ | `database_discovery` | Explore databases, tables, and schema structure | `get_all_tables_relationships, list_databases, list_tables, read_table_schema` |
386
+ | `crud_operations` | Create, read, update, delete operations on data | `create_record, delete_record, read_records, update_record` |
387
+ | `bulk_operations` | High-performance batch processing operations | `bulk_delete, bulk_insert, bulk_update` |
388
+ | `seed_operations` | FK-aware relational dummy data seeding | `execute_seed_plan, generate_seed_preview, infer_seed_rules, plan_seed_data, seed_from_template, validate_seed_integrity` |
389
+ | `custom_queries` | Execute custom SQL queries and advanced operations | `execute_write_query, run_select_query` |
390
+ | `schema_management` | Manage database schema, tables, and structure | `alter_table, create_table, drop_table, execute_ddl` |
391
+ | `utilities` | Database utilities, diagnostics, and helper functions | `cursor_execute_request, describe_connection, export_query_to_csv, export_table_to_csv, list_all_tools, read_changelog, test_connection` |
392
+ | `transaction_management` | Handle ACID transactions and rollback operations | `begin_transaction, commit_transaction, execute_in_transaction, get_transaction_status, rollback_transaction` |
393
+ | `stored_procedures` | Create, execute, and manage stored procedures | `create_stored_procedure, drop_stored_procedure, execute_stored_procedure, get_stored_procedure_info, list_stored_procedures, show_create_procedure` |
394
+ | `views_management` | Create and manage database views | `alter_view, create_view, drop_view, get_view_info, list_views, show_create_view` |
395
+ | `triggers_management` | Create and manage database triggers | `create_trigger, drop_trigger, get_trigger_info, list_triggers, show_create_trigger` |
396
+ | `index_management` | Optimize performance with index and fulltext management | `analyze_index, create_fulltext_index, create_index, drop_fulltext_index, drop_index, fulltext_search, get_fulltext_info, get_fulltext_stats, get_index_info, list_indexes, optimize_fulltext` |
397
+ | `constraint_management` | Manage data integrity constraints | `add_check_constraint, add_foreign_key, add_unique_constraint, drop_constraint, drop_foreign_key, list_constraints, list_foreign_keys` |
398
+ | `table_maintenance` | Table optimization, repair, and maintenance | `analyze_table, check_table, flush_table, get_table_size, get_table_status, optimize_table, repair_table, truncate_table` |
399
+ | `query_optimization` | Analyze and optimize SQL queries | `analyze_query, get_optimization_hints, repair_query` |
400
+ | `analysis` | Data analysis, schema discovery, and reporting tools | `find_tables_by_keyword, get_column_statistics, get_database_summary, get_schema_erd, get_schema_rag_context, search_data_across_tables, search_schema` |
401
+
402
+ <details>
403
+ <summary>Copy/paste list (comma-separated, no spaces)</summary>
404
+
405
+ ```text
406
+ database_discovery,crud_operations,bulk_operations,seed_operations,custom_queries,schema_management,utilities,transaction_management,stored_procedures,views_management,triggers_management,index_management,constraint_management,table_maintenance,query_optimization,analysis
407
+ ```
408
+
409
+ </details>
410
+
411
+ Tool descriptions per category are in **[DOCUMENTATIONS.md → Tool Categories](DOCUMENTATIONS.md#tool-categories)**.
412
+
413
+ ---
414
+
415
+ ## Available Tools
416
+
417
+ The server exposes **88 tools** organized into categories (CRUD, seed, schema, discovery, and utilities).
418
+
419
+ - Complete list of tools: **[DOCUMENTATIONS.md → Tool Categories](DOCUMENTATIONS.md#tool-categories)**
420
+ - Every tool carries MCP annotations (`readOnlyHint`, `destructiveHint`, `idempotentHint`); see **[DOCUMENTATIONS.md → Tool annotations](DOCUMENTATIONS.md#tool-annotations)**
421
+
422
+ ---
423
+
424
+ ## Detailed Documentation
425
+
426
+ For comprehensive documentation, see **[DOCUMENTATIONS.md](DOCUMENTATIONS.md)**:
427
+
428
+ - **Remote Access** - Streamable HTTP transport, bearer/OAuth authentication, sessions, protection settings, audit log
429
+
430
+ - **DDL Operations** - Create, alter, and drop tables
431
+ - **Data Export Tools** - Export data to CSV format
432
+ - **Relational Data Seeder** - Plan, preview, execute, validate, infer rules, and template FK-aware dummy data
433
+ - **Full-Text Search** - Create and search FULLTEXT indexes with multiple search modes
434
+ - **Transaction Management** - ACID transactions
435
+ - **Stored Procedures** - Create and execute with IN/OUT/INOUT parameters
436
+ - **Views & Triggers** - Manage database views and triggers
437
+ - **Index & Constraint Management** - Optimize performance and enforce data integrity
438
+ - **Table Maintenance** - Analyze, optimize, check, and repair tables
439
+ - **Query Logging** - See all SQL queries executed automatically
440
+ - **Security Features** - Built-in security and best practices
441
+ - **Bulk Operations** - High-performance batch processing
442
+ - **Troubleshooting** - Common issues and solutions
443
+
444
+ ---
445
+
446
+ ## MySQL MCP vs Manual Database Access
447
+
448
+ This MySQL MCP is a **powerful intermediary layer** between AI assistants and MySQL databases.
449
+
450
+ For full feature coverage and usage examples, see **[DOCUMENTATIONS.md](DOCUMENTATIONS.md)**.
451
+
452
+ ---
453
+
454
+ ## License
455
+
456
+ MIT License - see [LICENSE](LICENSE) file for details.
457
+
458
+ ---
459
+
460
+ <div align="center">
461
+
462
+ **Made with care for the AI development community**
463
+
464
+ *Enabling AI agents to interact with MySQL databases safely and efficiently*
465
+
466
+ [Report Bug](https://github.com/berthojoris/mysql-mcp/issues) · [Request Feature](https://github.com/berthojoris/mysql-mcp/issues) · [Documentation](DOCUMENTATIONS.md)
467
+
468
+ </div>