M

MySQL智能服务

此服务器通过标准化接口使人工智能模型能够与MySQL数据库进行交互。

databases

1.7w 查看 · 2026-07-07 更新

简介

此服务器通过标准化接口使人工智能模型能够与MySQL数据库进行交互。

简介

此服务器通过标准化接口使人工智能模型能够与MySQL数据库进行交互。

@f4ww4z/mcp-mysql-server

smithery badge

一个提供 MySQL 数据库操作的 Model Context Protocol 服务器。该服务器通过标准化接口使 AI 模型能够与 MySQL 数据库进行交互。

mcp-mysql-server MCP server

安装

通过 Smithery 安装

要通过 Smithery 自动为 Claude Desktop 安装 MySQL 服务器:

npx -y @smithery/cli install @f4ww4z/mcp-mysql-server --client claude

手动安装

npx @f4ww4z/mcp-mysql-server

配置

服务器需要在您的 MCP 设置配置文件中设置以下环境变量:

{ "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z/mcp-mysql-server"], "env": { "MYSQL_HOST": "your_host", "MYSQL_USER": "your_user", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } }

可用工具

1. connect_db

使用提供的凭据建立到 MySQL 数据库的连接。

use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { host: "localhost", user: "your_user", password: "your_password", database: "your_database" } });

2. query

执行带有可选预处理语句参数的 SELECT 查询。

use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT * FROM users WHERE id = ?", params: [1] } });

3. execute

执行带有可选预处理语句参数的 INSERT、UPDATE 或 DELETE 查询。

use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "INSERT INTO users (name, email) VALUES (?, ?)", params: ["John Doe", "john@example.com"] } });

4. list_tables

列出已连接数据库中的所有表。

use_mcp_tool({ server_name: "mysql", tool_name: "list_tables", arguments: {} });

5. describe_table

获取特定表的结构。

use_mcp_tool({ server_name: "mysql", tool_name: "describe_table", arguments: { table: "users" } });

特性

  • 安全连接处理,支持自动清理
  • 支持查询参数的预处理语句
  • 全面的错误处理和验证
  • 支持 TypeScript
  • 自动连接管理

安全性

  • 使用预处理语句防止 SQL 注入
  • 通过环境变量支持安全密码处理
  • 在执行前验证查询
  • 在完成后自动关闭连接

错误处理

服务器为常见问题提供了详细的错误信息:

  • 连接失败
  • 无效查询
  • 缺少参数
  • 数据库错误

贡献

欢迎贡献!请随时提交 Pull Request 到 https://github.com/f4ww4z/mcp-mysql-server

许可证

MIT

工具列表

  • connect_db: Connect to MySQL database

  • query: Execute a SELECT query

  • execute: Execute an INSERT, UPDATE, or DELETE query

  • list_tables: List all tables in the database

  • describe_table: Get table structure

服务配置

[{'mcpServers': {'mysql': {'args': ['-y', '@f4ww4z/mcp-mysql-server'], 'command': 'npx', 'env': {'MYSQL_DATABASE': 'your_database', 'MYSQL_HOST': 'your_host', 'MYSQL_PASSWORD': 'your_password', 'MYSQL_USER': 'your_user'}}}}]

来源