Purpose
mcp-mongo-server is a Model Context Protocol (MCP) server used to connect MongoDB databases to MCP-enabled AI assistants. It lets tools such as Claude Desktop and Cursor read and understand your data directly: assistants can converse with the database in natural language, automatically discover collections and their structure, and perform queries, aggregations, and write operations.
Key Capabilities
- Natural language interaction: converse with the database in natural language, and the assistant will automatically discover collections and their shape.
- Secure by default: read-only mode can be enabled, letting the assistant explore without the risk of data changes.
- Broad connectivity: supports standalone, replica set, sharded, and Atlas deployments, using either standard or TLS connections.
- Read-only mode: blocks all write paths, including insert, update, index creation, and aggregation stages that may modify data (such as $out / $merge).
- Intelligent ObjectId handling: configurable auto / none / force, converting 24-character hexadecimal strings to ObjectId.
- Schema inference: automatically detects collection schemas based on document samples.
- Queries and aggregations: full support for queries and aggregation pipelines, with the option to generate explain plans.
- Write operations: when read-only mode is disabled, supports inserts, updates, and index creation.
- Time conversion: the convertTime helper function can convert Unix timestamps and date strings to UTC / GMT / ISO, keeping date queries unambiguous across time zones.
- Progress and cancellation: long-running operations report progress and can be cancelled mid-execution.
- Two transport methods: run locally via stdio, or expose an HTTP endpoint for remote access.
Usage
Requires Node.js 20 or higher. No installation step is needed; simply point the server at your database:
npx mcp-mongo-server "mongodb://localhost:27017/mydb"
Read-only mode for exploring only, without changing data:
npx mcp-mongo-server "mongodb://localhost:27017/mydb" --read-only
By default it uses stdio transport, for Claude Desktop, Cursor, and other local clients:
npx mcp-mongo-server "mongodb://localhost:27017/mydb" --stdio
Expose an HTTP endpoint at /mcp for remote or multi-client access:
npx mcp-mongo-server "mongodb://localhost:27017/mydb" --http --port 3000
By default, only requests without a browser Origin (CLI, IDE) and requests from localhost are accepted; other requests are rejected with 403 to prevent DNS rebinding attacks. --allowed-origins can be used to allow specific browser origins.
Environment Variables
The server profile lists an Environment Variables section, but it does not provide the specific variable names or value descriptions, so they are not provided for now.
Use Cases
Suitable for development and analysis scenarios that require an AI assistant to read, query, aggregate, or even write MongoDB data, including local IDE assistants and remote multi-client access.
Limitations
- Database scope: The server only operates on the database in the connection string. Aggregation stages involving other databases ($out, $merge, and $lookup with an explicit db) are rejected by default, to prevent the pipeline from quietly reading from or writing to unspecified databases; if needed, they can be enabled with --allow-cross-db.
- Server-side JavaScript: The aggregation operators $function, $where, and $accumulator run arbitrary JavaScript on the MongoDB server side and are rejected by default; if you trust the pipelines being run, they can be enabled with --allow-server-js.
- Read-only mode blocks all write paths, including aggregation stages that write or run server-side JavaScript ($out, $merge, $function, $where, $accumulator).
- Least privilege: Application-layer checks have limited effect; the strongest guarantee comes from the database itself. It is recommended to connect with a MongoDB user that is restricted to only the required databases and has read-only permissions; this is especially true when the assistant only needs to explore, with the database itself enforcing the boundary to form defense in depth.
Integration and License
The Integration Guide covers Claude Desktop, Windsurf, Cursor, and Docker; Available Tools covers query, aggregate, update, insert, etc.; Development covers installation, scripts, and debugging. The project uses the MIT license, see LICENSE for details.