@praise25/mcp-server-mysql 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,730 @@
1
+
2
+ # MCP Server for MySQL based on NodeJS
3
+
4
+
5
+ A Model Context Protocol server that provides access to MySQL databases. This server enables LLMs to inspect database schemas and execute SQL queries.
6
+
7
+ ## Table of Contents
8
+ - [Requirements](#requirements)
9
+ - [Installation](#installation)
10
+ - [Smithery](#using-smithery)
11
+ - [Clone to Local Repository](#running-from-local-repository)
12
+ - [Remote mode](#run-in-remote-mode)
13
+ - [Components](#components)
14
+ - [Configuration](#configuration)
15
+ - [Environment Variables](#environment-variables)
16
+ - [Multi-DB Mode](#multi-db-mode)
17
+ - [Schema-Specific Permissions](#schema-specific-permissions)
18
+ - [Testing](#testing)
19
+ - [Troubleshooting](#troubleshooting)
20
+ - [Contributing](#contributing)
21
+ - [License](#license)
22
+
23
+ ## Requirements
24
+
25
+ - Node.js v20 or higher
26
+ - MySQL 5.7 or higher (MySQL 8.0+ recommended)
27
+ - MySQL user with appropriate permissions for the operations you need
28
+ - For write operations: MySQL user with INSERT, UPDATE, and/or DELETE privileges
29
+
30
+ ## Installation
31
+
32
+ There are several ways to install and configure the MCP server but the most common would be checking this website https://smithery.ai/server/@benborla29/mcp-server-mysql
33
+
34
+ ### Cursor
35
+
36
+ For Cursor IDE, you can install this MCP server with the following command in your project:
37
+
38
+ 1. Visit https://smithery.ai/server/@benborla29/mcp-server-mysql
39
+ 2. Follow the instruction for Cursor
40
+
41
+
42
+ MCP Get provides a centralized registry of MCP servers and simplifies the installation process.
43
+
44
+ ### Claude Code
45
+
46
+ #### Option 1: Import from Claude Desktop (Recommended if already configured)
47
+
48
+ If you already have this MCP server configured in Claude Desktop, you can import it automatically:
49
+
50
+ ```bash
51
+ claude mcp add-from-claude-desktop
52
+ ```
53
+
54
+ This will show an interactive dialog where you can select your `mcp_server_mysql` server to import with all existing configuration.
55
+
56
+ #### Option 2: Manual Configuration
57
+
58
+ **Using NPM/PNPM Global Installation:**
59
+
60
+ First, install the package globally:
61
+ ```bash
62
+ # Using npm
63
+ npm install -g @benborla29/mcp-server-mysql
64
+
65
+ # Using pnpm
66
+ pnpm add -g @benborla29/mcp-server-mysql
67
+ ```
68
+
69
+ Then add the server to Claude Code:
70
+ ```bash
71
+ claude mcp add mcp_server_mysql \
72
+ -e MYSQL_HOST="127.0.0.1" \
73
+ -e MYSQL_PORT="3306" \
74
+ -e MYSQL_USER="root" \
75
+ -e MYSQL_PASS="your_password" \
76
+ -e MYSQL_DB="your_database" \
77
+ -e ALLOW_INSERT_OPERATION="false" \
78
+ -e ALLOW_UPDATE_OPERATION="false" \
79
+ -e ALLOW_DELETE_OPERATION="false" \
80
+ -- npx @benborla29/mcp-server-mysql
81
+ ```
82
+
83
+ **Using Local Repository (for development):**
84
+
85
+ If you're running from a cloned repository:
86
+ ```bash
87
+ claude mcp add mcp_server_mysql \
88
+ -e MYSQL_HOST="127.0.0.1" \
89
+ -e MYSQL_PORT="3306" \
90
+ -e MYSQL_USER="root" \
91
+ -e MYSQL_PASS="your_password" \
92
+ -e MYSQL_DB="your_database" \
93
+ -e ALLOW_INSERT_OPERATION="false" \
94
+ -e ALLOW_UPDATE_OPERATION="false" \
95
+ -e ALLOW_DELETE_OPERATION="false" \
96
+ -e PATH="/path/to/node/bin:/usr/bin:/bin" \
97
+ -e NODE_PATH="/path/to/node/lib/node_modules" \
98
+ -- /path/to/node /full/path/to/mcp-server-mysql/dist/index.js
99
+ ```
100
+
101
+ Replace:
102
+ - `/path/to/node` with your Node.js binary path (find with `which node`)
103
+ - `/full/path/to/mcp-server-mysql` with the full path to your cloned repository
104
+ - Update MySQL credentials to match your environment
105
+
106
+ **Using Unix Socket Connection:**
107
+
108
+ For local MySQL instances using Unix sockets:
109
+ ```bash
110
+ claude mcp add mcp_server_mysql \
111
+ -e MYSQL_SOCKET_PATH="/tmp/mysql.sock" \
112
+ -e MYSQL_USER="root" \
113
+ -e MYSQL_PASS="your_password" \
114
+ -e MYSQL_DB="your_database" \
115
+ -e ALLOW_INSERT_OPERATION="false" \
116
+ -e ALLOW_UPDATE_OPERATION="false" \
117
+ -e ALLOW_DELETE_OPERATION="false" \
118
+ -- npx @benborla29/mcp-server-mysql
119
+ ```
120
+
121
+ #### Choosing the Right Scope
122
+
123
+ Consider which scope to use based on your needs:
124
+
125
+ ```bash
126
+ # Local scope (default) - only available in current project
127
+ claude mcp add mcp_server_mysql [options...]
128
+
129
+ # User scope - available across all your projects
130
+ claude mcp add mcp_server_mysql -s user [options...]
131
+
132
+ # Project scope - shared with team members via .mcp.json
133
+ claude mcp add mcp_server_mysql -s project [options...]
134
+ ```
135
+
136
+ For database servers with credentials, **local** or **user** scope is recommended to keep credentials private.
137
+
138
+ #### Verification
139
+
140
+ After adding the server, verify it's configured correctly:
141
+
142
+ ```bash
143
+ # List all configured servers
144
+ claude mcp list
145
+
146
+ # Get details for your MySQL server
147
+ claude mcp get mcp_server_mysql
148
+
149
+ # Check server status within Claude Code
150
+ /mcp
151
+ ```
152
+
153
+ #### Multi-Database Configuration
154
+
155
+ For multi-database mode, omit the `MYSQL_DB` environment variable:
156
+
157
+ ```bash
158
+ claude mcp add mcp_server_mysql_multi \
159
+ -e MYSQL_HOST="127.0.0.1" \
160
+ -e MYSQL_PORT="3306" \
161
+ -e MYSQL_USER="root" \
162
+ -e MYSQL_PASS="your_password" \
163
+ -e MULTI_DB_WRITE_MODE="false" \
164
+ -- npx @benborla29/mcp-server-mysql
165
+ ```
166
+
167
+ #### Advanced Configuration
168
+
169
+ For advanced features, add additional environment variables:
170
+
171
+ ```bash
172
+ claude mcp add mcp_server_mysql \
173
+ -e MYSQL_HOST="127.0.0.1" \
174
+ -e MYSQL_PORT="3306" \
175
+ -e MYSQL_USER="root" \
176
+ -e MYSQL_PASS="your_password" \
177
+ -e MYSQL_DB="your_database" \
178
+ -e MYSQL_POOL_SIZE="10" \
179
+ -e MYSQL_QUERY_TIMEOUT="30000" \
180
+ -e MYSQL_CACHE_TTL="60000" \
181
+ -e MYSQL_RATE_LIMIT="100" \
182
+ -e MYSQL_SSL="true" \
183
+ -e ALLOW_INSERT_OPERATION="false" \
184
+ -e ALLOW_UPDATE_OPERATION="false" \
185
+ -e ALLOW_DELETE_OPERATION="false" \
186
+ -e MYSQL_ENABLE_LOGGING="true" \
187
+ -- npx @benborla29/mcp-server-mysql
188
+ ```
189
+
190
+ #### Troubleshooting Claude Code Setup
191
+
192
+ 1. **Server Connection Issues**: Use `/mcp` command in Claude Code to check server status and authenticate if needed.
193
+
194
+ 2. **Path Issues**: If using a local repository, ensure Node.js paths are correctly set:
195
+ ```bash
196
+ # Find your Node.js path
197
+ which node
198
+
199
+ # For PATH environment variable
200
+ echo "$(which node)/../"
201
+
202
+ # For NODE_PATH environment variable
203
+ echo "$(which node)/../../lib/node_modules"
204
+ ```
205
+
206
+ 3. **Permission Errors**: Ensure your MySQL user has appropriate permissions for the operations you've enabled.
207
+
208
+ 4. **Server Not Starting**: Check Claude Code logs or run the server directly to debug:
209
+ ```bash
210
+ # Test the server directly
211
+ npx @benborla29/mcp-server-mysql
212
+ ```
213
+
214
+ ### Using NPM/PNPM
215
+
216
+ For manual installation:
217
+
218
+ ```bash
219
+ # Using npm
220
+ npm install -g @benborla29/mcp-server-mysql
221
+
222
+ # Using pnpm
223
+ pnpm add -g @benborla29/mcp-server-mysql
224
+ ```
225
+
226
+ After manual installation, you'll need to configure your LLM application to use the MCP server (see Configuration section below).
227
+
228
+ ### Running from Local Repository
229
+
230
+ If you want to clone and run this MCP server directly from the source code, follow these steps:
231
+
232
+ 1. **Clone the repository**
233
+ ```bash
234
+ git clone https://github.com/benborla/mcp-server-mysql.git
235
+ cd mcp-server-mysql
236
+ ```
237
+
238
+ 2. **Install dependencies**
239
+ ```bash
240
+ npm install
241
+ # or
242
+ pnpm install
243
+ ```
244
+
245
+ 3. **Build the project**
246
+ ```bash
247
+ npm run build
248
+ # or
249
+ pnpm run build
250
+ ```
251
+
252
+ 4. **Configure Claude Desktop**
253
+
254
+ Add the following to your Claude Desktop configuration file (`claude_desktop_config.json`):
255
+
256
+ ```json
257
+ {
258
+ "mcpServers": {
259
+ "mcp_server_mysql": {
260
+ "command": "/path/to/node",
261
+ "args": [
262
+ "/full/path/to/mcp-server-mysql/dist/index.js"
263
+ ],
264
+ "env": {
265
+ "MYSQL_HOST": "127.0.0.1",
266
+ "MYSQL_PORT": "3306",
267
+ "MYSQL_USER": "root",
268
+ "MYSQL_PASS": "your_password",
269
+ "MYSQL_DB": "your_database",
270
+ "ALLOW_INSERT_OPERATION": "false",
271
+ "ALLOW_UPDATE_OPERATION": "false",
272
+ "ALLOW_DELETE_OPERATION": "false",
273
+ "PATH": "/Users/atlasborla/Library/Application Support/Herd/config/nvm/versions/node/v22.9.0/bin:/usr/bin:/bin", // <--- Important to add the following, run in your terminal `echo "$(which node)/../"` to get the path
274
+ "NODE_PATH": "/Users/atlasborla/Library/Application Support/Herd/config/nvm/versions/node/v22.9.0/lib/node_modules" // <--- Important to add the following, run in your terminal `echo "$(which node)/../../lib/node_modules"`
275
+ }
276
+ }
277
+ }
278
+ }
279
+ ```
280
+
281
+ Replace:
282
+ - `/path/to/node` with the full path to your Node.js binary (find it with `which node`)
283
+ - `/full/path/to/mcp-server-mysql` with the full path to where you cloned the repository
284
+ - Set the MySQL credentials to match your environment
285
+
286
+ 5. **Test the server**
287
+ ```bash
288
+ # Run the server directly to test
289
+ node dist/index.js
290
+ ```
291
+
292
+ If it connects to MySQL successfully, you're ready to use it with Claude Desktop.
293
+
294
+ ### Run in remote mode
295
+
296
+ To run in remote mode, you'll need to provide [environment variables](https://github.com/benborla/mcp-server-mysql?tab=readme-ov-file#environment-variables) to the npx script.
297
+ 1. Create env file in preferred directory
298
+ ```bash
299
+ # create .env file
300
+ touch .env
301
+ ```
302
+ 2. Copy-paste [example file](https://github.com/benborla/mcp-server-mysql/blob/main/.env) from this repository
303
+ 3. Set the MySQL credentials to match your environment
304
+ 4. Set `IS_REMOTE_MCP=true`
305
+ 5. Set `REMOTE_SECRET_KEY` to a secure string.
306
+ 6. Provide custom `PORT` if needed. Default is 3000.
307
+ 7. Load variables in current session:
308
+ ```bash
309
+ source .env
310
+ ```
311
+ 8. Run the server
312
+ ```bash
313
+ npx @benborla29/mcp-server-mysql
314
+ ```
315
+ 9. Configure your agent to connect to the MCP with the next configuration:
316
+ ```json
317
+ {
318
+ "mcpServers": {
319
+ "mysql": {
320
+ "url": "http://your-host:3000/mcp",
321
+ "type": "streamableHttp",
322
+ "headers": {
323
+ "Authorization": "Bearer <REMOTE_SECRET_KEY>"
324
+ }
325
+ }
326
+ }
327
+ }
328
+ ```
329
+
330
+
331
+ ## Components
332
+
333
+ ### Tools
334
+
335
+ - **mysql_query**
336
+ - Execute SQL queries against the connected database
337
+ - Input: `sql` (string): The SQL query to execute
338
+ - By default, limited to READ ONLY operations
339
+ - Optional write operations (when enabled via configuration):
340
+ - INSERT: Add new data to tables (requires `ALLOW_INSERT_OPERATION=true`)
341
+ - UPDATE: Modify existing data (requires `ALLOW_UPDATE_OPERATION=true`)
342
+ - DELETE: Remove data (requires `ALLOW_DELETE_OPERATION=true`)
343
+ - All operations are executed within a transaction with proper commit/rollback handling
344
+ - Supports prepared statements for secure parameter handling
345
+ - Configurable query timeouts and result pagination
346
+ - Built-in query execution statistics
347
+
348
+ ### Resources
349
+
350
+ The server provides comprehensive database information:
351
+
352
+ - **Table Schemas**
353
+ - JSON schema information for each table
354
+ - Column names and data types
355
+ - Index information and constraints
356
+ - Foreign key relationships
357
+ - Table statistics and metrics
358
+ - Automatically discovered from database metadata
359
+
360
+ ### Security Features
361
+
362
+ - SQL injection prevention through prepared statements
363
+ - Query whitelisting/blacklisting capabilities
364
+ - Rate limiting for query execution
365
+ - Query complexity analysis
366
+ - Configurable connection encryption
367
+ - Read-only transaction enforcement
368
+
369
+ ### Performance Optimizations
370
+
371
+ - Optimized connection pooling
372
+ - Query result caching
373
+ - Large result set streaming
374
+ - Query execution plan analysis
375
+ - Configurable query timeouts
376
+
377
+ ### Monitoring and Debugging
378
+
379
+ - Comprehensive query logging
380
+ - Performance metrics collection
381
+ - Error tracking and reporting
382
+ - Health check endpoints
383
+ - Query execution statistics
384
+
385
+ ## Configuration
386
+
387
+ ### Automatic Configuration with Smithery
388
+ If you installed using Smithery, your configuration is already set up. You can view or modify it with:
389
+
390
+ ```bash
391
+ smithery configure @benborla29/mcp-server-mysql
392
+ ```
393
+
394
+ When reconfiguring, you can update any of the MySQL connection details as well as the write operation settings:
395
+
396
+ - **Basic connection settings**:
397
+ - MySQL Host, Port, User, Password, Database
398
+ - SSL/TLS configuration (if your database requires secure connections)
399
+
400
+ - **Write operation permissions**:
401
+ - Allow INSERT Operations: Set to true if you want to allow adding new data
402
+ - Allow UPDATE Operations: Set to true if you want to allow updating existing data
403
+ - Allow DELETE Operations: Set to true if you want to allow deleting data
404
+
405
+ For security reasons, all write operations are disabled by default. Only enable these settings if you specifically need Claude to modify your database data.
406
+
407
+ ### Advanced Configuration Options
408
+ For more control over the MCP server's behavior, you can use these advanced configuration options:
409
+
410
+ ```json
411
+ {
412
+ "mcpServers": {
413
+ "mcp_server_mysql": {
414
+ "command": "/path/to/npx/binary/npx",
415
+ "args": [
416
+ "-y",
417
+ "@benborla29/mcp-server-mysql"
418
+ ],
419
+ "env": {
420
+ // Basic connection settings
421
+ "MYSQL_HOST": "127.0.0.1",
422
+ "MYSQL_PORT": "3306",
423
+ "MYSQL_USER": "root",
424
+ "MYSQL_PASS": "",
425
+ "MYSQL_DB": "db_name",
426
+ "PATH": "/path/to/node/bin:/usr/bin:/bin",
427
+
428
+ // Performance settings
429
+ "MYSQL_POOL_SIZE": "10",
430
+ "MYSQL_QUERY_TIMEOUT": "30000",
431
+ "MYSQL_CACHE_TTL": "60000",
432
+
433
+ // Security settings
434
+ "MYSQL_RATE_LIMIT": "100",
435
+ "MYSQL_MAX_QUERY_COMPLEXITY": "1000",
436
+ "MYSQL_SSL": "true",
437
+
438
+ // Monitoring settings
439
+ "ENABLE_LOGGING": "true",
440
+ "MYSQL_LOG_LEVEL": "info",
441
+ "MYSQL_METRICS_ENABLED": "true",
442
+
443
+ // Write operation flags
444
+ "ALLOW_INSERT_OPERATION": "false",
445
+ "ALLOW_UPDATE_OPERATION": "false",
446
+ "ALLOW_DELETE_OPERATION": "false"
447
+ }
448
+ }
449
+ }
450
+ }
451
+ ```
452
+
453
+ ## Environment Variables
454
+
455
+ ### Basic Connection
456
+ - `MYSQL_SOCKET_PATH`: Unix socket path for local connections (e.g., "/tmp/mysql.sock")
457
+ - `MYSQL_HOST`: MySQL server host (default: "127.0.0.1") - ignored if MYSQL_SOCKET_PATH is set
458
+ - `MYSQL_PORT`: MySQL server port (default: "3306") - ignored if MYSQL_SOCKET_PATH is set
459
+ - `MYSQL_USER`: MySQL username (default: "root")
460
+ - `MYSQL_PASS`: MySQL password
461
+ - `MYSQL_DB`: Target database name (leave empty for multi-DB mode)
462
+
463
+ ### Performance Configuration
464
+ - `MYSQL_POOL_SIZE`: Connection pool size (default: "10")
465
+ - `MYSQL_QUERY_TIMEOUT`: Query timeout in milliseconds (default: "30000")
466
+ - `MYSQL_CACHE_TTL`: Cache time-to-live in milliseconds (default: "60000")
467
+
468
+ ### Security Configuration
469
+ - `MYSQL_RATE_LIMIT`: Maximum queries per minute (default: "100")
470
+ - `MYSQL_MAX_QUERY_COMPLEXITY`: Maximum query complexity score (default: "1000")
471
+ - `MYSQL_SSL`: Enable SSL/TLS encryption (default: "false")
472
+ - `ALLOW_INSERT_OPERATION`: Enable INSERT operations (default: "false")
473
+ - `ALLOW_UPDATE_OPERATION`: Enable UPDATE operations (default: "false")
474
+ - `ALLOW_DELETE_OPERATION`: Enable DELETE operations (default: "false")
475
+ - `ALLOW_DDL_OPERATION`: Enable DDL operations (default: "false")
476
+ - `SCHEMA_INSERT_PERMISSIONS`: Schema-specific INSERT permissions
477
+ - `SCHEMA_UPDATE_PERMISSIONS`: Schema-specific UPDATE permissions
478
+ - `SCHEMA_DELETE_PERMISSIONS`: Schema-specific DELETE permissions
479
+ - `SCHEMA_DDL_PERMISSIONS`: Schema-specific DDL permissions
480
+ - `MULTI_DB_WRITE_MODE`: Enable write operations in multi-DB mode (default: "false")
481
+
482
+ ### Monitoring Configuration
483
+ - `MYSQL_ENABLE_LOGGING`: Enable query logging (default: "false")
484
+ - `MYSQL_LOG_LEVEL`: Logging level (default: "info")
485
+ - `MYSQL_METRICS_ENABLED`: Enable performance metrics (default: "false")
486
+
487
+ ### Remote MCP Configuration
488
+ - `IS_REMOTE_MCP`: Enable remote MCP mode (default: "false")
489
+ - `REMOTE_SECRET_KEY`: Secret key for remote MCP authentication (default: ""). If not provided, remote MCP mode will be disabled.
490
+ - `PORT`: Port number for the remote MCP server (default: 3000)
491
+
492
+ ## Multi-DB Mode
493
+
494
+ MCP-Server-MySQL supports connecting to multiple databases when no specific database is set. This allows the LLM to query any database the MySQL user has access to. For full details, see [README-MULTI-DB.md](./README-MULTI-DB.md).
495
+
496
+ ### Enabling Multi-DB Mode
497
+
498
+ To enable multi-DB mode, simply leave the `MYSQL_DB` environment variable empty. In multi-DB mode, queries require schema qualification:
499
+
500
+ ```sql
501
+ -- Use fully qualified table names
502
+ SELECT * FROM database_name.table_name;
503
+
504
+ -- Or use USE statements to switch between databases
505
+ USE database_name;
506
+ SELECT * FROM table_name;
507
+ ```
508
+
509
+ ## Schema-Specific Permissions
510
+
511
+ For fine-grained control over database operations, MCP-Server-MySQL now supports schema-specific permissions. This allows different databases to have different levels of access (read-only, read-write, etc.).
512
+
513
+ ### Configuration Example
514
+
515
+ ```
516
+ SCHEMA_INSERT_PERMISSIONS=development:true,test:true,production:false
517
+ SCHEMA_UPDATE_PERMISSIONS=development:true,test:true,production:false
518
+ SCHEMA_DELETE_PERMISSIONS=development:false,test:true,production:false
519
+ SCHEMA_DDL_PERMISSIONS=development:false,test:true,production:false
520
+ ```
521
+
522
+ For complete details and security recommendations, see [README-MULTI-DB.md](./README-MULTI-DB.md).
523
+
524
+ ## Testing
525
+
526
+ ### Database Setup
527
+
528
+ Before running tests, you need to set up the test database and seed it with test data:
529
+
530
+ 1. **Create Test Database and User**
531
+ ```sql
532
+ -- Connect as root and create test database
533
+ CREATE DATABASE IF NOT EXISTS mcp_test;
534
+
535
+ -- Create test user with appropriate permissions
536
+ CREATE USER IF NOT EXISTS 'mcp_test'@'localhost' IDENTIFIED BY 'mcp_test_password';
537
+ GRANT ALL PRIVILEGES ON mcp_test.* TO 'mcp_test'@'localhost';
538
+ FLUSH PRIVILEGES;
539
+ ```
540
+
541
+ 2. **Run Database Setup Script**
542
+ ```bash
543
+ # Run the database setup script
544
+ pnpm run setup:test:db
545
+ ```
546
+
547
+ This will create the necessary tables and seed data. The script is located in `scripts/setup-test-db.ts`
548
+
549
+ 3. **Configure Test Environment**
550
+ Create a `.env.test` file in the project root (if not existing):
551
+ ```env
552
+ MYSQL_HOST=127.0.0.1
553
+ MYSQL_PORT=3306
554
+ MYSQL_USER=mcp_test
555
+ MYSQL_PASS=mcp_test_password
556
+ MYSQL_DB=mcp_test
557
+ ```
558
+
559
+ 4. **Update package.json Scripts**
560
+ Add these scripts to your package.json:
561
+ ```json
562
+ {
563
+ "scripts": {
564
+ "setup:test:db": "ts-node scripts/setup-test-db.ts",
565
+ "pretest": "pnpm run setup:test:db",
566
+ "test": "vitest run",
567
+ "test:watch": "vitest",
568
+ "test:coverage": "vitest run --coverage"
569
+ }
570
+ }
571
+ ```
572
+
573
+ ### Running Tests
574
+
575
+ The project includes a comprehensive test suite to ensure functionality and reliability:
576
+
577
+ ```bash
578
+ # First-time setup
579
+ pnpm run setup:test:db
580
+
581
+ # Run all tests
582
+ pnpm test
583
+ ```
584
+
585
+
586
+
587
+ ## Running evals
588
+
589
+ The evals package loads an mcp client that then runs the index.ts file, so there is no need to rebuild between tests. You can load environment variables by prefixing the npx command. Full documentation can be found [here](https://www.mcpevals.io/docs).
590
+
591
+ ```bash
592
+ OPENAI_API_KEY=your-key npx mcp-eval evals.ts index.ts
593
+ ```
594
+ ## Troubleshooting
595
+
596
+ ### Common Issues
597
+
598
+ 1. **Connection Issues**
599
+ - Verify MySQL server is running and accessible
600
+ - Check credentials and permissions
601
+ - Ensure SSL/TLS configuration is correct if enabled
602
+ - Try connecting with a MySQL client to confirm access
603
+
604
+ 2. **Performance Issues**
605
+ - Adjust connection pool size
606
+ - Configure query timeout values
607
+ - Enable query caching if needed
608
+ - Check query complexity settings
609
+ - Monitor server resource usage
610
+
611
+ 3. **Security Restrictions**
612
+ - Review rate limiting configuration
613
+ - Check query whitelist/blacklist settings
614
+ - Verify SSL/TLS settings
615
+ - Ensure the user has appropriate MySQL permissions
616
+
617
+ 4. **Path Resolution**
618
+ If you encounter an error "Could not connect to MCP server mcp-server-mysql", explicitly set the path of all required binaries:
619
+ ```json
620
+ {
621
+ "env": {
622
+ "PATH": "/path/to/node/bin:/usr/bin:/bin"
623
+ }
624
+ }
625
+ ```
626
+
627
+ *Where can I find my `node` bin path*
628
+ Run the following command to get it:
629
+
630
+ For **PATH**
631
+ ```bash
632
+ echo "$(which node)/../"
633
+ ```
634
+
635
+ For **NODE_PATH**
636
+ ```bash
637
+ echo "$(which node)/../../lib/node_modules"
638
+ ```
639
+
640
+ 5. **Claude Desktop Specific Issues**
641
+ - If you see "Server disconnected" logs in Claude Desktop, check the logs at `~/Library/Logs/Claude/mcp-server-mcp_server_mysql.log`
642
+ - Ensure you're using the absolute path to both the Node binary and the server script
643
+ - Check if your `.env` file is being properly loaded; use explicit environment variables in the configuration
644
+ - Try running the server directly from the command line to see if there are connection issues
645
+ - If you need write operations (INSERT, UPDATE, DELETE), set the appropriate flags to "true" in your configuration:
646
+ ```json
647
+ "env": {
648
+ "ALLOW_INSERT_OPERATION": "true", // Enable INSERT operations
649
+ "ALLOW_UPDATE_OPERATION": "true", // Enable UPDATE operations
650
+ "ALLOW_DELETE_OPERATION": "true" // Enable DELETE operations
651
+ }
652
+ ```
653
+ - Ensure your MySQL user has the appropriate permissions for the operations you're enabling
654
+ - For direct execution configuration, use:
655
+ ```json
656
+ {
657
+ "mcpServers": {
658
+ "mcp_server_mysql": {
659
+ "command": "/full/path/to/node",
660
+ "args": [
661
+ "/full/path/to/mcp-server-mysql/dist/index.js"
662
+ ],
663
+ "env": {
664
+ "MYSQL_HOST": "127.0.0.1",
665
+ "MYSQL_PORT": "3306",
666
+ "MYSQL_USER": "root",
667
+ "MYSQL_PASS": "your_password",
668
+ "MYSQL_DB": "your_database"
669
+ }
670
+ }
671
+ }
672
+ }
673
+ ```
674
+
675
+ 6. **Authentication Issues**
676
+ - For MySQL 8.0+, ensure the server supports the `caching_sha2_password` authentication plugin
677
+ - Check if your MySQL user is configured with the correct authentication method
678
+ - Try creating a user with legacy authentication if needed:
679
+ ```sql
680
+ CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
681
+ ```
682
+ @lizhuangs
683
+
684
+ 7. I am encountering `Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'dotenv' imported from` error
685
+ try this workaround:
686
+ ```bash
687
+ npx -y -p @benborla29/mcp-server-mysql -p dotenv mcp-server-mysql
688
+ ```
689
+ Thanks to @lizhuangs
690
+
691
+ ## Contributing
692
+
693
+ Contributions are welcome! Please feel free to submit a Pull Request to
694
+ https://github.com/benborla/mcp-server-mysql
695
+
696
+ ## Many Thanks to the following Contributors:
697
+ <a href = "https://github.com/benborla/mcp-server-mysql/graphs/contributors">
698
+ <img src = "https://contrib.rocks/image?repo=benborla/mcp-server-mysql"/>
699
+ </a>
700
+
701
+ ### Development Setup
702
+
703
+ 1. Clone the repository
704
+ 2. Install dependencies: `pnpm install`
705
+ 3. Build the project: `pnpm run build`
706
+ 4. Run tests: `pnpm test`
707
+
708
+ ### Project Roadmap
709
+
710
+ We're actively working on enhancing this MCP server. Check our [CHANGELOG.md](./CHANGELOG.md) for details on planned features, including:
711
+
712
+ - Enhanced query capabilities with prepared statements
713
+ - Advanced security features
714
+ - Performance optimizations
715
+ - Comprehensive monitoring
716
+ - Expanded schema information
717
+
718
+ If you'd like to contribute to any of these areas, please check the issues on GitHub or open a new one to discuss your ideas.
719
+
720
+ ### Submitting Changes
721
+
722
+ 1. Fork the repository
723
+ 2. Create a feature branch: `git checkout -b feature/your-feature-name`
724
+ 3. Commit your changes: `git commit -am 'Add some feature'`
725
+ 4. Push to the branch: `git push origin feature/your-feature-name`
726
+ 5. Submit a pull request
727
+
728
+ ## License
729
+
730
+ This MCP server is licensed under the MIT License. See the LICENSE file for details.