Back to MCP directory
publicPublicdnsLocal runtime

MongoDB-Model-Context-Protocol-MCP-

MongoDB MCP服务器是一个允许LLM直接与MongoDB数据库交互的服务,支持查询集合、检查模式和管理数据。

article

README

🚀 MongoDB 模型上下文协议 (MCP) 服务器用于 LLM

一个 Model Context Protocol (MCP) 服务器,可让大语言模型(LLM)直接与 MongoDB 数据库进行交互。借助它,用户能通过自然语言查询集合、检查架构,还能对数据进行管理和处理。

✨ 主要特性

  • 🔍 集合架构检查
  • 📊 文档查询和筛选
  • 📈 索引管理
  • 📝 文档操作(插入、更新、删除)

🎥 演示视频

点击查看

🚀 快速开始

配置启动

要开始使用,您需要找到 MongoDB 连接 URL,并将以下配置添加到您的 Claude Desktop 配置文件中:

  • MacOS~/Library/Application\ 支持/Claude/claude_desktop_config.json
  • Windows%APPDATA%/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "mongodb": {
      "command": "npx",
      "args": [
        "mongo-mcp",
        "mongodb://<username>:<password>@<host>:<port>/<database>?authSource=admin"
      ]
    }
  }
}

使用 Smithery 安装

您可以通过 Smithery 自动安装 MongoDB MCP Server for Claude Desktop:

npx -y @smithery/cli install mongo-mcp --client claude

先决条件

  • Node.js 18+
  • npx
  • Docker 和 Docker Compose(仅限本地沙盒测试)
  • MCP 客户端(例如 Claude Desktop App)

测试沙盒设置

如果您没有 MongoDB 数据库服务器可以连接,并且想要创建一个示例沙盒,请按照以下步骤操作:

  1. 使用 Docker Compose 启动 MongoDB:
docker-compose up -d
  1. 运行 seed 脚本以创建测试数据:
npm run seed

配置 Claude Desktop

在不同操作系统下修改配置文件:

  • MacOS 和 Linux:编辑 ~/.config/Claude/claude_config.json 文件,添加以下内容:
"mongo-mcp": {
  " connectionString": "mongodb://localhost:27017"
}
  • Windows:编辑 %APPDATA%/Claude/claude_config.json 文件,添加类似的内容。

💻 使用示例

基础用法

# 查询所有文档
/mongo-mcp --query '{"command": "findAll"}'

# 插入新文档
/mongo-mcp --insert '{"name": "test", "value": 123}'

高级用法

# 按条件查找
/mongo-mcp --search '{"name": "test"}' --projection '{"_id": 0, "name": 1}'

# 更新文档
/mongo-mcp --update '{"query": {"name": "test"}, "update": {"$set": {"value": 456}}}'

# 创建索引
/mongo-mcp --create-index '{"collection": "users", "index": { "field": 1 }}'

# 删除索引
/mongo-mcp --drop-index '{"collection": "users", "indexName": "field_1"}'

📚 详细文档

可用工具

查询工具

| 工具名称 | 功能 | | ---- | ---- | | find | 查找所有文档 | | search | 根据条件查找 | | insert | 插入新文档 | | update | 更新现有文档 | | delete | 删除文档 |

索引工具

| 工具名称 | 功能 | | ---- | ---- | | create-index | 创建索引 | | drop-index | 删除索引 | | indexes | 列出集合的索引 |

📄 许可证

该项目使用 MIT License,有关详细信息,请参阅 LICENSE 文件。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client