mongodb
MongoDB MCP Server
claude mcp add --transport stdio jonfreeland-mongodb-mcp node /path/to/jonfreeland-mongodb-mcp/build/index.js \ --env MONGODB_URI="mongodb://username:password@hostname:port/database" \ --env MONGODB_DEFAULT_DATABASE="your_default_db"
How to use
This MongoDB MCP Server exposes read-only access to your MongoDB databases through the MCP (Model Context Protocol) interface. It supports essential data exploration and analysis tasks such as listing databases and collections, inferring collection schemas, executing read-only queries with filtering, projection, sorting, and limiting, and performing safe aggregations. Additional capabilities include text search on indexed fields, geospatial queries, counting and sampling documents, retrieving statistics and index information, and exporting results as JSON or CSV. The server also provides helpful guidance for visualization and intelligent safety checks to prevent unintended data modifications.
To use the server, connect an MCP-enabled client (such as Claude Desktop/Web or Claude Code) to the mongodb MCP server endpoint. Provide the required MONGODB_URI for authentication, and optionally set MONGODB_DEFAULT_DATABASE for default query context. Once connected, you can issue standard MCP tool commands (e.g., list databases, run queries, fetch document samples) and receive structured results suitable for downstream AI-assisted analysis and visualization.
How to install
Prerequisites:
- Node.js and npm installed on your system
- Access to a MongoDB instance (with read permissions)
- A path or deployment method to host the MCP server code
- Install dependencies
npm install
- Build the server (if your project requires a build step)
npm run build
- (Optional) Run in watch mode for development
npm run watch
- Prepare environment variables
- MONGODB_URI: Your MongoDB connection string (including credentials if required)
- MONGODB_DEFAULT_DATABASE: (Optional) Default database name for queries
- Run the MCP server
# Example runner command
node /path/to/jonfreeland-mongodb-mcp/build/index.js
- Verify the server is reachable via your MCP client (Claude Desktop/Web/Code) by configuring the server as described in the README
Additional notes
Tips and common issues:
- Ensure MONGODB_URI is kept secure; avoid exposing it in client configurations or logs.
- The server is read-only by design; attempting write-style operations will be rejected or ignored.
- If you encounter connection errors, verify network access to the MongoDB instance and that the credentials have the appropriate read permissions.
- For Claude Code integration, ensure the command and path point to the compiled MCP server index.js file and include the necessary -e environment variables when using the add command.
- When using text search or geospatial queries, make sure relevant indexes (text, 2dsphere) exist on the target collections to achieve expected performance.
- Use the MCP Inspector during debugging to inspect the protocol messages and responses.
- If you need to override defaults, you can set MONGODB_DEFAULT_DATABASE to a sensible fallback database.
Related MCP Servers
mcp-for-beginners
This open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
bitbucket
Bitbucket MCP - A Model Context Protocol (MCP) server for integrating with Bitbucket Cloud and Server APIs
mcp-arr
MCP server for *arr media management suite
crawlbase
Crawlbase MCP Server connects AI agents and LLMs with real-time web data. It powers Claude, Cursor, and Windsurf integrations with battle-tested web scraping, JavaScript rendering, and anti-bot protection enabling structured, live data inside your AI workflows.
autowpmcp
AutoWP MCP (Model Context Protocol) server connects Claude to WordPress site and allows users to ask Claude to write blog posts and automatically publish them to WordPress sites.
SureChEMBL
A comprehensive Model Context Protocol (MCP) server for accessing the SureChEMBL chemical patent database.