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

@johnson.lee/mysql-mcp-server

v0.0.2-8

Published

MySQL MCP Server - Model Context Protocol server for MySQL databases

Downloads

88

Readme


MySQL MCP Server

基於 NestJS 和 MCP-Nest 建構的 MySQL Model Context Protocol (MCP) 伺服器。讓 AI 助理(如 Claude 和 Cursor)透過標準化協定與 MySQL 資料庫互動。

English · 繁體中文


概述

MySQL MCP Server 將 MySQL 資料庫操作暴露為 MCP 工具,讓 AI 助理能夠:

  • 查詢和探索資料庫結構
  • 執行帶有權限控制的 SQL 查詢
  • 列出表格、描述表格結構和瀏覽資料庫
  • 支援多種傳輸模式(stdio、HTTP SSE、Streamable HTTP)

功能特點

| | 說明 | | ---------------- | ---------------------------------------------------------------- | | 連線池 | 高效的 MySQL 連線管理,可設定連線池大小 | | 權限控制 | 細粒度的 SQL 操作權限管理(SELECT、INSERT、UPDATE、DELETE、DDL) | | DRY_RUN 模式 | 驗證 SQL 查詢但不返回實際資料 | | MCP 工具 | 透過 Model Context Protocol 暴露標準化的資料庫操作 | | 優雅關閉 | 程序終止時完善清理資源 | | 檔案日誌 | 可設定的日誌輸出,支援輪轉 |

環境需求

  • Node.js 18+
  • MySQL 5.7+ 資料庫
  • npm 或 pnpm 套件管理器

安裝

# 全域安裝(推薦)
npm install -g @johnson.lee/mysql-mcp-server

# 或使用 npx
npx @johnson.lee/mysql-mcp-server

快速開始

# 設定環境變數
export DB_HOST=localhost
export DB_PORT=3306
export DB_USER=root
export DB_PASSWORD=your_password
export DB_NAME=your_database

# 啟動伺服器
mysql-mcp

設定

透過環境變數設定:

資料庫連線

| 變數 | 預設值 | 說明 | | ------------- | --------- | ------------ | | DB_HOST | localhost | MySQL 主機 | | DB_PORT | 3306 | MySQL 連接埠 | | DB_USER | root | MySQL 使用者 | | DB_PASSWORD | - | MySQL 密碼 | | DB_NAME | test_db | 資料庫名稱 | | DB_POOL_MIN | 2 | 最小連線數 | | DB_POOL_MAX | 10 | 最大連線數 |

權限控制

| 變數 | 預設值 | 說明 | | -------------- | ------ | ------------------------------- | | ALLOW_SELECT | true | 允許 SELECT 查詢 | | ALLOW_VIEW | true | 允許 SHOW / DESCRIBE | | ALLOW_INSERT | false | 允許 INSERT | | ALLOW_UPDATE | false | 允許 UPDATE | | ALLOW_DELETE | false | 允許 DELETE | | ALLOW_DDL | false | 允許 CREATE/ALTER/DROP/TRUNCATE |

伺服器選項

| 變數 | 預設值 | 說明 | | --------------- | ------ | ---------------------------------------- | | MCP_TRANSPORT | stdio | 傳輸模式:stdio/http-sse/streamable-http | | LOG_LEVEL | info | 日誌等級:debug/info/warn/error | | LOG_DIR | ./logs | 日誌目錄 | | DRY_RUN | false | 驗證 SQL 但不返回資料 |

編輯器整合

Claude Desktop

編輯 ~/.config/claude/claude_desktop_config.json

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["@johnson.lee/mysql-mcp-server"],
      "env": {
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_PASSWORD": "your_password",
        "DB_NAME": "your_database"
      }
    }
  }
}

Cursor

建立 .cursor/mcp.json

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["@johnson.lee/mysql-mcp-server"],
      "env": {
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_PASSWORD": "your_password",
        "DB_NAME": "your_database"
      }
    }
  }
}

可用工具

list_tables

列出目前資料庫的所有表格。

describe_table

取得表格結構(欄位、型別、主鍵等)。

{
  "name": "describe_table",
  "arguments": { "tableName": "users" }
}

execute_query

執行 SQL 查詢。

{
  "name": "execute_query",
  "arguments": { "sql": "SELECT * FROM users LIMIT 10" }
}

list_databases

列出 MySQL 伺服器上所有可用的資料庫。


NestJSMCP-Nest 建構