Skip to content

Commit 07b89c6

Browse files
authored
Merge pull request #68 from crewsycrews/feature/remote-mcp
Support for the remote mcp
2 parents 5cc3702 + 82e036f commit 07b89c6

File tree

7 files changed

+459
-216
lines changed

7 files changed

+459
-216
lines changed

.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ MYSQL_MAX_QUERY_COMPLEXITY=1000
4444
ENABLE_LOGGING=true
4545
MYSQL_LOG_LEVEL=info
4646
MYSQL_METRICS_ENABLED=false
47+
48+
# Remote MCP configuration
49+
IS_REMOTE_MCP=false
50+
PORT=3000
51+
REMOTE_SECRET_KEY=

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
20

README.md

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11

22
# MCP Server for MySQL based on NodeJS
3-
[![smithery badge](https://smithery.ai/badge/@benborla29/mcp-server-mysql)](https://smithery.ai/server/@benborla29/mcp-server-mysql)
43

5-
![Demo](assets/demo.gif)
6-
<a href="https://glama.ai/mcp/servers/@benborla/mcp-server-mysql">
7-
<img width="380" height="200" src="https://glama.ai/mcp/servers/@benborla/mcp-server-mysql/badge" />
8-
</a>
94

105
A Model Context Protocol server that provides access to MySQL databases. This server enables LLMs to inspect database schemas and execute SQL queries.
116

@@ -14,6 +9,7 @@ A Model Context Protocol server that provides access to MySQL databases. This se
149
- [Installation](#installation)
1510
- [Smithery](#using-smithery)
1611
- [Clone to Local Repository](#running-from-local-repository)
12+
- [Remote mode](#run-in-remote-mode)
1713
- [Components](#components)
1814
- [Configuration](#configuration)
1915
- [Environment Variables](#environment-variables)
@@ -26,7 +22,7 @@ A Model Context Protocol server that provides access to MySQL databases. This se
2622

2723
## Requirements
2824

29-
- Node.js v18 or higher
25+
- Node.js v20 or higher
3026
- MySQL 5.7 or higher (MySQL 8.0+ recommended)
3127
- MySQL user with appropriate permissions for the operations you need
3228
- For write operations: MySQL user with INSERT, UPDATE, and/or DELETE privileges
@@ -199,11 +195,11 @@ claude mcp add mcp_server_mysql \
199195
```bash
200196
# Find your Node.js path
201197
which node
202-
198+
203199
# For PATH environment variable
204200
echo "$(which node)/../"
205-
206-
# For NODE_PATH environment variable
201+
202+
# For NODE_PATH environment variable
207203
echo "$(which node)/../../lib/node_modules"
208204
```
209205

@@ -295,6 +291,43 @@ If you want to clone and run this MCP server directly from the source code, foll
295291

296292
If it connects to MySQL successfully, you're ready to use it with Claude Desktop.
297293

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+
298331
## Components
299332

300333
### Tools
@@ -391,22 +424,22 @@ For more control over the MCP server's behavior, you can use these advanced conf
391424
"MYSQL_PASS": "",
392425
"MYSQL_DB": "db_name",
393426
"PATH": "/path/to/node/bin:/usr/bin:/bin",
394-
427+
395428
// Performance settings
396429
"MYSQL_POOL_SIZE": "10",
397430
"MYSQL_QUERY_TIMEOUT": "30000",
398431
"MYSQL_CACHE_TTL": "60000",
399-
432+
400433
// Security settings
401434
"MYSQL_RATE_LIMIT": "100",
402435
"MYSQL_MAX_QUERY_COMPLEXITY": "1000",
403436
"MYSQL_SSL": "true",
404-
437+
405438
// Monitoring settings
406439
"ENABLE_LOGGING": "true",
407440
"MYSQL_LOG_LEVEL": "info",
408441
"MYSQL_METRICS_ENABLED": "true",
409-
442+
410443
// Write operation flags
411444
"ALLOW_INSERT_OPERATION": "false",
412445
"ALLOW_UPDATE_OPERATION": "false",
@@ -451,6 +484,11 @@ For more control over the MCP server's behavior, you can use these advanced conf
451484
- `MYSQL_LOG_LEVEL`: Logging level (default: "info")
452485
- `MYSQL_METRICS_ENABLED`: Enable performance metrics (default: "false")
453486

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+
454492
## Multi-DB Mode
455493

456494
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).
@@ -493,7 +531,7 @@ Before running tests, you need to set up the test database and seed it with test
493531
```sql
494532
-- Connect as root and create test database
495533
CREATE DATABASE IF NOT EXISTS mcp_test;
496-
534+
497535
-- Create test user with appropriate permissions
498536
CREATE USER IF NOT EXISTS 'mcp_test'@'localhost' IDENTIFIED BY 'mcp_test_password';
499537
GRANT ALL PRIVILEGES ON mcp_test.* TO 'mcp_test'@'localhost';
@@ -591,12 +629,12 @@ Run the following command to get it:
591629

592630
For **PATH**
593631
```bash
594-
echo "$(which node)/../"
632+
echo "$(which node)/../"
595633
```
596634

597635
For **NODE_PATH**
598636
```bash
599-
echo "$(which node)/../../lib/node_modules"
637+
echo "$(which node)/../../lib/node_modules"
600638
```
601639

602640
5. **Claude Desktop Specific Issues**
@@ -652,7 +690,7 @@ Thanks to @lizhuangs
652690

653691
## Contributing
654692

655-
Contributions are welcome! Please feel free to submit a Pull Request to
693+
Contributions are welcome! Please feel free to submit a Pull Request to
656694
https://github.com/benborla/mcp-server-mysql
657695

658696
## Many Thanks to the following Contributors:

0 commit comments

Comments
 (0)