这是一个由社区维护的MCP服务器,提供对MongoDB数据库的只读访问。若您想访问官方MongoDB MCP服务器,请前往 mongodb-js/mongodb-mcp-server。
本服务器是一个提供对MongoDB数据库只读访问的模型上下文协议(MCP)服务器,它能让LLM检查集合模式并执行聚合管道。
要使用此服务器与Claude Desktop应用,需将以下配置添加到claude_desktop_config.json
文件的“mcpServers”部分:
"mongodb": {
"command": "npx",
"args": [
"-y" ,
"@pash1986/mcp-server-mongodb"
],
"env" : {
"MONGODB_URI" : "mongodb+srv://" // '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"
}
aggregate
collection
(字符串):要查询的集合。pipeline
(数组):MongoDB聚合管道阶段。options
(对象):可选的聚合设置。
allowDiskUse
(布尔值):允许使用磁盘操作。maxTimeMS
(数字):最大执行时间,以毫秒为单位。comment
(字符串):标识操作的注释。explain
collection
(字符串):要分析的集合。pipeline
(数组):MongoDB聚合管道阶段。verbosity
(字符串):解释的详细程度。
服务器为每个数据库集合提供模式信息:
mongodb:////schema
)
此MCP服务器根据MIT许可证发布。这意味着您可以自由使用、修改和分发软件,但需遵循MIT许可证的条款和条件。有关详细信息,请参阅项目存储库中的LICENSE文件。