Mcp Mongodb

by nan-qin

412 downloads
Not rated
GitHub

About

Mcp Mongodb is an MCP server that enables interaction with MongoDB databases through the Model Context Protocol. It provides tools and resources for reading and writing data, executing aggregation pipelines, and performing multi‑collection queries. It is intended for developers…

Details

Author
nan-qin
Downloads
412
Categories
Database

- Supports read and write operations via resources and tools.
- Enables multi‑collection aggregation using MongoDB’s $lookup.
- Provides a clear separation between CallTool and ReadResource schemas.
- Configurable connection URI via environment variable.
- Built on Node.js for lightweight deployment.

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Mcp Mongodb
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Configure the server by setting the MONGO_URI environment variable (e.g., mongodb://localhost:27017/). Launch the server with Node.js, then use MCP tools such as read_resource to read resources and multi_collection_query to perform aggregation queries across collections.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mcp mongodb": {
            "mongodb": {
                "command": "node",
                "args": [
                    "E:\\project\\mongodb\\build\\index2.js"
                ],
                "env": {
                    "MONGO_URI": "mongodb://localhost:27017/"
                },
                "disabled": false,
                "autoApprove": []
            }
        }
    }
}

McpServers

{
    "mongodb": {
        "command": "node",
        "args": [
            "E:\\project\\mongodb\\build\\index2.js"
        ],
        "env": {
            "MONGO_URI": "mongodb://localhost:27017/"
        },
        "disabled": false,
        "autoApprove": []
    }
}

MCP 配置文件

`` { "mcpServers": { "mongodb": { "command": "node", "args": [ "E:\\project\\mongodb\\build\\index2.js" ], "env": { "MONGO_URI": "mongodb://localhost:27017/" }, "disabled": false, "autoApprove": [] }, } } ``

读取资源请求示例:

<use_mcp_tool> <server_name>mongodb</server_name> <tool_name>read_resource</tool_name> { "uri": "mongodb://localhost:27017/common" } </use_mcp_tool>

CallToolRequestSchema、ReadResourceRequestSchema 的区别

CallToolRequestSchema: 用于执行特定操作 适合执行命令、处理数据等主动操作 示例:获取集合列表、插入数据等 ReadResourceRequestSchema: 用于读取资源内容 适合提供对资源的只读访问 示例:读取集合文档、获取数据库状态等

多表联查示例

<use_mcp_tool> <server_name>mongodb</server_name> <tool_name>multi_collection_query</tool_name> { "database": "common", "collection": "players", "pipeline": [ { "$lookup": { "from": "platform", "localField": "platform", "foreignField": "appKey", "as": "platformInfo" } }, { "$unwind": "$platformInfo" }, { "$project": { "_id": 1, "pid": 1, "__v": 1, "bank": 1, "ip": 1, "lobbyUrl": 1, "platform": "$platformInfo", "rtp": 1, "_collection": { "$literal": "players" } } }, { "$limit": 2 } ] } </use_mcp_tool>

修改托送测试test

pull-request 漫长的过程 跑一下试试
No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.