目的:基于MCP实现text2sql能力 参考:blog.csdn.net/hacker_Lees…

服务端#

  1. 选用开源的MySQL MCP Server,本地部署:github.com/dpflucas/my…
1
# Clone the repository git clone https://github.com/dpflucas/mysql-mcp-server.git cd mysql-mcp-server # Install dependencies and build npm install npm run build 客户端[#](https://www.cnblogs.com/pam-sh/p/18821579#%E5%AE%A2%E6%88%B7%E7%AB%AF) 使用`Cherry Studio`作为客户端,内置接入MCP服务器功能,模型配置省略。 MCP有两种模式: ```txt 1)STDIO模式(本地运行) 特点:本地安装运行MCP Server,但需配置开发环境。 配置步骤: 安装依赖:需Python(推荐用uv安装)和NodeJS(推荐bun代替npm),Windows/MacOS/Linux均支持 添加MCP服务:在Cherry Studio->Settings->MCP Servers中,选择Edit JSON,填写mcpServers配置内容。 2)SSE模式(远程服务) 特点:无需本地环境,仅需输入服务器URL,适合调用云端API(如天气查询、数据库接口)。 配置步骤:直接输入SSE服务地址即可,例如集成Google Gemini或腾讯混元的联网搜索功能。 添加MCP json: ```json "mcpServers": { "mysql": { "isActive": true, "command": "node", "args": [ "D:\\code\\MCP\\mysql-mcp-server-main\\build\\index.js" "env": { "MYSQL_HOST": "localhost", "MYSQL_PORT": "3306", "MYSQL_USER": "root", "MYSQL_PASSWORD": "root", "MYSQL_DATABASE": "test" "disabled": false, "autoApprove": [], "name": "mysql" [![Image 15: image-20250411233018608](https://api.995120.cn/ecgdata/other/2025-10-18/83266202510181150439kiGVxir.awebp)](tos-cn-i-73owjymdk6/bc3f1507e3d049e58a117661abe31559) ### 测试[#](https://www.cnblogs.com/pam-sh/p/18821579#%E6%B5%8B%E8%AF%95) [![Image 16: image-20250411232740643](https://api.995120.cn/ecgdata/other/2025-10-18/4570720251018115044maGjYDr7.awebp)](tos-cn-i-73owjymdk6/6aeb3537385d4236a1be9981994a2860) 总的来说,text2sql能力还是取决于可用工具的功能,**MCP就是让模型根据用户意图去执行接口调度的过程**。 作者:[Hang Shao](https://www.cnblogs.com/pam-sh/) 出处:[https://www.cnblogs.com/pam-sh/p/18821579](https://www.cnblogs.com/pam-sh/p/18821579) 版权:本作品采用「[知识共享](https://www.cnblogs.com/pam-sh)」许可协议进行许可。 声明:欢迎交流! [原文链接](https://www.cnblogs.com/pam-sh/p/18821579#) ,如有问题,可邮件(mir\_soh@163.com)咨询.