MySQL MCP服务是一个基于Node.js开发的API服务,它提供了让Cursor AI直接访问MySQL数据库的能力。该服务遵循MCP(模型控制平台)协议规范,使AI能够通过标准化接口执行SQL查询、获取表结构信息以及进行数据操作。
git clone https://github.com/lichuanrong7/mysql-mcp-server.git
cd mysql-mcp-server
npm install
创建或编辑.env文件,添加以下配置:
# 服务器配置
PORT=3100
# 数据库配置
DB_HOST=你的数据库地址
DB_PORT=3306
DB_USER=你的数据库用户名
DB_PASSWORD=你的数据库密码
DB_NAME=你的数据库名称
# 开发模式启动
npm run dev
# 生产模式启动
npm start
项目提供了方便的启动和停止脚本:
启动服务:
./start.sh
终止服务:
./stop.sh
docker build -t mysql-mcp-server .
docker-compose up -d
/manifest.json/openapi.yaml/api/mysql/query/api/mysql/schema/api/mysql/ddl执行SQL查询:
curl -X POST http://localhost:3100/api/mysql/query \
-H "Content-Type: application/json" \
-d '{"query":"SELECT * FROM users LIMIT 10"}'
获取表结构:
curl -X GET http://localhost:3100/api/mysql/schema?table=users
http://localhost:3100/manifest.json激活MCP服务后,您可以在Cursor中使用自然语言来操纵数据库:
服务无法启动
lsof -i :3100./logs/mysql-mcp-*.log数据库连接失败
API请求失败
curl http://localhost:3100/manifest.json本项目采用MIT许可证 - 请参阅更多详情LICENSE文档
欢迎提交问题和贡献代码。请确保遵循以下步骤:
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)