mysql-mcp-xu

xmqsvip/mysql-mcp-xu
1 Stars 595 次浏览 更新于 2026-08-23

MySQL MCP Xu 是一个基于 FastMCP 的 MySQL MCP Server 项目,提供了一个安全、高效的接口来执行 SQL 操作。该项目支持多种权限控制(读、写、管理员),并通过工具函数实现了表结构查询、索引信息获取、健康状态监控等功能。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "mysql-mcp-xu": {
      "args": [
        "--directory",
        "D:/mysql-mcp-xu/src/mysql_mcp_xu",
        "run",
        "-m",
        "mcp_server",
        "sse"
      ],
      "command": "uv"
    }
  }
}

该服务需要配置环境变量:MYSQL_DATABASE、MYSQL_HOST、MYSQL_PASSWORD、MYSQL_PORT、MYSQL_ROLE、MYSQL_USER

可用工具 (5 个)

该服务在 MCP 协议中暴露的工具,AI 可按需调用

execute_sql 1 个参数 需填 1 项

在MySql数据库上执行";"分割的SQL语句并返回结果(Execute the SQL statements separated by ";" on the MySql database and return the results) :param: sqls (str): SQL语句,多个SQL语句以";"分隔 :return:: 结果以CSV格式返回,包含列名和数据

必填参数:sqls

get_table_structure 1 个参数 需填 1 项

根据表名搜索数据库中对应的表字段(Search for the corresponding table fields in the database based on the table name) :param: table_names (str): 要查询的表名,多个表名以逗号分隔 :return:: - 返回表的字段名、字段注释等信息 - 结果按表名和字段顺序排序 - 结果以CSV格式返回,包含列名和数据

必填参数:table_names

get_table_indexes 1 个参数 需填 1 项

获取指定表的索引信息(Get the index information of the specified table.) :param table_names:要查询的表名,多个表名以逗号分隔 :return: - 返回表的索引名、索引字段、索引类型等信息 - 结果按表名、索引名和索引顺序排序 - 结果以CSV格式返回,包含列名和数据

必填参数:table_names

search_table_by_chinese 1 个参数 需填 1 项

根据表中文名或表描述搜索数据库中对应的表名 :param: table_name (str): 表中文名或表描述 :return:: - 返回匹配的表名 - 匹配结果按匹配度排序 - 匹配结果以CSV格式返回,包含列名和数据

必填参数:table_name

get_mysql_health

获取当前mysql的健康状态(Obtain the current health status of MySQL)

该工具无需必填参数,直接调用即可

服务介绍

PyPI Version
PyPI Downloads

MySQL MCP Xu

Project Overview

MySQL MCP Xu is a MySQL MCP Server project based on FastMCP, providing a secure and efficient interface for executing SQL operations. The project supports multiple permission controls (read, write, admin) and implements functions such as table structure queries, index information retrieval, and health status monitoring through utility functions.

Directory Structure

plaintext
.
├── src
│ └── mysql_mcp_xu
│ ├── init.py
│ ├── config.py
│ └── mcp_server.py
├── README.md
└── pyproject.toml

Quick Start

  1. Install: pip install mysql-mcp-xu
  2. Create a .env file in the directory where you will run the command, with the following content:
    bash
    MYSQL_HOST=localhost
    MYSQL_PORT=3306
    MYSQL_USER=your_username
    MYSQL_PASSWORD=your_password
    MYSQL_DATABASE=your_database

Possible values: r, w, a

MYSQL_ROLE=r

  1. Start the command:
    • STDIO: uv run -m mysql_mcp_xu.mcp_server
    • Streamable HTTP: uv run -m mysql_mcp_xu.mcp_server sh
    • SSE: uv run -m mysql_mcp_xu.mcp_server sse
  2. Connect to the service using an MCP client and execute SQL operations.

Features

  • SQL Execution: Supports executing multiple SQL statements and returning results.
  • Permission Control: Restricts SQL operations based on roles (read, write, admin).
  • Table Structure Query: Retrieves field names, field comments, etc., for a specified table.
  • Index Information Retrieval: Retrieves index names, index fields, index types, etc., for a specified table.
  • Health Status Monitoring: Retrieves the health status of MySQL, including connection count, query count, buffer pool usage, etc.

Permission Control

Permission control is implemented via the PERMISSIONS dictionary, supporting the following roles:

  • r: Read-only permission, allowing SELECT, SHOW, DESCRIBE, EXPLAIN, USE operations.
  • w: Read-write permission, allowing SELECT, SHOW, DESCRIBE, EXPLAIN, INSERT, UPDATE, DELETE, USE operations.
  • a: Admin permission, allowing all operations, including CREATE, ALTER, DROP, TRUNCATE, etc.

Utility Functions

  • execute_sql: Executes an SQL statement and returns the result.
  • get_table_structure: Retrieves field information for a specified table.
  • get_table_indexes: Retrieves index information for a specified table.
  • search_table_by_chinese: Searches for the corresponding table name in the database by Chinese table name or table description.
  • get_mysql_health: Retrieves the health status of MySQL.

Deployment Methods

Using uvx for Deployment

Add the following configuration to the MCP configuration file to deploy the MySQL MCP Xu service using uvx:

STDIO

json
{
"mcpServers": {
"mysql-mcp-xu": {
"command": "uvx",
"args": [
"mysql-mcp-xu"
],
"env": {
"MYSQL_DATABASE": "",
"MYSQL_HOST": "",
"MYSQL_PASSWORD": "",
"MYSQL_PORT": "3306",
"MYSQL_ROLE": "r",
"MYSQL_USER": ""
}
}
}
}

Streamable HTTP

json
{
"mcpServers": {
"mysql-mcp-xu": {
"name": "mysql-mcp-xu",
"type": "streamableHttp",
"description": "",
"isActive": true,
"baseUrl": "http://localhost:9009/mcp"
}
}
}

SSE

json
{
"mcpServers": {
"mysql-mcp-xu": {
"name": "mysql-mcp-xu",
"description": "",
"isActive": true,
"baseUrl": "http://localhost:9009/sse"
}
}
}

Using uv for Deployment

json
{
"mcpServers": {
"mysql-mcp-xu": {
"command": "uv",
"args": [
"--directory",
"D:/mysql-mcp-xu/src/mysql_mcp_xu",
"run",
"-m",
"mcp_server"
]
}
}
}

Streamable HTTP

json
{
"mcpServers": {
"mysql-mcp-xu": {
"command": "uv",
"args": [
"--directory",
"D:/mysql-mcp-xu/src/mysql_mcp_xu",
"run",
"-m",
"mcp_server",
"sh"
]
}
}
}#### sse
json
{
"mcpServers": {
"mysql-mcp-xu": {
"command": "uv",
"args": [
"--directory",
"D:/mysql-mcp-xu/src/mysql_mcp_xu",
"run",
"-m",
"mcp_server",
"sse"
]
}
}
}

相关 MCP 服务