mysql-mcp-server

MCP数据服务

提供方 minivv

数据服务 stdio · 本地进程 API Key 社区 / 第三方 Claude DesktopClaude
查看接入方式

A Model Context Protocol server that enables AI assistants to connect to and manage MySQL databases, offering SQL query execution, multi-connection management, SQL blacklist protection, and a web-based management UI, suitable for securely accessing and managing MySQL through natural language.

一句话选型结论

按资料字段整理

mysql-mcp-server 属于数据服务类 MCP 服务器,stdio · 本地进程,API Key,可直接接入 Claude Desktop、Claude,有可直接执行的安装命令。接入前先确认权限范围;涉及写入、删除或付款的操作,建议先在测试环境验证。

分类数据服务 传输方式stdio · 本地进程 鉴权API Key 部署方式本地部署
GitHub 星标 1 仓库热度,无公开仓库时显示未标注
工具数 未标注 暴露给模型的工具数量
资源 / 提示词 0 / 0 资源与提示词模板数量
维护方 社区 / 第三方 核验等级 仅资料核对

工具与能力

数据服务
数量来自来源目录的标注,具体工具清单以官方文档为准
工具数量未标注暴露给模型可调用的工具个数
资源数量0可读取的资源条目
提示词数量0内置提示词模板数量

能力标签

Local Deployment MySQL MCP Server JavaScript Database Management SQL Execution Connection Management SQL Blacklist Web Management UI AI Integration

支持客户端

适用场景

Local DeploymentMySQLMCP Server

安装与配置

stdio · 本地进程 API Key
客户端在本机拉起子进程,数据不出本机
node /path/to/mysql-mcp-server/build/index.js

这条命令只是入口,具体启动参数请按官方文档补齐,不要直接照搬到别的服务器。

  1. 1
    准备运行环境

    stdio 服务在本地起进程,需要先装好 node,再按安装命令拉取依赖。

  2. 2
    安装服务

    复制上面的安装命令执行;命令里带占位符的位置,换成自己的密钥或路径。

  3. 3
    写入客户端配置

    在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4
    验证是否可用

    连接成功后随便调一个只读工具,确认能返回结果,再接入正式流程。

典型使用场景

3 类
按分类与标签整理的常见用法,具体以官方文档为准
数据库查询

用自然语言查库、取数,不用手写 SQL。

数据同步与清洗

把多来源数据拉到一处做整理。

报表取数

按口径快速拉出统计结果。

选择建议

选之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 有现成的安装命令,不用自己找入口,照着跑就能起服务。
  • 已适配 Claude Desktop、Claude,换客户端不用重新研究配置。

先想清楚的地方

  • stdio 方式要求本地装好运行时(如 Node.js),换机器要重新装一遍。
  • 使用前要准备好API Key对应的凭据,并按最小权限配置。
  • 资料没标注工具数量,实际能力要装好后确认。
  • 版本更新与行为细节以官方仓库为准。

更适合

  • 需要在数据服务场景里让模型直接调用外部能力的人。
  • 已经在用 Claude Desktop、Claude 的用户,接入路径最短。
  • 想先快速试一下、能接受在本地或自有环境跑服务的人。

不太适合

  • 完全不想在本地装环境的人。
  • 不方便管理密钥或第三方授权的人。
  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
MCP 服务器工具数传输方式部署方式安装命令最后核验
mysql-mcp-server当前 未标注 stdio · 本地进程 本地部署 有 2026-06-30
Memory 9d25f64e 9 未标注 未标注 无 2026-05-17
Getzep MCP 9 stdio · 本地进程 本地部署 有 2026-05-17
anything-llm 未标注 stdio · 本地进程 本地部署 有 2026-04-11
Prisma MCP Server 未标注 stdio · 本地进程 本地部署 有 2026-05-17
Astr Bot 未标注 stdio · 本地进程 本地部署 有 2026-05-17

服务器档案

数据服务
字段来自项目仓库与公开索引,中文说明由本站标注
提供方minivv上游标注的维护方 minivv
分类数据服务本站按上游分类展示
连接方式stdio · 本地进程客户端在本机拉起子进程,数据不出本机
鉴权方式API Key远程服务建议用最小权限凭据
维护方社区 / 第三方核验等级 仅资料核对
包名 / 运行时未标注 · node本地安装时用到的包标识与运行时
部署类型本地部署上游给出的部署形态
最近核验2026-06-30上游最后核验时间

详细介绍

13.2 KB
来自项目仓库与上游目录的原文,未做删改

MySQL MCP Server

> A MySQL tool layer for AI agents that knows which database it is talking to: per-connection test/prod tagging, fine-grained write permissions, SSH tunnels for intranet databases, and a visual web console.

English · 中文


English

Why This Server?

