MySQL MCP Server

io.github.musaddiq-dev由 GitHub 帳號 musaddiq-dev 發布v0.1.2更新於 Nov 3, 2026

Python MCP server for MySQL database inspection and querying

已驗證STDIO僅桌面資料庫資料與分析

概覽

AI 產生的概覽

在本機執行的 Python MCP 伺服器,讓助理檢視與查詢 MySQL 資料庫:列出資料表、查看結構、執行受限 SELECT 與解讀執行計畫。

可以做什麼
  • 列出資料表並檢視資料表結構
  • 執行單一受限 SELECT 查詢,具備關鍵字與筆數上限保護
  • 取得 SHOW CREATE TABLE 輸出與 EXPLAIN 執行計畫
  • 彙總資料表清單與資料列數
  • 啟用寫入工具時可執行 INSERT、UPDATE、DELETE 及 DDL 語句
適用情境
適合在 Claude Desktop、Cursor、VS Code 等 MCP 用戶端中,讓助理探索或查詢 MySQL 資料庫,例如查看資料表結構、臨時唯讀查詢或分析執行計畫。只有在能提供資料庫連線、最好使用唯讀帳號時才建議安裝。
執行需求
透過 uvx(套件名稱 mdev-mysql-mcp-server)或原始碼在本機以 stdio 執行;需要 Python 3.11+ 與 MySQL 5.7+/8.0+。需設定 MYSQL_DATABASE(必填)以及 MYSQL_HOST、MYSQL_PORT、MYSQL_USER、MYSQL_PASSWORD、MYSQL_POOL_SIZE、MYSQL_READ_QUERY_LIMIT、LOG_LEVEL,並能連線到 MySQL 主機。
安裝前請注意
用戶端設定中會保存資料庫憑證(MYSQL_PASSWORD),請勿提交到版本控制。唯讀查詢的限制不能取代資料庫權限,應使用最小權限的唯讀帳號。寫入與 DDL 工具可能修改或刪除資料,應保持手動核准。不要在沒有額外驗證與傳輸加密的情況下,把此伺服器暴露到不受信任的網路。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 MySQL MCP Server,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

MySQL MCP Server

A Python Model Context Protocol (MCP) server for inspecting and querying MySQL databases from MCP-compatible clients. It provides table discovery, schema inspection, read query execution, DDL lookup, query explanation, and optional write/DDL tools for controlled database administration workflows.

Features

  • List tables and describe table schemas
  • Execute SELECT queries with safety checks
  • Retrieve SHOW CREATE TABLE output
  • Explain query execution plans
  • Summarize tables and row counts
  • Optional write and DDL tools for users who intentionally run with elevated database privileges

Safety Model

mysql_execute_read_query only accepts a single statement beginning with SELECT, rejects common modifying SQL keywords and risky file-read/write forms, and caps returned rows by MYSQL_READ_QUERY_LIMIT. This is a guardrail, not a substitute for database permissions. Use a dedicated read-only MySQL user for safe exploration. The write and DDL tools can modify or destroy data if the configured database user is allowed to do so; keep them on manual approval in your MCP client.

Requirements

  • Python 3.11+
  • MySQL 5.7+ or MySQL 8.0+
  • MCP-compatible client such as Claude Desktop, Cursor, VS Code, or another MCP host

Installation

When published to PyPI, install or run the server like a standard Python MCP package:

bash
uvx mdev-mysql-mcp-server

For local development from source:

bash
git clone https://github.com/musaddiq-dev/mysql-mcp-server.gitcd mysql-mcp-serverpython -m venv .venvsource .venv/bin/activatepip install -e .

Configuration

Copy the example environment file and update it with your database connection details.

bash
cp .env.example .env
VariableDescriptionRequiredDefault
MYSQL_HOSTMySQL hostNolocalhost
MYSQL_PORTMySQL portNo3306
MYSQL_USERMySQL usernameNoroot
MYSQL_PASSWORDMySQL passwordNoEmpty
MYSQL_DATABASEMySQL database nameYesEmpty
MYSQL_POOL_SIZEConnection pool sizeNo5
LOG_LEVELPython logging levelNoINFO
MYSQL_READ_QUERY_LIMITMaximum rows returned by read queriesNo1000

