Mysql

io.github.marcelo-ochoa由 GitHub 账号 marcelo-ochoa 发布v1.0.7更新于 Oct 24, 2026

An MCP server for MySQL databases.

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

概览

AI 生成的概览

本地 MCP 服务器,让助手以只读方式访问 MySQL 数据库:执行与解释查询、查看表统计和结构,并生成性能报告。

可以做什么
  • 在只读事务中执行只读 SQL 查询
  • 解释查询执行计划并以 JSON 返回
  • 获取指定表的表、索引与列统计信息
  • 生成类似 Oracle AWR 的性能报告,含 InnoDB 指标、高频查询与优化建议
  • 读取每张表的 schema 资源,包含列名与数据类型
  • 在运行中重新连接到其他 MySQL 主机、数据库和凭据
适用场景
适合让助手探索现有 MySQL 数据库、用 SQL 回答问题、调优慢查询,或在不授予写权限的前提下生成性能概览。
运行要求
以 stdio 本地运行,可通过 npx(需 Node.js)或已发布的 Docker 镜像启动。需要可访问的 MySQL 服务器,以及包含主机、端口和数据库的连接串,可作为可选启动参数或通过 mysql-connect 工具提供。凭据来自 MYSQL_USER 与 MYSQL_PASSWORD 环境变量或连接工具。启用 performance_schema 时 mysql-awr 报告最完整。
安装前请注意
MYSQL_PASSWORD 密钥以及传给 mysql-connect 的密码会保存在客户端配置或对话中。文档称访问为只读,但实际可达范围取决于所提供的凭据,建议使用最小权限的 MySQL 账号。查询文本与表结构会发送给模型提供方。mysql-connect 工具可在运行时接受新凭据,请留意连接变更。

安装

在 SourceWeft 中

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

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

其他 MCP 客户端

参照 仓库 中的启动说明。

README

MySQL Database

A Model Context Protocol server that provides read-only access to MySQL databases. This server enables LLMs to inspect database schemas, execute and explain read-only queries, and analyze performance metrics.

Components

Tools

  • mysql-query

    • Execute read-only SQL queries against the connected MySQL database
    • Input: sql (string): The SQL query to execute
    • All queries are executed within a READ ONLY transaction
  • mysql-explain

    • Explain plan SQL queries against the connected MySQL database
    • Input: sql (string): The SQL query to explain
    • Returns execution plan in JSON format
  • mysql-stats

    • Get statistics for a given table in the current connected database
    • Input: name (string): The table name
    • Returns comprehensive table, index, and column statistics
  • mysql-connect

    • Reconnect using new credentials
    • Input: connectionString (string): MySQL connect string (e.g., host.docker.internal:3306/mydb)
    • Input: user (string): Username (e.g., root)
    • Input: password (string): Password

Example: mysql-connect host.docker.internal:3306/hr root my_2025

  • mysql-awr
    • Generate a MySQL performance report similar to Oracle AWR
    • Includes database statistics, InnoDB metrics, top queries (requires performance_schema), table/index statistics, connection info, and optimization recommendations
    • No input required

Resources

