MCP Server for MySQL based on NodeJS

by MCP-Mirror

54.3k downloads Not rated yet MIT license

About

A Model Context Protocol server that provides read-only access to MySQL databases, enabling LLMs to inspect database schemas and execute read‑only queries. It is built on Node.js and is intended for developers who want their AI assistants to query MySQL safely.

Details

License
MIT license

Explore

- SQL injection prevention through prepared statements
- Query whitelisting/blacklisting capabilities
- Rate limiting for query execution
- Query complexity analysis
- Configurable connection encryption
- Read-only transaction enforcement

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MCP Server for MySQL based on NodeJS
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

npx -y @smithery/cli@latest install @benborla29/mcp-server-mysql --client claude


During configuration, you'll be prompted to enter your MySQL connection details. Smithery will automatically:
- Set up the correct environment variables
- Configure your LLM application to use the MCP server
- Test the connection to your MySQL database
- Provide helpful troubleshooting if needed

If you installed using Smithery, your configuration is already set up. You can view or modify it with:

bash
smithery configure @benborla29/mcp-server-mysql

To manually configure the MCP server for Claude Desktop App, add the following to your claude_desktop_config.json file (typically located in your user directory):

json
{
"mcpServers": {
"mcp_server_mysql": {
"command": "npx",
"args": [
"-y",
"@benborla29/mcp-server-mysql"
],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "",
"MYSQL_DB": "db_name"
}
}
}
}

Replace db_name with your database name or leave it blank to access all databases.

For more control over the MCP server's behavior, you can use these advanced configuration options:

json
{
"mcpServers": {
"mcp_server_mysql": {
"command": "/path/to/npx/binary/npx",
"args": [
"-y",
"@benborla29/mcp-server-mysql"
],
"env": {
// Basic connection settings
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "root",
"MYSQL_PASS": "",
"MYSQL_DB": "db_name",
"PATH": "/path/to/node/bin:/usr/bin:/bin",

// Performance settings
"MYSQL_POOL_SIZE": "10",
"MYSQL_QUERY_TIMEOUT": "30000",
"MYSQL_CACHE_TTL": "60000",

// Security settings
"MYSQL_RATE_LIMIT": "100",
"MYSQL_MAX_QUERY_COMPLEXITY": "1000",
"MYSQL_SSL": "true",

// Monitoring settings
"MYSQL_ENABLE_LOGGING": "true",
"MYSQL_LOG_LEVEL": "info",
"MYSQL_METRICS_ENABLED": "true"
}
}
}
}

- MYSQL_POOL_SIZE: Connection pool size (default: "10")
- MYSQL_QUERY_TIMEOUT: Query timeout in milliseconds (default: "30000")
- MYSQL_CACHE_TTL: Cache time-to-live in milliseconds (default: "60000")

- MYSQL_RATE_LIMIT: Maximum queries per minute (default: "100")
- MYSQL_MAX_QUERY_COMPLEXITY: Maximum query complexity score (default: "1000")
- MYSQL_SSL: Enable SSL/TLS encryption (default: "false")

- MYSQL_ENABLE_LOGGING: Enable query logging (default: "false")
- MYSQL_LOG_LEVEL: Logging level (default: "info")
- MYSQL_METRICS_ENABLED: Enable performance metrics (default: "false")

Before running tests, you need to set up the test database and seed it with test data:

1. Create Test Database and User

sql
-- Connect as root and create test database
CREATE DATABASE IF NOT EXISTS mcp_test;

-- Create test user with appropriate permissions
CREATE USER IF NOT EXISTS 'mcp_test'@'localhost' IDENTIFIED BY 'mcp_test_password';
GRANT ALL PRIVILEGES ON mcp_test.* TO 'mcp_test'@'localhost';
FLUSH PRIVILEGES;

2. Run Database Setup Script
bash

pnpm run setup:test:db


This will create the necessary tables and seed data. The script is located in scripts/setup-test-db.ts

3. Configure Test Environment
Create a .env.test file in the project root:

env
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=mcp_test
MYSQL_PASS=mcp_test_password
MYSQL_DB=mcp_test

4. Update package.json Scripts
Add these scripts to your package.json:
json
{
"scripts": {
"setup:test:db": "ts-node scripts/setup-test-db.ts",
"pretest": "pnpm run setup:test:db",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
}
}

The project includes a comprehensive test suite to ensure functionality and reliability:

bash

pnpm run setup:test:db

1. Clone the repository
2. Install dependencies: pnpm install
3. Build the project: pnpm run build
4. Run tests: pnpm test

- mysql_query
- Execute read-only SQL queries against the connected database
- Input: sql (string): The SQL query to execute
- All queries are executed within a READ ONLY transaction
- Supports prepared statements for secure parameter handling
- Configurable query timeouts and result pagination
- Built-in query execution statistics

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mcp server for mysql based on nodejs": {
            "zhaoxin34_mcp-server-mysql": {
                "command": "npx",
                "args": [
                    "-y",
                    "@smithery/cli@latest",
                    "install",
                    "@benborla29/mcp-server-mysql",
                    "--client",
                    "claude"
                ]
            }
        }
    }
}

McpServers

{
    "zhaoxin34_mcp-server-mysql": {
        "command": "npx",
        "args": [
            "-y",
            "@smithery/cli@latest",
            "install",
            "@benborla29/mcp-server-mysql",
            "--client",
            "claude"
        ]
    }
}
smithery badge

Demo

A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.

Installation

Using Smithery

The easiest way to install and configure this MCP server is through Smithery:

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.