一个模型上下文协议服务器,提供对MongoDB数据库的只读访问。该服务器使LLMs能够检查集合模式并执行聚合管道。
aggregate
collection
(字符串): 要查询的集合pipeline
(数组): MongoDB聚合管道阶段options
(对象): 可选的聚合设置
allowDiskUse
(布尔值): 允许需要磁盘使用的操作maxTimeMS
(数字): 最大执行时间(毫秒)comment
(字符串): 用于标识操作的注释explain
collection
(字符串): 要分析的集合pipeline
(数组): MongoDB聚合管道阶段verbosity
(字符串): 解释的详细程度
服务器提供数据库中每个集合的模式信息:
mongodb://<主机>/<集合>/schema
)
要在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"
}

此MCP服务器根据MIT许可证授权。这意味着您可以自由使用、修改和分发该软件,但需遵守MIT许可证的条款和条件。有关更多详细信息,请参阅项目仓库中的LICENSE文件。