MySQL MCP Server

io.github.musaddiq-dev由 GitHub 账号 musaddiq-dev 发布v0.1.2更新于 Nov 3, 2026

Python MCP server for MySQL database inspection and querying

已验证STDIO仅桌面数据库数据与分析

概览

AI 生成的概览

本地运行的 Python MCP 服务器,让助手检查并查询 MySQL 数据库:列出表、查看结构、执行受限 SELECT 与解释执行计划。

可以做什么
  • 列出表并查看表结构
  • 执行单条受限 SELECT 查询,带关键字与行数上限保护
  • 获取 SHOW CREATE TABLE 输出与 EXPLAIN 执行计划
  • 汇总表清单与行数
  • 在启用写工具时可执行 INSERT、UPDATE、DELETE 及 DDL 语句
适用场景
适合在 Claude Desktop、Cursor、VS Code 等 MCP 客户端中让助手探索或查询 MySQL 数据库,例如查看表结构、临时只读查询或分析执行计划。只有在能提供数据库连接、最好使用只读账号时才建议安装。
运行要求
通过 uvx(包名 mdev-mysql-mcp-server)或源码在本地以 stdio 运行;需要 Python 3.11+ 与 MySQL 5.7+/8.0+。需配置 MYSQL_DATABASE(必填)以及 MYSQL_HOST、MYSQL_PORT、MYSQL_USER、MYSQL_PASSWORD、MYSQL_POOL_SIZE、MYSQL_READ_QUERY_LIMIT、LOG_LEVEL,并能访问 MySQL 主机。
安装前请注意
客户端配置中会保存数据库凭据(MYSQL_PASSWORD),不要提交到版本库。只读查询的限制不能替代数据库权限,应使用最小权限的只读账号。写入与 DDL 工具可能修改或删除数据,应保持手动审批。不要在无额外认证与传输加密的情况下把该服务器暴露到不可信网络。

安装

在 SourceWeft 中

  1. 打开 控制台中的 MySQL MCP Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

MySQL MCP Server

A Python Model Context Protocol (MCP) server for inspecting and querying MySQL databases from MCP-compatible clients. It provides table discovery, schema inspection, read query execution, DDL lookup, query explanation, and optional write/DDL tools for controlled database administration workflows.

Features

  • List tables and describe table schemas
  • Execute SELECT queries with safety checks
  • Retrieve SHOW CREATE TABLE output
  • Explain query execution plans
  • Summarize tables and row counts
  • Optional write and DDL tools for users who intentionally run with elevated database privileges

Safety Model

mysql_execute_read_query only accepts a single statement beginning with SELECT, rejects common modifying SQL keywords and risky file-read/write forms, and caps returned rows by MYSQL_READ_QUERY_LIMIT. This is a guardrail, not a substitute for database permissions. Use a dedicated read-only MySQL user for safe exploration. The write and DDL tools can modify or destroy data if the configured database user is allowed to do so; keep them on manual approval in your MCP client.

Requirements

  • Python 3.11+
  • MySQL 5.7+ or MySQL 8.0+
  • MCP-compatible client such as Claude Desktop, Cursor, VS Code, or another MCP host

Installation

When published to PyPI, install or run the server like a standard Python MCP package:

bash
uvx mdev-mysql-mcp-server

For local development from source:

bash
git clone https://github.com/musaddiq-dev/mysql-mcp-server.gitcd mysql-mcp-serverpython -m venv .venvsource .venv/bin/activatepip install -e .

Configuration

Copy the example environment file and update it with your database connection details.

bash
cp .env.example .env
VariableDescriptionRequiredDefault
MYSQL_HOSTMySQL hostNolocalhost
MYSQL_PORTMySQL portNo3306
MYSQL_USERMySQL usernameNoroot
MYSQL_PASSWORDMySQL passwordNoEmpty
MYSQL_DATABASEMySQL database nameYesEmpty
MYSQL_POOL_SIZEConnection pool sizeNo5
LOG_LEVELPython logging levelNoINFO
MYSQL_READ_QUERY_LIMITMaximum rows returned by read queriesNo1000

