mongodb-mcp
MongoDB MCP Server
Documentation
MongoDB MCP Server
A Model Context Protocol server that provides read-only access to MongoDB databases through standardized MCP tools and resources.
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 installBuild the server:
npm run buildFor development with auto-rebuild:
npm run watchIntegration 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=dbnameMake 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: │
│ │
│ ─────────────────────────────────────────────────── │
│ │
│ 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 inspectorThe Inspector will provide a URL to access debugging tools in your browser.
Frequently asked questions
What is mongodb-mcp?
mongodb-mcp is MongoDB MCP Server
How do I install mongodb-mcp?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is mongodb-mcp open source?
Yes — it is hosted on GitHub at https://github.com/jonfreeland/mongodb-mcp and has 9 stars.
Related MCP tools
🔥 Official Firecrawl MCP Server - Adds powerful web scraping and search to Cursor, Claude and any other LLM clients.
Official remote MCP server for Atlassian. Securely connect Jira, Confluence, Jira Service Management, Bitbucket, and Compass to Claude, ChatGPT, Cursor, VS Code, and other AI tools using OAuth 2.1 or API tokens.
🔥 Official Firecrawl MCP Server - Adds powerful web scraping and search to Cursor, Claude and any other LLM clients. JavaScript-based implementation.
Use any LLMs (Large Language Models) for Deep Research. Support SSE API and MCP server.
文颜 MCP Server 可以让 AI 自动将 Markdown 文章排版后发布至微信公众号。
This is a 12306 ticket search server based on the Model Context Protocol (MCP).
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP