npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@morris131/mysql-mcp-server

v1.0.5

Published

MySQL MCP Server - stdio protocol for MySQL database operations with Windows support

Readme

MySQL MCP Server

基于模型上下文协议(MCP)的 MySQL 数据库操作服务器,支持单数据库多数据库两种模式。

特性

  • 智能模式 - 根据配置自动切换单数据库/多数据库模式
  • 执行 SQL 查询 - 支持 SELECT、INSERT、UPDATE、DELETE 等操作
  • 列出数据库 - 查看所有可用数据库(仅多数据库模式)
  • 列出表 - 查看指定数据库中的所有表
  • 描述表结构 - 获取表的详细结构信息
  • 连接超时 - 可配置连接超时时间(默认 10 秒)
  • 自动重试 - 连接错误时自动重试(默认 2 次)
  • 保活机制 - TCP Keep-Alive 防止连接断开
  • 安全 - 基于环境变量配置,无硬编码凭据
  • 高性能 - 基于 TypeScript 和连接池构建

配置

服务器通过环境变量进行数据库配置:

| 环境变量 | 说明 | 默认值 | | :--- | :--- | :--- | | DB_HOST | MySQL 主机地址 | 127.0.0.1 | | DB_USER | MySQL 用户名 | root | | DB_PASSWORD | MySQL 密码 | 空 | | DB_PORT | MySQL 端口 | 3306 | | DB_NAME | 数据库名称(可选,详见下方模式说明) | 空 | | DB_CONNECTION_LIMIT | 连接池大小 | 3 | | DB_CONNECTION_TIMEOUT | 连接超时时间(毫秒) | 10000(10秒) | | DB_KEEP_ALIVE_DELAY | TCP Keep-Alive 延迟(毫秒) | 30000(30秒) | | DB_MAX_RETRIES | 最大重试次数 | 2 | | DB_RETRY_DELAY | 重试间隔(毫秒) | 1000(1秒) |

模式说明

单数据库模式(配置了 DB_NAME)

当设置了 DB_NAME 时,服务器以单数据库模式运行:

  • execute_sql 只需 sql 参数
  • list_tables 无需参数
  • describe_table 只需 table 参数
  • list_databases 工具不可用

多数据库模式(未配置 DB_NAME)

当未设置 DB_NAME 时,服务器以多数据库模式运行:

  • execute_sql 需要同时提供 databasesql 参数
  • list_tables 需要提供 database 参数
  • describe_table 需要同时提供 databasetable 参数
  • list_databases 工具可用

使用方式

OpenCode 配置

在 MCP 配置中添加:

{
  "mcp": {
    "mysql": {
      "type": "local",
      "command": [
        "npx",
        "-y",
        "@morris131/mysql-mcp-server"
      ],
      "environment": {
        "DB_HOST": "your_mysql_host",
        "DB_PORT": "3306",
        "DB_USER": "your_username",
        "DB_PASSWORD": "your_password",
        "DB_NAME": "your_database"
      }
    }
  }
}

请将凭据替换为实际值。

Claude Code 配置

运行以下命令添加 MCP 服务器:

claude mcp add mysql -e DB_HOST=localhost -e DB_USER=your_username -e DB_PASSWORD=your_password -e DB_PORT=3306 -- npx -y @morris131/mysql-mcp-server

可用工具

单数据库模式

execute_sql

执行 MySQL 查询。

参数:

  • sql(必填):要执行的 SQL 语句

示例:

{
  "sql": "SELECT * FROM users WHERE id = ?"
}

list_tables

列出已配置数据库中的所有表。

参数:

示例: {}

describe_table

获取表结构的详细信息。

参数:

  • table(必填):表名

示例:

{
  "table": "users"
}

多数据库模式

list_databases

列出 MySQL 服务器上所有可用的数据库。

参数:

示例: {}

execute_sql

在指定数据库上执行 MySQL 查询。

参数:

  • database(必填):数据库名
  • sql(必填):要执行的 SQL 语句

示例:

{
  "database": "testdb",
  "sql": "SELECT * FROM users WHERE id = ?"
}

list_tables

列出指定数据库中的所有表。

参数:

  • database(必填):数据库名

示例:

{
  "database": "testdb"
}

describe_table

获取表结构的详细信息。

参数:

  • database(必填):数据库名
  • table(必填):表名

示例:

{
  "database": "testdb",
  "table": "users"
}