Example read-only user:

sql
CREATE USER 'mcp_readonly'@'localhost' IDENTIFIED BY 'change-me';GRANT SELECT ON your_database.* TO 'mcp_readonly'@'localhost';FLUSH PRIVILEGES;

Running

bash
mdev-mysql-mcp-server

From a local checkout before PyPI publication, run:

bash
python -m mysql_mcp_server.server

MCP Client Configuration

For published installs, prefer uvx. MCP servers using stdio must write protocol messages only to stdout; this server writes logs to stderr through Python logging.

Claude Desktop / Cursor / Windsurf / Cline

Most MCP clients accept this mcpServers JSON shape:

json
{  "mcpServers": {    "mysql": {      "command": "uvx",      "args": ["mdev-mysql-mcp-server"],      "env": {        "MYSQL_HOST": "localhost",        "MYSQL_PORT": "3306",        "MYSQL_USER": "mcp_readonly",        "MYSQL_PASSWORD": "change-me",        "MYSQL_DATABASE": "your_database"      }    }  }}

For local development from this repository, use the installed console script path instead:

json
{  "mcpServers": {    "mysql": {      "command": "/absolute/path/to/mysql-mcp-server/.venv/bin/mdev-mysql-mcp-server",      "args": [],      "env": {        "MYSQL_HOST": "localhost",        "MYSQL_PORT": "3306",        "MYSQL_USER": "mcp_readonly",        "MYSQL_PASSWORD": "change-me",        "MYSQL_DATABASE": "your_database"      }    }  }}

Claude Code CLI

bash
claude mcp add mysql \  --env MYSQL_HOST=localhost \  --env MYSQL_PORT=3306 \  --env MYSQL_USER=mcp_readonly \  --env MYSQL_PASSWORD=change-me \  --env MYSQL_DATABASE=your_database \  -- uvx mdev-mysql-mcp-server

VS Code MCP

VS Code uses the same command/args/env model in its MCP configuration:

json
{  "servers": {    "mysql": {      "type": "stdio",      "command": "uvx",      "args": ["mdev-mysql-mcp-server"],      "env": {        "MYSQL_HOST": "localhost",        "MYSQL_PORT": "3306",        "MYSQL_USER": "mcp_readonly",        "MYSQL_PASSWORD": "change-me",        "MYSQL_DATABASE": "your_database"      }    }  }}

Tools

ToolPurposeSafety
mysql_list_tablesList tables in the configured databaseRead-only
mysql_describe_tableShow schema for a tableRead-only
mysql_execute_read_queryExecute a single bounded SELECT queryRead-only guardrail
mysql_execute_write_queryExecute a single INSERT, UPDATE, or DELETEDestructive
mysql_execute_ddlExecute a single CREATE, DROP, ALTER, or TRUNCATEDestructive
mysql_get_table_ddlReturn SHOW CREATE TABLE outputRead-only
mysql_explain_queryRun EXPLAIN for a single queryRead-only
mysql_get_database_summaryReturn table list and row countsRead-only

Smoke Check

Without a database, verify syntax with:

bash
python -m py_compile src/mysql_mcp_server/server.py

With a configured database, start the server and use your MCP client to call list_tables.

Distribution

This server is published through the standard Python MCP distribution path:

  • PyPI package: mdev-mysql-mcp-server
  • MCP Registry name: io.github.musaddiq-dev/mysql-mcp-server
  • Runtime hint: uvx
  • Transport: stdio

The mcp-name marker at the top of this README is required for MCP Registry ownership verification. Users should prefer uvx mdev-mysql-mcp-server in local MCP client configurations.

Security Notes

  • Do not commit .env or MCP client configs containing credentials.
  • Use least-privilege database users.
  • Keep execute_write_query and execute_ddl on explicit manual approval.
  • Do not expose this server over an untrusted network without additional authentication and transport security.

License

MIT

来源:README.md,提交 be66e02

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.2最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分