MySQL MCP Server
A lightweight server for executing SQL queries and inspecting schemas across multiple MySQL database connections. It provides tools for managing persistent connection configurations and exploring database structures through natural language.
README
MySQL MCP Server
A lightweight Model Context Protocol (MCP) server for MySQL database operations. Supports multiple named connections and runs in a minimal Docker container.
Features
- Multiple Connections: Manage multiple MySQL connections with unique names
- Persistent Storage: Connection configs saved to SQLite (survives restarts)
- Query Execution: Execute arbitrary SQL queries with parameterized support
- Schema Inspection: List databases, tables, and describe table structures
- Minimal Footprint: Alpine-based Docker image (~92MB)
- Pre-configured Connections: Optionally load connections from environment variables
Tools
| Tool | Description |
|---|---|
add_connection |
Add a new MySQL connection with a unique name |
remove_connection |
Remove an existing connection |
list_connections |
List all active connections |
execute_query |
Execute SQL queries on a named connection |
list_databases |
List all databases on a connection |
list_tables |
List tables in a database |
describe_table |
Get table schema/structure |
Quick Start
Build the Docker Image
docker build -t mysql-mcp .
Run with Docker
# Run interactively (for MCP stdio communication)
# Mount ./config to persist connection data
docker run -i --rm -v $(pwd)/config:/app/config mysql-mcp
Pre-configure Connections
Set the MYSQL_CONNECTIONS environment variable with a JSON array:
docker run -i --rm \
-v $(pwd)/config:/app/config \
-e MYSQL_CONNECTIONS='[{"name": "prod", "host": "mysql.example.com", "port": 3306, "user": "admin", "password": "secret", "database": "myapp"}]' \
mysql-mcp
Docker Compose
docker-compose up -d
MCP Configuration
Add to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": ["run", "-i", "--rm", "-v", "/path/to/config:/app/config", "mysql-mcp"],
"env": {
"MYSQL_CONNECTIONS": "[{\"name\": \"dev\", \"host\": \"host.docker.internal\", \"port\": 3306, \"user\": \"root\", \"password\": \"secret\"}]"
}
}
}
}
Note: Use host.docker.internal to connect to MySQL running on your host machine.
Usage Examples
Add a Connection
{
"name": "add_connection",
"arguments": {
"name": "production",
"host": "db.example.com",
"port": 3306,
"user": "app_user",
"password": "secure_password",
"database": "myapp"
}
}
Execute a Query
{
"name": "execute_query",
"arguments": {
"connection": "production",
"query": "SELECT * FROM users WHERE status = %s LIMIT 10",
"params": ["active"]
}
}
List Tables
{
"name": "list_tables",
"arguments": {
"connection": "production",
"database": "myapp"
}
}
Development
Run Locally (without Docker)
# Install dependencies
pip install -r requirements.txt
# Run the server
python src/server.py
Test with a Local MySQL
Uncomment the MySQL service in docker-compose.yml:
docker-compose up -d
Persistence
Connection configurations are stored in a SQLite database at /app/config/connections.db. Mount a volume to ./config to persist connections across container restarts:
docker run -i --rm -v $(pwd)/config:/app/config mysql-mcp
The database stores:
- Connection name, host, port, user, password, and default database
Security Notes
- Passwords are stored in the SQLite database - ensure the config directory has appropriate permissions
- Use environment variables for initial seeding; they will be saved to the store
- The container runs as a non-root user (uid 1000)
- Consider using Docker secrets or a vault for sensitive credentials
- Set
MCP_CONFIG_PATHenvironment variable to customize the config directory
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。