Cover image
Try Now
2025-03-26

MongoDB MCP服务器

3 years

Works with Finder

2

Github Watches

2

Github Forks

3

Github Stars

MongoDB MCP Server

A Model Context Protocol server that provides read-only access to MongoDB databases through standardized MCP tools and resources.

MongoDB Server MCP server

Overview

This MongoDB MCP server enables AI assistants to directly query and analyze MongoDB databases without write access, maintaining data safety while providing powerful data exploration capabilities.

Features

MongoDB Operations

  • Database Exploration: List databases and collections
  • Schema Discovery: Infer collection schemas from sample documents
  • Querying: Execute MongoDB queries with filtering, projection, sorting, and limiting
  • Aggregation: Run read-only aggregation pipelines with safety validation
  • Text Search: Perform full-text search on collections with text indexes
  • Geospatial Queries: Find locations near points, within polygons, or intersecting geometries
  • Document Operations: Count documents, sample random documents, find documents by IDs
  • Data Analysis: Get collection statistics, index information, and query execution plans
  • Performance Insights: Examine query execution plans to optimize performance
  • Data Exploration: Get distinct values, field distributions, and data samples
  • Format Conversion: Export query results as JSON or CSV formats

Enhanced Capabilities

  • Schema Inference: Automatically detect data types and structure from documents
  • Visualization Hints: Intelligent suggestions for data visualization based on result content
  • Safety Validation: Prevents write operations in aggregation pipelines
  • Example-Rich Documentation: Each tool includes detailed examples in its description

Requirements

Environment Variables

  • MONGODB_URI (required): MongoDB connection string with authentication if needed
  • MONGODB_DEFAULT_DATABASE (optional): Default database name when not specified in queries

Prerequisites

  • Network access to MongoDB server
  • Authentication credentials if required by MongoDB instance
  • Appropriate read permissions on target databases

Installation

Building from Source

Install dependencies:

npm install

Build the server:

npm run build

For development with auto-rebuild:

npm run watch

Integration with Claude Desktop

To use with Claude Desktop, add the server configuration:

On MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json On Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "mongodb": {
      "command": "/path/to/mongodb-server/build/index.js",
      "env": {
        "MONGODB_URI": "mongodb://username:password@hostname:port/database",
        "MONGODB_DEFAULT_DATABASE": "your_default_db"
      }
    }
  }
}

Integration with Claude Web

For Claude Web via the MCP Chrome extension, add configuration to Cline MCP settings:

{
  "mcpServers": {
    "mongodb": {
      "command": "node",
      "args": ["/path/to/mongodb-server/build/index.js"],
      "env": {
        "MONGODB_URI": "mongodb://username:password@hostname:port/database",
        "MONGODB_DEFAULT_DATABASE": "your_default_db"
      }
    }
  }
}

Integration with Claude Code

To use with Claude Code, use the following commands:

cd /path/to/my/project
claude mcp add mongo-server /path/to/mongodb-mcp/build/index.js -e "MONGODB_URI=mongodb://user@password:27017/dbname?authSource=authDbName" -e MONGO_DEFAULT_DATABASE=dbname 

Make sure to replace the placeholders with your actual MongoDB connection string and default database name.

If configured correctly, you should see the following when you run claude:

╭───────────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code research preview!            │
│                                                       │
│   /help for help                                      │
│                                                       │
│   cwd: <path-to-project-directory>                    │
│                                                       │
│   ─────────────────────────────────────────────────── │
│                                                       │
│   MCP Servers:                                        │
│                                                       │
│   • mongo-server                            connected │
╰───────────────────────────────────────────────────────╯

If you run into issues, see the Claude Code documentation.

Security Considerations

  • This server provides read-only access by design
  • Connection strings may contain sensitive authentication information
  • Store connection strings securely in environment variables
  • Use a MongoDB user with read-only permissions

Debugging

Since MCP servers communicate over stdio, debugging can be challenging. Use the MCP Inspector, which is available as a package script:

npm run inspector

The Inspector will provide a URL to access debugging tools in your browser.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Khalid kalib
  • Write professional emails

  • https://tovuti.be
  • Oede knorrepot die vasthoudt an de goeie ouwe tied van 't boerenleven

  • ANGEL LEON
  • A world class elite tech co-founder entrepreneur, expert in software development, entrepreneurship, marketing, coaching style leadership and aligned with ambition for excellence, global market penetration and worldy perspectives.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Gil kaminski
  • Make sure you are post-ready before you post on social media

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • OffchainLabs
  • 进行以太坊的实施

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

  • deemkeen
  • 用电源组合控制您的MBOT2:MQTT+MCP+LLM

  • zhaoyunxing92
  • MCP(消息连接器协议)服务

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

    Reviews

    4 (1)
    Avatar
    user_bEscJicR
    2025-04-15

    As a devoted user of MCP Filesystem, I must say it has greatly enhanced my workflows with its reliability and efficiency. Gabrielmaialva33 has created an outstanding product that's intuitive and powerful. If you're looking for a seamless file management experience, MCP Filesystem is a must-try! Check it out here: https://mcp.so/server/mcp-filesystem/gabrielmaialva33