Example read-only user:

sql
CREATE USER 'mcp_readonly'@'localhost' IDENTIFIED BY 'change-me';GRANT SELECT ON your_database.* TO 'mcp_readonly'@'localhost';FLUSH PRIVILEGES;

Running

bash
mdev-mysql-mcp-server

From a local checkout before PyPI publication, run:

bash
python -m mysql_mcp_server.server

MCP Client Configuration

For published installs, prefer uvx. MCP servers using stdio must write protocol messages only to stdout; this server writes logs to stderr through Python logging.

Claude Desktop / Cursor / Windsurf / Cline

Most MCP clients accept this mcpServers JSON shape:

json
{  "mcpServers": {    "mysql": {      "command": "uvx",      "args": ["mdev-mysql-mcp-server"],      "env": {        "MYSQL_HOST": "localhost",        "MYSQL_PORT": "3306",        "MYSQL_USER": "mcp_readonly",        "MYSQL_PASSWORD": "change-me",        "MYSQL_DATABASE": "your_database"      }    }  }}

For local development from this repository, use the installed console script path instead:

json
{  "mcpServers": {    "mysql": {      "command": "/absolute/path/to/mysql-mcp-server/.venv/bin/mdev-mysql-mcp-server",      "args": [],      "env": {        "MYSQL_HOST": "localhost",        "MYSQL_PORT": "3306",        "MYSQL_USER": "mcp_readonly",        "MYSQL_PASSWORD": "change-me",        "MYSQL_DATABASE": "your_database"      }    }  }}

Claude Code CLI

bash
claude mcp add mysql \  --env MYSQL_HOST=localhost \  --env MYSQL_PORT=3306 \  --env MYSQL_USER=mcp_readonly \  --env MYSQL_PASSWORD=change-me \  --env MYSQL_DATABASE=your_database \  -- uvx mdev-mysql-mcp-server

VS Code MCP

VS Code uses the same command/args/env model in its MCP configuration:

json
{  "servers": {    "mysql": {      "type": "stdio",      "command": "uvx",      "args": ["mdev-mysql-mcp-server"],      "env": {        "MYSQL_HOST": "localhost",        "MYSQL_PORT": "3306",        "MYSQL_USER": "mcp_readonly",        "MYSQL_PASSWORD": "change-me",        "MYSQL_DATABASE": "your_database"      }    }  }}

Tools

ToolPurposeSafety
mysql_list_tablesList tables in the configured databaseRead-only
mysql_describe_tableShow schema for a tableRead-only
mysql_execute_read_queryExecute a single bounded SELECT queryRead-only guardrail
mysql_execute_write_queryExecute a single INSERT, UPDATE, or DELETEDestructive
mysql_execute_ddlExecute a single CREATE, DROP, ALTER, or TRUNCATEDestructive
mysql_get_table_ddlReturn SHOW CREATE TABLE outputRead-only
mysql_explain_queryRun EXPLAIN for a single queryRead-only
mysql_get_database_summaryReturn table list and row countsRead-only

Smoke Check

Without a database, verify syntax with:

bash
python -m py_compile src/mysql_mcp_server/server.py

With a configured database, start the server and use your MCP client to call list_tables.

Distribution

This server is published through the standard Python MCP distribution path:

  • PyPI package: mdev-mysql-mcp-server
  • MCP Registry name: io.github.musaddiq-dev/mysql-mcp-server
  • Runtime hint: uvx
  • Transport: stdio

The mcp-name marker at the top of this README is required for MCP Registry ownership verification. Users should prefer uvx mdev-mysql-mcp-server in local MCP client configurations.

Security Notes

  • Do not commit .env or MCP client configs containing credentials.
  • Use least-privilege database users.
  • Keep execute_write_query and execute_ddl on explicit manual approval.
  • Do not expose this server over an untrusted network without additional authentication and transport security.

License

MIT

來源:README.md,提交 be66e02

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.2最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分