Every statement an agent runs happens somewhere specific — a database it is free to break, or the one real users depend on. This server makes that context part of the protocol:

  1. Where am I? Every connection carries a test or prod tag, and every tool response reports it.
  2. What am I allowed to do here? Five permission switches per tag, enforced before the statement ever reaches MySQL.
  3. How do I reach a database that only exists inside a private network? A managed SSH tunnel.

The parts that do not belong in a chat — connection management, permission templates, and a live view of what the server exposes — live in a web console.

Features

  • Four focused tools — run_sql_query, execute_sql, inspect, switch_database, each with a single clear job
  • Environment tagging — every connection is test or prod; permissions are bound to the tag, not the connection
  • 5 granular write switches — Basic DDL / Advanced DDL (DROP, TRUNCATE) / INSERT / UPDATE / DELETE. prod defaults to read-only
  • Self-describing results — every tool response carries env, envLabel, readOnly, allowedWrites, so the model never has to guess
  • SSH tunnels — reach intranet MySQL through a jump host; key file + optional passphrase, managed by the server
  • Web console — three tabs: connections, permissions, tools & policy
  • Hot switching — change the active connection in the UI; running MCP sessions follow automatically, no restart
  • Encrypted at rest — passwords and SSH passphrases use AES-256-GCM

Quick Start```bash

git clone https://github.com/minivv/mysql-mcp-server.git
cd mysql-mcp-server
npm install
npm run build


Start it once so the web console opens at , add a connection, tag it, and click **Use**.

### MCP Client Configuration```json
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["/path/to/mysql-mcp-server/build/index.js"],
      "env": {
        "MCP_OPEN_BROWSER": "false"
      }
    }
  }
}

Claude Desktop config lives at ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows).

Tools

Tool Arguments Description
run_sql_query query, max_rows? Read-only SQL (SELECT / SHOW / DESCRIBE / EXPLAIN / read-only WITH). Allowed in every environment. Truncates at max_rows (default 500).
execute_sql query Write SQL (INSERT / UPDATE / DELETE / DDL). Gated by the environment tag and its permission template; a rejection explains which rule fired.
inspect database?, table? No arguments → databases + tables of the current database. database → its tables. table → table structure.
switch_database database Switch the current database. Does not change the test/prod tag.

Example response:```json
{
"env": "prod",
"envLabel": "正式库",
"readOnly": true,
"allowedWrites": [],
"rowCount": 1,
"rows": [{ "cnt": 42 }]
}


### Web UI

- **Connections** — add / edit / delete / test connections, tag as test or prod, filter the list, enable an SSH tunnel, one-click switch
- **Permissions** — five switches per tag (`test`, `prod`). Change a template once and every connection with that tag follows
- **Tools & Policy** — the live tool list with argument hints, the effective policy of the active connection, and the statement-classification rules

### Environment Permissions

Permissions are bound to the **tag**, not to individual connections.

| Operation | Statements | Default `test` | Default `prod` |
|-----------|------------|:--------------:|:--------------:|
| Basic DDL | CREATE / RENAME / ALTER without DROP | ✅ | ❌ |
| Advanced DDL | DROP / TRUNCATE / ALTER … DROP | ✅ | ❌ |
| INSERT | INSERT / REPLACE | ✅ | ❌ |
| UPDATE | UPDATE | ✅ | ❌ |
| DELETE | DELETE | ✅ | ❌ |
| Read | SELECT / SHOW / DESCRIBE / EXPLAIN / read-only WITH | ✅ | ✅ |

Statements are normalised before classification: leading `--`, `/* */` and `#` comments are stripped, and `WITH … DELETE` is recognised as a write — so `/* x */ DELETE …` does not slip through. Anything that cannot be classified is treated as **advanced DDL**, the strictest bucket.

### SSH Tunnels

For databases that only the jump host can see, enable **SSH tunnel** on the connection. The server spawns `ssh -N -L` itself and reuses the tunnel for the lifetime of the connection pool.

- **SSH host** — an alias from `~/.ssh/config` (e.g. `ssh66`), or an explicit host/user pair
- **Key file / passphrase** — optional; the passphrase is stored encrypted and fed to `ssh` through an ephemeral `SSH_ASKPASS` helper
- The connection's **host / port** then mean *"where MySQL listens as seen from the jump host"* (usually `127.0.0.1:3306`)
- Without a passphrase, auth runs in `BatchMode=yes`; configure passwordless key auth first
- The local forwarding port is picked automatically from `13306` upwards
- Tunnels are closed on connection switch / delete and on `SIGINT` / `SIGTERM````bash
# Pre-check: key auth must work without prompting
ssh -o BatchMode=yes <ssh-alias> echo OK

Configuration Files

Everything lives in ~/.mysql-mcp/:

File Contents
connections.json Saved connections, active connection, environment tags, SSH settings
permissions.json The two permission templates (test, prod)
.key AES-256-GCM key for passwords and passphrases (mode 0600)

Environment Variables```bash

