A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases. This server allows AI assistants to list tables, read data, and execute SQL queries through a controlled interface, making database exploration and analysis safer and more structured.
Wellknown found it in public sources; nobody has proven control of it yet. Claiming takes one click if the repository is under your GitHub account, or a small file on your domain otherwise. Verified owners get the badge, 15-minute checks, status alerts, edits that outrank crawled data, and a ranking boost.
Agents can do it too: POST https://wellknown.network/api/v1/claims with {"agent":"mysql-mcp-server-ddz","method":"well_known_file"} — machine-readable steps at claim.json, guide at /docs/claim.
Everything here was measured by our prober or read from a registry. Nothing is self-reported.
Attributed to the source that supplied each field. Treated as claims, not facts.
# MySQL MCP Server(基于 FastMCP 的 MySQL 工具服务器) 一个基于 **Model Context Protocol (MCP)** 的 MySQL 服务器,使用 **FastMCP** 框架实现, 用于让 AI 应用(例如 Claude Desktop、支持 MCP 的 IDE 等)安全地访问和操作 MySQL 数据库。 > **定位**:这是一个“给大模型用的 MySQL 工具层”,不是传统意义上的 Web API 服务。 > > 你可以把它理解成:把 MySQL 封装成一个 MCP Server, > 让 LLM 通过标准协议调用“列出表、查看表数据、执行 SQL”这类能力。 --- ## 功能概览 - **列出表**: - 通过资源 `mysql://tables` 列出当前数据库下所有表名 - **查看表数据**: - 通过资源 `mysql://{table}/data` 读取指定表前 100 行,返回 CSV 文本 - **执行 SQL**: - 提供工具 `execute_sql(query: str)`,可以执行任意 SQL(读写都可以) - 对 `SHOW TABLES` 做了专门格式处理,保持与历史版本兼容 - **环境变量配置**: - 所有数据库连接参数都来自环境变量,便于在本地 / 服务器 / 容器中统一管理 - **日志完善**: - 所有关键路径(连接、查询、错误)都有日志记录,便于调试 --- ## 技术栈 - **语言与运行环境**: - Python 3.11+ - **MCP 框架**: - [`fastmcp`](https://pypi.org/project/fastmcp/) —— 高层 MCP Server 框架 - **数据库驱动**: - `mysql-connector-python` - **项目打包 / 构建**: - `pyproject.toml` + `hatchling` - **测试**: - `pytest` + `pytest-asyncio`(目前示例测试只覆盖配置和基本初始化) --- ## 安装与依赖 > 建议使用 [`uv`](https://github.com/astral-sh/uv) 管理 Python 环境和依赖(更快、更干净)。 ### 1. 克隆仓库 ```bash git clone https://github.com/designcomputer/mysql_mcp_server_ddz.git cd mysql_mcp_server_ddz ``` ### 2. 安装依赖(推荐 uv) 在项目根目录执行: ```bash uv pip install -r requirements.txt ``` 如果你希望开发 /运行测试,还可以安装开发依赖: ```bash uv pip install -r requirements-dev.txt ``` > 依赖的核心部分: > > - `fastmcp` > - `mysql-connector-python>=9.1.0` 如果你是通过 PyPI 安装(发布包名称可能为 `mysql-mcp-server`),可以: ```bash pip install mysql-mcp-server ``` > 具体包名以实际发布为准,这个仓库的源码已经适配 fastmcp。 > 若仅在本地使用,可以直接 `uv pip install -e .` 做可编辑安装。 --- ## 数据库配置(环境变量) 所有数据库连接信息都通过环境变量传入,这对本地、服务器、容器都适用。 必须配置: ```bash MYSQL_HOST=localhost # 数据库主机 MYSQL_PORT=3306 # 端口(可选,默认 3306) MYSQL_USER=root # 数据库用户名 MYSQL_PASSWORD=123456 # 数据库密码 MYSQL_DATABASE=jspt # 要连接的数据库名 ``` 可选配置(兼容性与高级配置): ```bash MYSQL_CHARSET=utf8mb4 MYSQL_COLLATION=utf8mb4_unicode_ci MYSQL_SQL_MODE=TRADITIONAL ``` > 如果缺少 `MYSQL_USER` / `MYSQL_PASSWORD` / `MYSQL_DATABASE` 中任意一个, > 在启动时会直接抛出 `Value…
Mapped onto the structured taxonomy from declared text and observed tool names. Confidence shown for derived entries.
Every source is kept verbatim. Field changes are logged as events.