mysql-mcp-tool
Enables AI models to interact with MySQL databases through MCP protocol, supporting queries, table schema inspection, and data manipulation operations.
README
MySQL MCP 工具
针对MySQL数据库操作的MCP(Model Context Protocol)工具实现,为AI模型提供数据库操作能力。
- 推荐使用本地模型使用这个工具,防止出现不必要的数据泄露风险
功能特性
- MySQL数据库连接管理
- 表结构查询
- 数据增删改查操作
- 错误处理和连接状态管理
- MCP协议支持,可与AI模型集成
安装
npm install
使用方法
作为MCP服务器
将以下配置添加到你的MCP客户端配置文件中:
{
"mcpServers": {
"mysql-mcp-tool": {
"command": "npx",
"args": ["mysql-mcp-tool", "server"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "",
"MYSQL_DATABASE": "test"
}
}
}
}
命令行使用
# 查询表
mysql-mcp-tool tables
# 查看表结构
mysql-mcp-tool schema users
# 执行SQL
mysql-mcp-tool query "SELECT * FROM users WHERE id = ?" -p '["1"]'
# 启动MCP服务器
mysql-mcp-tool server -h localhost -u root -p password -d mydb
编程使用
import MySQLMCPTool from './index.js';
const tool = new MySQLMCPTool({
host: 'localhost',
user: 'root',
password: '',
database: 'test'
});
await tool.connect();
const result = await tool.select('users', { id: 1 });
await tool.disconnect();
API文档
基础方法
connect()- 连接数据库disconnect()- 断开连接executeQuery(sql, params)- 执行SQL查询
数据操作
getTables()- 获取所有表getTableSchema(tableName)- 获取表结构select(tableName, where, limit)- 查询数据insert(tableName, data)- 插入数据update(tableName, data, where)- 更新数据delete(tableName, where)- 删除数据
MCP工具
该工具提供以下MCP工具:
-
mysql_query - 执行MySQL查询
- 参数:sql(必需),params(可选)
-
mysql_tables - 获取所有表
- 参数:无
-
mysql_schema - 获取表结构
- 参数:table(必需)
-
mysql_insert - ⚠️ 警告:插入数据 - 使用者自负责任
- 参数:table(必需),data(必需)
-
mysql_update - ⚠️ 警告:更新数据 - 使用者自负责任
- 参数:table(必需),data(必需),where(可选)
-
mysql_delete - ⚠️ 警告:删除数据 - 使用者自负责任
- 参数:table(必需),where(可选)
开发
# 安装依赖
npm install
# 运行测试
npm test
# 启动开发模式
npm start
依赖
- mysql2: MySQL数据库驱动
- commander: 命令行参数解析
- Node.js ES模块支持
许可证
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.