MCP_WEB_PORT=3456 # Web console port (default 3456)
MCP_OPEN_BROWSER=false # Do not auto-open the browser
MCP_WEB_UI=false # Do not start the web console at all

Legacy fallback, used only when no connection has been activated in the UI

MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=secret
MYSQL_DATABASE=app
MYSQL_ENV=prod # test | prod, default prod


### Security

- Passwords and SSH passphrases are encrypted with AES-256-GCM; keys are written with mode `0600`
- `multipleStatements` is disabled — one query argument cannot smuggle a second statement
- Selections are capped by `max_rows` (default 500)
- The permission switches are a **guardrail, not a security boundary**. The real boundary is a least-privilege MySQL account per environment — use one.

### Development```bash
npm install
npm run build     # tsc → build/
node build/index.js

Source layout: src/index.ts (MCP server, web API, SSH tunnels) and src/web-ui.ts (the console page, shipped as a single HTML string).

License

MIT


中文

为什么用它

agent 执行的每一条 SQL 都发生在具体的某个地方——它可以随便搞坏的库,或者真实用户正在用的那个库。这个服务把「在哪儿」变成协议的一部分:

  1. 我在哪? 每个连接带 test / prod 标识,每次工具返回都会报出当前所处环境。
  2. 这里允许我做什么? 每个标识五项权限开关,在语句到达 MySQL 之前就拦下。
  3. 只能内网访问的库怎么连? 服务端托管的 SSH 隧道。

不适合塞进对话里的东西——连接管理、权限模板、当前到底暴露了什么——都放在 Web 控制台里。

功能特性

  • 四个聚焦的工具 —— run_sql_query、execute_sql、inspect、switch_database,每个只干一件事
  • 库环境标识 —— 每个连接标记为 test 或 prod,权限绑在标识上而不是单个连接上
  • 5 项细粒度写开关 —— 基础 DDL / 高级 DDL(DROP、TRUNCATE)/ INSERT / UPDATE / DELETE;正式库默认只读
  • 返回值自描述 —— 每次调用都带 env、envLabel、readOnly、allowedWrites,模型不用猜
  • SSH 隧道 —— 通过跳板机访问内网 MySQL,支持密钥文件与口令,隧道由服务端托管
  • Web 控制台 —— 连接管理、权限配置、工具与策略三个标签页
  • 热切换连接 —— 在界面里换连接,正在运行的 MCP 会话自动跟随,不用重启
  • 密码加密存储 —— 数据库密码与 SSH 口令均为 AES-256-GCM 加密

快速开始```bash

git clone https://github.com/minivv/mysql-mcp-server.git
cd mysql-mcp-server
npm install
npm run build


先启动一次,浏览器会打开 ,添加连接、选择标识,点**使用**。

### MCP 客户端配置```json
{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["/path/to/mysql-mcp-server/build/index.js"],
      "env": {
        "MCP_OPEN_BROWSER": "false"
      }
    }
  }
}

Claude Desktop 的配置位置:macOS 是 ~/Library/Application Support/Claude/claude_desktop_config.json,Windows 是 %APPDATA%\Claude\claude_desktop_config.json。

工具清单

工具 参数 说明
run_sql_query query、max_rows? 只读 SQL(SELECT / SHOW / DESCRIBE / EXPLAIN / 只读 WITH),任何环境都放行。超过 max_rows(默认 500)会被截断
execute_sql query 写操作 SQL(INSERT / UPDATE / DELETE / DDL)。是否放行由连接的库环境标识及其权限模板决定,被拦截时会说明命中了哪条规则
inspect database?、table? 不带参数返回库列表 + 当前库的表;传 database 返回该库的表;传 table 返回表结构
switch_database database 切换当前数据库,不会改变测试库/正式库标识

