这是一个提供只读访问MongoDB数据库的模型上下文协议服务器。此服务器使LLMs能够检查集合模式并执行聚合管道。
aggregate
collection(字符串):要查询的集合pipeline(数组):MongoDB聚合管道阶段options(对象):可选的聚合设置
allowDiskUse(布尔值):允许需要磁盘使用的操作maxTimeMS(数字):最大执行时间(毫秒)comment(字符串):用于标识操作的注释explain
collection(字符串):要分析的集合pipeline(数组):MongoDB聚合管道阶段verbosity(字符串):解释的详细程度
该服务器提供了数据库中每个集合的模式信息:
mongodb://<host>/<collection>/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": "按城市统计用户"
}
}
{
"collection": "users",
"pipeline": [
{ "$match": { "age": { "$gt": 21 } } },
{ "$sort": { "age": 1 } }
],
"verbosity": "executionStats"
}
此MCP服务器采用MIT许可证。这意味着您可以自由地使用、修改和分发软件,但需遵守MIT许可证中的条款和条件。更多详情,请参见项目仓库中的LICENSE文件。