
MCP Database Server

2025.03.24
0
TypeScript数据库交互自然语言处理数据库
MCP Database Server 是一个基于 Model Context Protocol (MCP) 的服务实现,允许大型语言模型 (LLMs) 通过自然语言与各种数据库进行交互。目前支持 MongoDB,并计划未来支持 PostgreSQL、CockroachDB、Redis 等更多数据库。
View on GitHub
Overview
基本能力
产品定位
MCP Database Server 是一个数据库交互服务,通过自然语言处理技术简化数据库操作流程,使非技术用户也能轻松进行数据库查询和管理。
核心功能
- 通过自然语言进行数据库操作
- 当前支持 MongoDB 的以下功能:
- 列出所有集合
- 带过滤和投影的文档查询
- 插入文档
- 删除文档
- 聚合管道操作
- 未来计划支持其他数据库:
- PostgreSQL: SQL 查询、表操作
- CockroachDB: 分布式 SQL 操作
- Redis: 键值操作、缓存
适用场景
- 非技术用户需要查询数据库
- 快速原型开发
- 数据分析师进行数据探索
- 需要自然语言接口的数据库应用
工具列表
- getCollections: 列出连接数据库中的所有集合
- getCollection: 从集合中检索文档,支持查询参数、限制和投影
- insertOne: 向集合中插入单个文档
- deleteOne: 从集合中删除单个文档
- aggregate: 执行聚合管道操作
常见问题解答
- 安全问题:不要将数据库连接字符串提交到版本控制
- 使用环境变量存储敏感信息
- 遵循数据库特定的安全最佳实践
使用教程
使用依赖
- Node.js v20.12.2 或更高版本
- 数据库(目前是 MongoDB)
- Claude 桌面应用程序
安装教程
- 克隆仓库:
git clone https://github.com/manpreet2000/mcp-database-server.git
cd mcp-database-server
- 安装依赖:
npm install
- 构建 TypeScript 代码:
npm run build
配置
在 Claude 桌面配置文件中配置数据库连接:
MacOS:
~/Library/Application\ Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%/Claude/claude_desktop_config.json
添加以下配置:
{
"mcpServers": {
"database": {
"command": "/path/to/node",
"args": ["/path/to/mcp-database/dist/index.js"],
"env": {
"MONGODB_URI": "your-mongodb-connection-string"
}
}
}
}
调试方式
安装完成后,可以通过以下自然语言命令进行测试: 1. 列出数据库中的所有集合:
Can you show me all the collections in my database?
- 从集合中获取特定记录:
Give me 2 records from the chargers collection
- 带过滤器的查询:
Show me all documents in the users collection where status is active
- 插入文档:
Add a new user to the users collection with name John and email [email protected]
- 删除文档:
Remove the user with email [email protected] from the users collection
- 聚合数据:
Show me the total count of users by status in the users collection