返回示例:```json
{
"env": "test",
"envLabel": "测试库",
"readOnly": false,
"allowedWrites": ["basicDdl", "advancedDdl", "insert", "update", "delete"],
"rowCount": 1,
"rows": [{ "cnt": 42 }]
}


### Web 控制台

- **连接管理** —— 新增 / 编辑 / 删除 / 测试连接,标记测试库或正式库,按标识筛选,可选 SSH 隧道,一键切换
- **权限配置** —— 按标识(`test`、`prod`)各 5 个开关,改一次即对该标识下所有连接生效
- **工具与策略** —— 实时展示对外暴露的工具与参数、当前连接的生效策略、语句归类与兜底规则

### 库环境权限

权限绑在**标识**上,而不是单个连接上。

| 操作 | 对应语句 | 测试库默认 | 正式库默认 |
|------|----------|:----------:|:----------:|
| 基础 DDL | CREATE / RENAME / 不含 DROP 的 ALTER | ✅ | ❌ |
| 高级 DDL | DROP / TRUNCATE / ALTER … DROP | ✅ | ❌ |
| INSERT | INSERT / REPLACE | ✅ | ❌ |
| UPDATE | UPDATE | ✅ | ❌ |
| DELETE | DELETE | ✅ | ❌ |
| 只读 | SELECT / SHOW / DESCRIBE / EXPLAIN / 只读 WITH | ✅ | ✅ |

判断前会先做归一化:剔除开头的 `--`、`/* */`、`#` 注释,识别 `WITH … DELETE` 这类型写语句,所以 `/* x */ DELETE …` 绕不过去。无法识别的语句一律按**高级 DDL** 处理(最严格的一档)。

### SSH 隧道

如果 MySQL 只能从跳板机访问,在连接上勾选 **SSH 隧道**。服务端会自己拉起 `ssh -N -L`,并在连接池生命周期内复用该隧道。

- **SSH 主机** —— `~/.ssh/config` 里的别名(如 `ssh66`),或直接填主机 / 用户
- **密钥文件 / 口令** —— 可选;口令加密存储,通过临时 `SSH_ASKPASS` 脚本交给 `ssh`
- 连接里的 **主机 / 端口** 此时表示「从跳板机看到的 MySQL 地址」(通常 `127.0.0.1:3306`)
- 未填口令时走 `BatchMode=yes`,请先配好免密登录
- 本地转发端口从 `13306` 起自动挑选
- 切换连接、删除连接、收到 `SIGINT` / `SIGTERM` 时自动关闭隧道```bash
# 前置检查:密钥认证必须免密可用
ssh -o BatchMode=yes <ssh别名> echo OK

配置文件

所有状态都在 ~/.mysql-mcp/ 下:

文件 内容
connections.json 已保存的连接、当前激活连接、环境标识、SSH 配置
permissions.json 两套权限模板(test、prod)
.key 用于加密密码与 SSH 口令的 AES-256-GCM 密钥(权限 0600)

环境变量```bash

MCP_WEB_PORT=3456 # Web 控制台端口,默认 3456
MCP_OPEN_BROWSER=false # 不自动打开浏览器
MCP_WEB_UI=false # 完全不启动 Web 控制台

兼容旧版的兜底连接,仅在界面上没有激活任何连接时生效

MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=secret
MYSQL_DATABASE=app
MYSQL_ENV=prod # test | prod,默认 prod


### 安全性

- 数据库密码与 SSH 口令使用 AES-256-GCM 加密,密钥文件权限 `0600`
- 关闭了 `multipleStatements`,一个 `query` 参数里塞不进第二条语句
- 查询结果按 `max_rows`(默认 500 行)截断
- 权限开关是**护栏,不是安全边界**。真正的边界是按环境区分的最小权限 MySQL 账号——请务必这样用

### 开发```bash
npm install
npm run build     # tsc → build/
node build/index.js

源码结构:src/index.ts(MCP 服务、Web API、SSH 隧道)与 src/web-ui.ts(控制台页面,以单个 HTML 字符串形式输出)。

许可证

MIT

常见问题

8 问
答案由本站依据条目字段整理,不引用上游原文
mysql-mcp-server 怎么安装?

在客户端按下面的安装命令接入:node /path/to/mysql-mcp-server/build/index.js。装完在客户端配置里引用同一个包或端点。

mysql-mcp-server 怎么在 Claude Desktop、Claude 里配置?

它的传输方式是stdio · 本地进程,在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,配置才会生效。

mysql-mcp-server 收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

mysql-mcp-server 需要 API Key 吗?

资料标注需要API Key认证,使用前准备好对应凭据,并按最小权限配置。

mysql-mcp-server 支持哪些客户端?

资料标注支持 Claude Desktop、Claude;其他客户端只要能配置 MCP Server,也能用同样的命令或地址接入。

mysql-mcp-server 能提供哪些能力?

资料显示能力标签包括 Local Deployment、MySQL、MCP Server、JavaScript、Database Management、SQL Execution。具体工具清单以官方文档为准。

mysql-mcp-server 需要什么运行环境?

运行时为 node;属于本地进程,需要在本机装好运行环境。

mysql-mcp-server 是本地还是远程?

它是本地进程(stdio),由客户端在本机拉起。传输方式为stdio · 本地进程。

热门专题

按标签挑服务器
全部专题 →

服务器信息以作者仓库与官方文档为准;分类、传输方式与鉴权方式的中文说明为中文整理,最近核验 2026-06-30。