mysql-mcp
It is a MySQL MCP server that lets clients inspect and query MySQL databases and perform controlled writes, using per-call credentials and safety limits.
Run as stdio or Streamable HTTP MCP server (Docker supported).
Check server health and MySQL version.
List available databases and tables.
Describe/ show table structures.
Fetch table rows with optional where, order_by, and limit.
Count rows with optional filtering.
Execute custom SQL with default read-only mode; allowed statements are SELECT, SHOW, DESCRIBE, EXPLAIN; multi-statements are rejected.
Insert rows, update and delete rows with bound parameters and row-count limits.
Credentials are provided per tool call and not persisted; supports optional auth token/TLS for HTTP transport.
Provides tools for interacting with a MySQL database, enabling listing databases and tables, fetching and counting rows, viewing table structures, inserting/updating/deleting rows, and executing SQL queries.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mysql-mcp Show me the first 50 rows from the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mysql-mcp
一个支持 stdio 和 Streamable HTTP 的 MySQL MCP Server。模型可以通过工具查询表、执行受控 SQL,以及插入、更新和删除数据。
快速开始
cd /path/to/mysql-mcp
uv syncstdio(桌面 MCP 客户端)
{
"mcpServers": {
"mysql-mcp": {
"command": "/path/to/mysql-mcp/.venv/bin/python",
"args": ["-m", "mysql_mcp"]
}
}
}使用 .venv/bin/python 的绝对路径;不要在客户端配置中依赖 cwd 或 uv run。
Streamable HTTP
.venv/bin/python -m mysql_mcp.mcp_server \
--transport streamable-http --host 127.0.0.1 --port 8000 --path /mcpMCP 地址:http://127.0.0.1:8000/mcp。这是 MCP 协议端点,不是普通网页。
可信内网可以使用 HTTP;跨不可信网段时建议设置 MYSQL_MCP_AUTH_TOKEN 或使用
--auth-token。没有证书也可以先用 HTTP + Token,HTTPS 不是运行前提。
Docker
docker compose up -d --build
docker compose logs -f mysql-mcp
docker compose down镜像名为 sundonglai/mysql-mcp:latest,容器名为 mysql-mcp。Compose 默认监听宿主机
所有网卡的 8002(容器内仍是 8000),局域网内用 http://<宿主机IP>:8002/mcp 访问;
这样可以与 contracts 和 Office 服务同机运行。
服务没有连接档案、remember 或兼容接口。数据库凭据必须由每次工具调用提供, 连接关闭后立即丢弃。
Related MCP server: Local MySQL Read-only MCP Server
连接数据库
每次业务调用都直接传入数据库凭据:
list_tables(credentials={
"host": "db.example.com",
"user": "reader",
"password": "...",
"database": "app"
})服务只在内存中使用凭据,连接关闭后不会保存密码。
工具
工具 | 作用 |
| 检查连接和 MySQL 版本 |
| 列出数据库 |
| 列出表 |
| 查看表结构 |
| 查询表数据,支持结构化过滤和排序 |
| 统计行数 |
| 执行单条 SQL,默认只读 |
| 数据变更 |
安全边界
execute_query默认只允许SELECT、SHOW、DESCRIBE、EXPLAIN。永远拒绝多语句 SQL;表名、字段名经过标识符校验,值使用参数绑定。
查询默认返回 50 行,服务端上限 500 行。
结构化更新和删除默认最多影响 1000 行,硬上限 10000 行。
read_only=true的连接拒绝写操作。execute_query(read_only=false)仍是高权限通道,真正的权限控制应使用 MySQL 账号权限。Docker 默认只绑定回环地址。可信内网开放端口时至少设置 Token;跨不可信网络再增加 HTTPS。
项目结构
src/mysql_mcp/
├── mcp_server.py # MCP transport 入口
├── server.py # 工具和 SQL 策略
├── client.py # MySQL 连接生命周期
└── credentials.py # 单次凭据校验和 TLS 配置(无文件读写)开发
.venv/bin/python -m pytest
.venv/bin/ruff check .
.venv/bin/ruff format --check .
docker compose config不要提交 .venv/、Docker 数据卷或任何密码文件。
License
MIT
Available Tools
11 toolscount_rowsD
Inputs: table_name (required), where. Returns: object
delete_rowsD
Inputs: where (required), table_name (required), where_params. Returns: object
describe_tableD
Inputs: table_name (required). Returns: result
execute_queryD
Inputs: sql (required), limit, read_only. Returns: object
execute_sqlD
Inputs: sql (required), limit, read_only. Returns: object
fetch_tableD
Inputs: table_name (required), limit, where, order_by. Returns: object
get_databasesD
Inputs: no named parameters. Returns: result
health_checkD
Inputs: no named parameters. Returns: object
insert_rowD
Inputs: row (required), table_name (required). Returns: object
list_tablesD
Inputs: no named parameters. Returns: result
update_rowsD
Inputs: where (required), updates (required), table_name (required), where_params. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Several tools have unclear boundaries: execute_sql and execute_query appear to do nearly the same thing, and fetch_table may overlap with execute_query for reading data. An agent could easily select the wrong generic tool despite the clear CRUD/schema tools.
Most names follow a predictable verb_noun snake_case pattern (list_tables, count_rows, delete_rows). Minor inconsistencies exist, such as insert_row singular vs update_rows/delete_rows pluralched and execute_sql vs execute_query using different nouns for the same conceptual operation.
11 tools is a reasonable size for a database MCP server case. However, execute_sql and execute_query are redundant, so not every tool clearly earns its place.
The set covers health, database/table listing, schema inspection, row CRUD, counting, and arbitrary SQL, so core database operations are well covered. Dedicated table lifecycle operations are missing but can be handled through execute_sql, making this a minor gap rather than a fatal one.
Maintenance
Related MCP Connectors
An MCP server that provides read access to your cloud storage providers, bank accounts and more.
Query, join, profile, clean and convert CSV/JSON/Parquet with server-side DuckDB over MCP.
Hosted MySQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Read-only MCP server for ClassQuill, a tutoring-business-management platform.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides MySQL database integration for AI assistants and other MCP clients, allowing them to list tables, read table data, and execute SQL queries.-
- FlicenseNot gradedqualityDmaintenanceProvides a read-only interface to local MySQL databases via MCP, enabling listing databases, tables, describing schemas, and querying rows with structured filters.-
- AlicenseNot gradedqualityCmaintenanceEnables executing SQL queries against a MySQL database via MCP, returning results as JSON.1,407,682 npmMIT
- FlicenseAqualityDmaintenanceMCP server that lets clients run SQL (select/insert/update/delete) against a MySQL database, with readonly and readwrite modes.4-