
Mysql
io.github.codeChap由 GitHub 账号 codeChap 发布v0.2.0更新于 Oct 24, 2026
MCP server for MySQL/MariaDB — pooled async queries with destructive-query safety
概览
本地运行的 MCP 服务器,让 AI 助手查看 MySQL 或 MariaDB 表结构并执行 SQL 查询,默认只读。
- 可以做什么
- 查看表结构、字段、索引和约束,或一次列出所有表。执行 SQL 查询,并可为每条查询指定数据库。在开启写入模式后插入、更新和删除数据行。返回受影响行数和最后插入 ID,使用连接池并在瞬时故障时重试。
- 适用场景
- 适合让助手探索 MySQL 或 MariaDB 数据库、基于数据回答问题,或在监督下做有针对性的行级修改。更适合本地开发或使用专用数据库账号,而不是无限制的生产环境访问。
- 运行要求
- 以本地二进制程序运行在用户机器上(用 Rust 1.70+ 从源码构建,或使用发布包)。需要可访问的 MySQL 5.7+ 或 MariaDB 10.2+ 服务器和数据库账号。连接信息通过命令行参数传入:主机、端口、用户名、密码和数据库名。
安装
在 SourceWeft 中
- 打开 控制台中的 Mysql,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
MySQL MCP Server
A high-quality Model Context Protocol (MCP) server implementation for MySQL databases. This server enables AI assistants like Claude to interact with MySQL databases through a standardized protocol.
Version: 0.2.0 | Protocol: MCP 2025-03-26 | Rust: 1.70+ | Status: Production Ready
Table of Contents
- Features
- Installation
- Quick Start (5 Minutes)
- Usage
- Available Tools
- Database Context Feature
- Security Considerations
- Architecture
- Troubleshooting
- Development
- Deployment Guide
- Contributing
- License
- Support
Features
- Schema Inspection: Retrieve table schemas and structure information
- Query Execution: Execute SQL queries (read-only by default for safety)
- Data Manipulation: Insert, update, and delete operations
- Database Context: Specify which database to use per query
- Safety Controls: Configurable query restrictions to prevent dangerous operations
- Connection Management: Robust connection handling with retry logic and pooling
- Error Handling: Comprehensive error reporting with detailed messages
- JSON-RPC 2.0 Protocol: Standardized communication via stdio
Installation
Prerequisites
- Rust 1.70+
- MySQL 5.7+ or MariaDB 10.2+
- Access to a MySQL database
Building from Source
The compiled binary will be available at target/release/mcp-server-mysql.
From Release Package
Quick Start (5 Minutes)
Step 1: Build the Server
The binary will be at target/release/mcp-server-mysql
Step 2: Test the Connection
You should see: "MCP MySQL Server started and ready to accept connections"
Step 3: Configure Claude Desktop
Edit your Claude Desktop configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Add this configuration:
Security Note: For production use, consider using environment variables or a secure secrets management solution instead of hardcoding passwords in the configuration file.
Step 4: Restart Claude Desktop
Close and reopen Claude Desktop completely. You should see a small hammer icon indicating the MCP server is connected.
Step 5: Try it Out!
Ask Claude:
- "Can you show me the schema for the users table in my MySQL database?"
- "Query the database and show me the first 10 rows from the products table"
- "What tables are in my database?"
Usage
Command Line Arguments
Arguments Reference
Configuration with Claude Desktop
Add this configuration to your Claude Desktop config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Available Tools
1. mysql (Schema Inspection)
Retrieve database schema information for tables.
Parameters:
table_name(string): Name of the table to inspect, or"all-tables"to get all table schemas
Example:
Returns:
- Column information (name, type, nullable, defaults, keys)
- Index information
- Table constraints
2. query (SQL Execution)
Execute SQL queries on the database.
Parameters:
query(string): SQL query to executedatabase(string, optional): Database name to use for this specific query
Example:
Safety:
- By default, only SELECT queries are allowed
- Use
--allow-dangerous-queriesflag to enable INSERT/UPDATE/DELETE - Dangerous keywords are blocked unless explicitly enabled
3. insert (Insert Data)
Insert data into a specified table.
Parameters:
table_name(string): Name of the tabledata(object): Key-value pairs of column names and values
Example:
Returns: Last insert ID
4. update (Update Data)
Update data in a specified table based on conditions.
Parameters:
table_name(string): Name of the tabledata(object): Key-value pairs of columns to updateconditions(object): Key-value pairs for WHERE clause
Example:
Returns: Number of affected rows
5. delete (Delete Data)
Delete data from a specified table based on conditions.
Parameters:
table_name(string): Name of the tableconditions(object): Key-value pairs for WHERE clause
Example:
Returns: Number of affected rows
Warning: Always specify conditions to avoid deleting all rows!
Database Context Feature
The Problem
Previously, database context was not maintained between queries:
The Solution
Use the optional database parameter on each query:
Benefits
- Explicit and Clear: Know exactly which database each query uses
- No Hidden State: Each query is independent
- Backward Compatible: Existing queries without parameter still work
- No Race Conditions: Each query gets its own connection
- Simple to Use: Just add
"database": "name"to query arguments
Usage Examples
Basic Query with Database Parameter
Query Without Database Parameter (Uses Default)
Uses the database specified in --database startup argument.
Multiple Databases in Same Session
Before vs After
Before (Required fully qualified names):
After (Clean and simple):
Common Scenarios
Scenario 1: Single Database Project
Set default database and omit the parameter:
Scenario 2: Multiple Database Project
Specify database for each query:
Error Handling
Error Code -32005: Connection Acquisition Failed
Error Code -32006: Database Context Switch Failed
Best Practices
✅ DO
- Specify database explicitly for production queries
- Use descriptive database names in your queries
- Test with
SELECT DATABASE()to verify context - Group queries by database for clarity
❌ DON'T
- Mix qualified and unqualified names in the same query
- Assume persistence - specify database for each query
- Use special characters in database names if possible
- Forget to verify user permissions for all databases
Security Considerations
Read-Only Mode (Default)
By default, the server operates in read-only mode, allowing only SELECT queries. This prevents accidental data modification or deletion.
Dangerous Queries Mode
Enable write operations with --allow-dangerous-queries:
Use with caution! This enables:
- INSERT statements
- UPDATE statements
- DELETE statements
- Other potentially destructive operations
SQL Injection Protection
- Table names are validated to contain only alphanumeric characters and underscores
- All data values are parameterized using prepared statements
- Database names are escaped by replacing backticks with double backticks
- No raw SQL concatenation is performed
Connection Security
- Supports standard MySQL SSL/TLS connections
- Connection strings can be configured securely
- Passwords can be provided via environment variables
- Consider using dedicated database users with limited permissions
Production Deployment Security
-
Use dedicated database user:
-
Enable write access only when needed:
-
Use environment variables (future enhancement): Consider wrapping the binary in a shell script that reads from env vars.
Architecture
System Overview
Sequence: Query with Database Parameter
Connection Pool Management
Technical Details
- Protocol Version: MCP 2025-03-26
- Transport: stdio (JSON-RPC 2.0)
- Connection Pooling: Max 5 connections
- Retry Logic: Automatic reconnection on transient failures
- Performance Overhead: ~50-200 microseconds per query with database parameter
Troubleshooting
Connection Failures
If you encounter connection errors:
-
Check MySQL is running:
-
Verify credentials:
- Ensure the username and password are correct
- Confirm the user has access to the specified database
-
Check network access:
- Verify the host and port are correct
- Ensure no firewall is blocking the connection
-
Review server logs:
- The server logs to stderr
- Check for detailed error messages
Common Errors
"Database connection failed"
- MySQL server may not be running
- Incorrect host/port configuration
- Network connectivity issues
"Only SELECT queries are allowed"
- You're trying to run a write query in read-only mode
- Add
--allow-dangerous-queries trueif write access is needed
"No database selected"
- The specified database doesn't exist
- The user doesn't have access to the database
- Check
SHOW DATABASES;to see available databases
"Table doesn't exist"
- Verify you're querying the correct database
- Add the
databaseparameter if using multiple databases - Use
SELECT DATABASE()to check current context
"Failed to acquire connection"
- Connection pool is exhausted
- Wait a moment and retry
Tool not appearing in Claude Desktop
- Verify the path to the binary is absolute (not relative)
- Check Claude Desktop logs for errors
- Restart Claude Desktop completely (not just reload)
- Ensure the server process starts without errors when run manually
Development
Project Structure
Building for Development
Running Tests
Code Quality
Development Conventions
The project follows standard Rust best practices:
- Code formatting:
cargo fmt - Linting:
cargo clippy - Testing:
cargo test
Deployment Guide
Quick Deployment
1. Test Connection
Press Ctrl+C to exit after seeing "MCP MySQL Server started".
2. Configure Claude Desktop
Edit your Claude config file and add the server configuration (see Quick Start section).
3. Restart Claude Desktop
Close and reopen Claude Desktop completely.
Production Deployment Tips
Performance
- The binary is optimized with
--releaseflag - Connection pooling is configured (max 5 connections)
- Automatic retry logic for transient failures
Monitoring
Server logs go to stderr. Capture them with:
Log levels:
INFO: Connection events, tool callsDEBUG: Detailed query informationWARN: Non-fatal issuesERROR: Failures and errors
Systemd Service (Optional)
For long-running deployments, create /etc/systemd/system/mcp-mysql.service:
Enable and start:
Upgrading
Rollback
Contributing
Contributions are welcome! Please ensure:
- Code follows Rust best practices
- All tests pass
- Documentation is updated
- Commit messages are clear and descriptive
License
Apache-2.0
Support
For issues, questions, or contributions, please open an issue on the project repository.
Version: 0.2.0 | Release Date: 2025-01-XX | Protocol: MCP 2025-03-26 | Platform: Linux x86_64 | Status: Production Ready ✅
来源:README.md,提交 23dbdaf
工具
0版本历史
1- v0.2.0最新Sep 16, 2026
评分
已满足适用检查项的 40%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
请在仓库或注册中心条目中声明许可证。