MongoDB MCP Server

Official

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Provides read-only access to MongoDB databases, enabling inspection of collection schemas and execution of aggregation pipelines with safety features like document limits and query timeouts.

MongoDB MCP 服务器

提供对 MongoDB 数据库的只读访问的模型上下文协议 (MLM) 服务器。该服务器使 LLM 能够检查集合模式并执行聚合管道。

成分

工具

  • 总计的
    • 针对连接的数据库执行 MongoDB 聚合管道
    • 输入:
      • collection (字符串):要查询的集合
      • pipeline (数组):MongoDB 聚合管道阶段
      • options (对象):可选的聚合设置
        • allowDiskUse (布尔值):允许需要使用磁盘的操作
        • maxTimeMS (数字):最大执行时间(以毫秒为单位)
        • comment (字符串):用于标识操作的注释
    • 如果未指定限制阶段,则默认限制为 1000 个文档
    • 默认超时时间为 30 秒
  • 解释
    • 获取聚合管道的执行计划
    • 输入:
      • collection (字符串):要分析的集合
      • pipeline (数组):MongoDB 聚合管道阶段
      • verbosity (字符串):解释的详细程度
        • 选项:“queryPlanner”、“executionStats”、“allPlansExecution”
        • 默认值:“queryPlanner”

资源

服务器为数据库中的每个集合提供架构信息:

  • 集合模式mongodb://<host>/<collection>/schema
    • 推断每个集合的 JSON 架构信息
    • 包括字段名称和数据类型
    • 模式源自采样收集文档

与 Claude Desktop 一起使用

要将此服务器与 Claude Desktop 应用程序一起使用,请将以下配置添加到claude_desktop_config.json的“mcpServers”部分:

"mongodb": { "command": "npx", "args": [ "-y" , "@pash1986/mcp-server-mongodb" ], "env" : { "MONGODB_URI" : "mongodb+srv://<yourcluster>" // 'mongodb://localhost:27017' } }

mydb替换为您的数据库名称,并根据需要调整连接字符串。

示例用法

基本聚合

{ "collection": "users", "pipeline": [ { "$match": { "age": { "$gt": 21 } } }, { "$group": { "_id": "$city", "avgAge": { "$avg": "$age" }, "count": { "$sum": 1 } }}, { "$sort": { "count": -1 } }, { "$limit": 10 } ], "options": { "allowDiskUse": true, "maxTimeMS": 60000, "comment": "City-wise user statistics" } }

查询说明

{ "collection": "users", "pipeline": [ { "$match": { "age": { "$gt": 21 } } }, { "$sort": { "age": 1 } } ], "verbosity": "executionStats" }

安全功能

  • 如果管道中未指定限制,则自动限制为 1000 个文档
  • 所有操作的默认超时时间为 30 秒
  • 仅限只读操作
  • 从收集样本中推断安全模式

执照

此 MCP 服务器采用 MIT 许可证。这意味着您可以自由使用、修改和分发该软件,但须遵守 MIT 许可证的条款和条件。更多详情,请参阅项目仓库中的 LICENSE 文件。

-
security - not tested
F
license - not found
-
quality - not tested

为 LLM 提供对 MongoDB 数据库的只读访问权限,以检查收集模式并执行聚合管道。

  1. Components
    1. Tools
    2. Resources
  2. Usage with Claude Desktop
    1. Example Usage
      1. Basic Aggregation
      2. Query Explanation
    2. Safety Features
      1. License
        ID: 553iezfbrd