一、简介
- MCP Toolbox for Databases 是一个针对数据库设计的开源 MCP 服务器工具
- 集成数据库连接池、身份认证,保证数据库访问性能和安全
- 支持多种数据源类型,如mysql、postgres、sqlite、http等等
- 支持自定义数据源与数据库工具,更加灵活可控
- 工具的开源地址参考:https://github.com/googleapis/genai-toolbox
二、安装
- 新建docker-compose.yml,内容如下:
services: toolbox: image: us-central1-docker.pkg.dev/database-toolbox/toolbox/toolbox:latest restart: always ports: - "5000:5000" volumes: - ./config:/config command: [ "toolbox", "--tools-file", "/config/tools.yaml", "--address", "0.0.0.0"]
- 再新建配置文件./config/tools.yaml,配置示例如下
更多配置项可参考官网文档:https://googleapis.github.io/genai-toolbox/getting-started/configure/sources: mysql-source: kind: mysql host: 127.0.0.1 port: 3306 database: test user: root password: root tools: search-user-by-name: kind: mysql-sql source: mysql-source description: 根据名称关键字查询用户信息 templateParameters: - name: name type: string description: 名称关键字 statement: SELECT id,name,status,created_at,updated_at FROM user WHERE name LIKE "%{{.name}}%" create-fake-user: kind: mysql-sql source: mysql-source description: 新增插入一个用户数据,只要调用正常即为成功,不需要判断具体的返回结果 templateParameters: - name: name type: string description: 用户名称,这是唯一索引 - name: status type: integer description: 状态,0-禁用,1-启用 - name: created_at type: string description: 创建时间,格式:2025-07-20 12:12:12 - name: updated_at type: string description: 更新时间,格式:2025-07-20 12:12:12 statement: | INSERT INTO user (name, status, created_at, updated_at) VALUES ('{{.name}}', {{.status}}, '{{.created_at}}', '{{.updated_at}}')
- 一键启动
docker-compose up -d
启动成功,可以看见初始化了多少个数据源和数据库工具
三、使用
1. 安装配置好支持MCP的AI对话客户端,如Cherry Studio,直接下载安装即可,参考:https://www.cherry-ai.com/
2. 在Cherry Studio中添加并配置好MCP工具,参考如下,输入streamablehttp的服务地址:http://127.0.0.1:5000/mcp
3. 在AI对话中使用改MCP工具示例
-
配置好可用的大语言模型,并且选择启用刚刚添加的MCP工具
-
对话示例一:创建3个测试用户数据
成功调用三次创建用户信息的工具
数据库成功插入了三条测试数据,如下
- 对话示例二:查询“测试用户”的账号信息
成功模糊查询到用户的账号信息
4. 更多数据库使用案例…(自行探索)
四、总结
- 该数据库MCP工具功能比较完善,安全性和性能都不错,可以作为生产环境工具使用
- 安装使用简单,官网文档完善,且是谷歌大厂开源背书,可靠可期
- 可以结合AI能力辅助生成符合业务场景的模拟数据,方便测试和开发验证,提升开发效率
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容