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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mcp-universal-mysql

v1.0.0

Published

通用数据库 MCP 客户端

Readme

基于 MySQL 数据库的 MCP 智能分析服务

这是一个符合 Model Context Protocol (MCP) 标准的服务端实现。它允许 Claude Desktop、Trae 或其他 MCP 客户端安全地与 MySQL 数据库进行交互,执行查询表结构和只读 SQL 查询操作。

本服务可以直接连接到现有的 MySQL 数据库,帮助用户更好地理解和分析数据库内容。

✨ 主要特性

  • 数据库结构查询:快速获取数据库表结构信息,支持查询特定表或所有表的结构。
  • 只读 SQL 查询:安全地执行 SELECT 查询,保护数据库免受意外修改。
  • 灵活配置:通过环境变量轻松配置数据库连接参数。
  • 开箱即用:支持 npx 直接启动,无需复杂的本地环境配置。
  • 标准协议:完全兼容 MCP 协议,可无缝集成到 Claude Desktop 或其他 MCP 兼容平台。

🛠️ 前置要求

  1. Node.js:版本 >= 18.0.0。
  2. MySQL 数据库:需要有一个可访问的 MySQL 数据库实例。
  3. 数据库权限:建议使用只读权限的数据库用户以确保安全性。

🚀 快速开始 (安装与配置)

你可以选择通过 npx 运行(推荐)或 本地安装

方法一:通过 Claude Desktop 使用 (最简便)

直接修改 Claude Desktop 的配置文件,添加以下内容即可。

配置文件路径

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json

添加配置

JSON

{
  "mcpServers": {
    "mysql-analyst": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mysql-analyst"
      ],
      "env": {
        "DB_HOST": "127.0.0.1",
        "DB_PORT": "3306",
        "DB_USER": "your_readonly_user",
        "DB_PASSWORD": "your_password",
        "DB_NAME": "your_database_name"
      }
    }
  }
}

注意

  1. 请将数据库连接信息替换为实际的配置。
  2. 建议使用只读用户连接数据库以确保安全性。
  3. mcp-mysql-analyst 是 npm 包名,请确保与实际发布包名一致。

方法二:百宝箱/Trae 配置

在支持 MCP 的 IDE 或工具箱中,参考以下配置:

  • 运行命令 (Command): npx
  • 参数 (Args): ["-y", "mcp-mysql-analyst"]
  • 环境变量 (Environment Variables):
    • DB_HOST: 127.0.0.1 (可选,默认为 localhost)
    • DB_PORT: 3306 (可选,默认为 3306)
    • DB_USER: your_username (必填)
    • DB_PASSWORD: your_password (必填)
    • DB_NAME: your_database (必填)

方法三:本地开发/源码运行

如果你想克隆代码进行修改:

Bash

# 1. 克隆项目
git clone https://github.com/your-repo/mcp-mysql-analyst.git
cd mcp-mysql-analyst

# 2. 安装依赖
npm install

# 3. 构建项目
npm run build

# 4. 配置 MCP (指向本地构建文件)
# 在 config.json 中将 command 改为 "node",args 改为 ["/path/to/dist/index.js"]

# 5. 设置环境变量并运行
export DB_HOST=127.0.0.1
export DB_PORT=3306
export DB_USER=your_username
export DB_PASSWORD=your_password
export DB_NAME=your_database
node dist/index.js

🧰 工具列表 (Tools)

本服务提供以下两个核心工具供 AI 调用:

1. get_db_schema

获取数据库表结构信息。

  • 功能:查询数据库中表的结构信息,包括字段名、数据类型、是否为空等元数据。
  • 参数
    • table_name (选填, string): 表名,如果不提供则返回所有表的结构信息。

2. execute_sql

执行只读 SQL 查询。

  • 功能:安全地执行 SELECT 查询语句并返回结果。
  • 参数
    • query (必填, string): 要执行的 SELECT SQL 查询语句。
  • 安全机制
    • 仅允许执行 SELECT 语句
    • 内置防护措施防止 SQL 注入攻击
    • 使用只读数据库连接确保数据安全

🗣️ 使用示例

配置成功后,你可以直接对 Claude 或 IDE 助手说:

"查看一下用户表的结构"

"查询最近注册的10个用户"

"我想了解一下数据库里有哪些表以及它们的结构"

"统计一下每个城市有多少用户"

❓ 常见问题 (FAQ)

Q1: 如何确保数据库连接的安全性? A: 建议使用具有只读权限的数据库用户连接,并且仅授予必要的最小权限。同时,确保网络连接是安全的。

Q2: 为什么我只能执行 SELECT 查询? A: 为了保护数据库安全,此工具被设计为只允许执行 SELECT 查询。这是防止意外修改或删除数据的重要安全措施。

Q3: 工具支持哪些 MySQL 版本? A: 工具应该支持大多数 MySQL 版本(5.7及以上),因为它使用标准的 SQL 查询语法。

Q4: 查询结果的格式是什么样的? A: 查询结果会以 JSON 格式返回,便于 AI 助手解析和进一步处理。

📄 License

ISC License