MySQL Database Explorer
STDIOModel Context Protocol server providing read-only access to MySQL databases.
Model Context Protocol server providing read-only access to MySQL databases.
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.
The easiest way to install and configure this MCP server is through Smithery:
# Install the MCP server 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:
You can also install this package using MCP Get:
npx @michaellatman/mcp-get@latest install @benborla29/mcp-server-mysql
MCP Get provides a centralized registry of MCP servers and simplifies the installation process.
For manual installation:
# Using npm npm install -g @benborla29/mcp-server-mysql # Using pnpm pnpm add -g @benborla29/mcp-server-mysql
After manual installation, you'll need to configure your LLM application to use the MCP server (see Configuration section below).
sql
(string): The SQL query to executeThe server provides comprehensive database information:
If you installed using Smithery, your configuration is already set up. You can view or modify it with:
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):
{ "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:
{ "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_HOST
: MySQL server host (default: "127.0.0.1")MYSQL_PORT
: MySQL server port (default: "3306")MYSQL_USER
: MySQL username (default: "root")MYSQL_PASS
: MySQL passwordMYSQL_DB
: Target database nameMYSQL_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:
Create Test Database and User
-- 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;
Run Database Setup Script
# Run the database setup script pnpm run setup:test:db
This will create the necessary tables and seed data. The script is located in scripts/setup-test-db.ts
Configure Test Environment
Create a .env.test
file in the project root:
MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USER=mcp_test MYSQL_PASS=mcp_test_password MYSQL_DB=mcp_test
Update package.json Scripts Add these scripts to your package.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:
# First-time setup pnpm run setup:test:db # Run all tests pnpm test
If you installed with Smithery, you can use its built-in diagnostics:
# Check the status of your MCP server smithery status @benborla29/mcp-server-mysql # Run diagnostics smithery diagnose @benborla29/mcp-server-mysql # View logs smithery logs @benborla29/mcp-server-mysql
If you installed with MCP Get:
# Check the status mcp-get status @benborla29/mcp-server-mysql # View logs mcp-get logs @benborla29/mcp-server-mysql
Connection Issues
Performance Issues
Security Restrictions
Path Resolution If you encounter an error "Could not connect to MCP server mcp-server-mysql", explicitly set the path of all required binaries:
{ "env": { "PATH": "/path/to/node/bin:/usr/bin:/bin" } }
caching_sha2_password
authentication pluginCREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Contributions are welcome! Please feel free to submit a Pull Request to https://github.com/benborla/mcp-server-mysql
pnpm install
pnpm run build
pnpm test
We're actively working on enhancing this MCP server. Check our CHANGELOG.md for details on planned features, including:
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.
git checkout -b feature/your-feature-name
git commit -am 'Add some feature'
git push origin feature/your-feature-name
This MCP server is licensed under the MIT License. See the LICENSE file for details.