The server provides schema information for each table in the MySQL database:

  • Table Schemas (mysql://<database>/<table>/schema)
    • JSON schema information for each table
    • Includes column names and data types
    • Automatically discovered from MySQL database metadata

Configuration

The MySQL server uses environment variables or the mysql-connect tool for secure credential management:

  • MYSQL_USER: MySQL username (optional if using mysql-connect)
  • MYSQL_PASSWORD: MySQL password (optional if using mysql-connect)

Connection String

The connection string should contain only the host, port, and database information (without embedded credentials). Providing it as a command-line argument is optional. If omitted at startup, you must use the mysql-connect tool to establish a connection before using other functionality.

Supported connection string formats:

  • mysql://host:port/dbname
  • host:port/dbname

Usage with Claude Desktop

To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json:

Docker

  • When running Docker on macOS, use host.docker.internal if the MySQL server is running on the host network (e.g., localhost)
  • Credentials are passed via environment variables MYSQL_USER and MYSQL_PASSWORD
json
{  "mcpServers": {    "mysql": {      "command": "docker",      "args": [        "run",         "-i",         "--rm",        "-e", "MYSQL_USER=myuser",        "-e", "MYSQL_PASSWORD=mypassword",        "mochoa/mcp-mysql"      ]    }  }}

Note: You can still provide the connection string as a final argument if you want to connect automatically on startup: "args": [..., "mochoa/mcp-mysql", "host.docker.internal:3306/mydb"].

NPX

json
{  "mcpServers": {    "mysql": {      "command": "npx",      "args": [        "-y",        "@marcelo-ochoa/server-mysql"      ],      "env": {        "MYSQL_USER": "myuser",        "MYSQL_PASSWORD": "mypassword"      }    }  }}

Replace /mydb with your database name.

Note: Replace the following placeholders with your actual values:

  • myuser and mypassword with your MySQL credentials
  • localhost:3306 with your MySQL server host and port
  • mydb with your database name

Usage with VS Code

For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing Ctrl + Shift + P and typing Preferences: Open User Settings (JSON).

Optionally, you can add it to a file called .vscode/mcp.json in your workspace. This will allow you to share the configuration with others.

Note that the mcp key is not needed in the .vscode/mcp.json file.

Docker

Note: When using Docker and connecting to a MySQL server on your host machine, use host.docker.internal instead of localhost in the connection URL.

json
{  "mcp": {    "inputs": [      {        "type": "promptString",        "id": "mysql_user",        "description": "MySQL username"      },      {        "type": "promptString",        "id": "mysql_password",        "description": "MySQL password",        "password": true      }    ],    "servers": {      "mysql": {        "command": "docker",        "args": [          "run",          "-i",          "--rm",          "-e", "MYSQL_USER=${input:mysql_user}",          "-e", "MYSQL_PASSWORD=${input:mysql_password}",          "mochoa/mcp-mysql"        ]      }    }  }}

Note: You can add an input for mysql_url and append it to args if you want to connect on startup.

NPX

json
{  "mcp": {    "inputs": [      {        "type": "promptString",        "id": "mysql_user",        "description": "MySQL username"      },      {        "type": "promptString",        "id": "mysql_password",        "description": "MySQL password",        "password": true      }    ],    "servers": {      "mysql": {        "command": "npx",        "args": [          "-y",          "@marcelo-ochoa/server-mysql"        ],        "env": {          "MYSQL_USER": "${input:mysql_user}",          "MYSQL_PASSWORD": "${input:mysql_password}"        }      }    }  }}

Usage with Antigravity Code Editor

Put this in ~/.gemini/antigravity/mcp_config.json

json
{    "mcpServers": {        "mysql": {            "command": "docker",            "args": [                "run",                "-i",                "--rm",                "-e",                "MYSQL_USER=myuser",                "-e",                "MYSQL_PASSWORD=mypassword",                "mochoa/mcp-mysql",                "host.docker.internal:3306/mydb"            ]        }    },    "inputs": []}

Performance Schema

For optimal performance monitoring with the mysql-awr tool, ensure that the Performance Schema is enabled in your MySQL configuration:

ini
[mysqld]performance_schema = ON

The Performance Schema provides detailed query statistics and performance metrics. If it's not enabled, the AWR report will still generate but with limited query-level statistics.

Building

Docker:

sh
docker build -t mochoa/mcp-mysql -f src/mysql/Dockerfile .

NPM:

sh
cd src/mysqlnpm installnpm run build

Demo Prompts

Sample prompts to try with the MySQL MCP server:

  • Connect to host.docker.internal:3306/mydb using root as user and password123 as password using mysql mcp server
  • Query all tables in the current database
  • Get stats for the users table
  • Explain the execution plan for: SELECT * FROM users WHERE email = '[email protected]'
  • Generate a performance report using mysql-awr
  • Based on the AWR report, what optimizations would you recommend?

Demos

See Demos for usage examples with Claude Desktop, Docker AI, Gemini CLI, and Antigravity Code Editor.

MySQL AWR in action

See MySQL AWR in action for an example of a performance report generated by the mysql-awr tool, highlighting specific optimization opportunities.

Change Log

See Change Log for the history of changes.

Sources

As usual, the code of this extension is at GitHub, feel free to suggest changes and make contributions.

📜 License

This project is licensed under the Apache License, Version 2.0 for new contributions, with existing code under MIT - see the LICENSE file for details.

来源:src/mysql/README.md,提交 bd2ce8f

工具

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

版本历史

1
  1. v1.0.7最新Sep 16, 2026

评分

已满足适用检查项的 40%

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

  • 近 30 天内可连通25 分

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

  • 已声明认证方式10 分

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

  • 已列出工具15 分

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

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

    请在仓库或注册中心条目中声明许可证。