MCP Database Server

MCP Database Server

site icon
2025.03.28 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:键值操作、缓存

适用场景

  • 需要通过自然语言界面管理数据库
  • 快速查询数据库内容而不需要编写复杂查询
  • 简化数据库操作流程
  • 教育与学习数据库操作

工具列表

  1. getCollections:列出连接数据库中的所有集合
  2. getCollection:从集合中检索文档,支持查询参数、限制和投影
  3. insertOne:向集合中插入单个文档
  4. deleteOne:从集合中删除单个文档
  5. aggregate:执行聚合管道操作

常见问题解答

  • 安全性:不要将数据库连接字符串提交到版本控制,使用环境变量存储敏感信息
  • 数据库支持:目前仅支持 MongoDB,其他数据库支持正在开发中
  • 性能:查询结果默认限制为10条,最大可设置为1000条

使用教程

使用依赖

  • Node.js v20.12.2 或更高版本
  • 数据库(当前为 MongoDB)
  • Claude Desktop Application

安装教程

  1. 克隆仓库:
git clone https://github.com/manpreet2000/mcp-database-server.git
cd mcp-database-server
  1. 安装依赖:
npm install
  1. 构建 TypeScript 代码:
npm run build

配置

在 Claude Desktop 配置文件中添加数据库配置:

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?
  1. 从集合中获取特定记录:
Give me 2 records from the chargers collection
  1. 带过滤器的查询:
Show me all documents in the users collection where status is active
  1. 插入文档:
Add a new user to the users collection with name John and email [email protected]
  1. 删除文档:
Remove the user with email [email protected] from the users collection
  1. 聚合数据:
Show me the total count of users by status in the users collection

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。