mongodb-mcp
Provides comprehensive MongoDB integration for database operations, document management, schema analysis, query execution, aggregation, indexing, and monitoring with optional read-only mode for safe data exploration.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mongodb-mcpanalyze schema for users collection in myapp"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MongoDB MCP Server
Also available in Russian: README-ru.md
Note: This project is designed for my personal needs. I do not plan to expand its functionality with features I don't use or cannot verify. You are free to submit suggestions and pull requests, but I make no guarantee that everything will be accepted.
MCP server for comprehensive MongoDB integration with the following capabilities:
Database operations - connect to MongoDB instances, list databases and collections
Document management - find, aggregate, and count documents
Schema analysis - analyze collection schemas and indexes
Query tools - execute queries and aggregations with full MongoDB syntax
Connection management - manage MongoDB connections with read-only mode support
Streaming file export - streaming save to files for large datasets
Read-only mode - safe read-only operations to prevent accidental data modifications
Monitoring - database statistics, performance metrics, and MongoDB logs
Query Analysis - execution plan analysis for performance optimization
Table of Contents
Related MCP server: MongoDB MCP Server for LLMs
Requirements
Node.js ≥ 22 (Node 20 reached EOL on 2026-04-30)
Environment variables:
MONGODB_MCP_CONNECTION_STRING— MongoDB connection string (mongodb:// or mongodb+srv:// format)MONGODB_MCP_DEFAULT_DATABASE— optional default database name for operationsMONGODB_MCP_TIMEZONE— optional timezone for date operations (default:Europe/Moscow), must be a valid IANA timezone identifier (e.g.,Europe/London,America/New_York,Asia/Tokyo)
Configuration for Qwen Code
To use this MCP server with Qwen Code, add to ~/.qwen/settings.json:
{
"mcpServers": {
"mongodb-mcp": {
"command": "npx",
"args": ["-y", "@vitalyostanin/mongodb-mcp@latest"],
"env": {
"MONGODB_MCP_CONNECTION_STRING": "mongodb://localhost:27017"
}
}
}
}Note: This configuration uses npx to run the published package. For local development, use "command": "node" with "args": ["/absolute/path/to/mongodb-mcp/dist/index.js"]. The MONGODB_MCP_TIMEZONE environment variable is optional.
Configuration for VS Code Cline
To use this MCP server with Cline extension in VS Code:
Open VS Code with Cline extension installed
Click the MCP Servers icon in Cline's top navigation
Select the "Configure" tab and click "Configure MCP Servers"
Add the following configuration to
cline_mcp_settings.json:
{
"mcpServers": {
"mongodb-mcp": {
"command": "npx",
"args": ["-y", "@vitalyostanin/mongodb-mcp@latest"],
"env": {
"MONGODB_MCP_CONNECTION_STRING": "mongodb://localhost:27017"
}
}
}
}Note: This configuration uses npx to run the published package. For local development, use "command": "node" with "args": ["/absolute/path/to/mongodb-mcp/dist/index.js"]. The MONGODB_MCP_TIMEZONE environment variable is optional.
MCP Tools
Read-Only Mode Tools
Tool | Description | Main Parameters |
| Get MongoDB service information, environment configuration, version, and current timezone | — |
| Establish connection to MongoDB using connection string | — |
| Disconnect from MongoDB | — |
| List all databases in the MongoDB instance | — |
| Get statistics for a specific database |
|
| List all collections for a given database |
|
| Analyze the schema for a collection |
|
| Describe the indexes for a collection |
|
| Get the size of a collection |
|
| Run find queries against a MongoDB collection |
|
| Count documents in a MongoDB collection |
|
| Returns statistics describing the execution of the winning plan chosen by the query optimizer |
|
| Returns the most recent logged mongod events | optionally |
Non-Read-Only Mode Tools
Tool | Description | Main Parameters |
| Run an aggregation against a MongoDB collection |
|
| Insert one or multiple documents into a MongoDB collection |
|
| Update one or multiple documents in a MongoDB collection |
|
| Delete one or multiple documents from a MongoDB collection |
|
| Create an index on a MongoDB collection |
|
| Drop an index from a MongoDB collection |
|
| Create a new collection in a MongoDB database |
|
| Drop a collection from a MongoDB database |
|
Note: The server runs in read-only mode by default to prevent accidental data modifications. In read-only mode, all write operations are blocked including:
Database-level operations:
insertOne,insertMany,updateOne,updateMany,deleteOne,deleteMany,createIndex,dropIndex,dropDatabase,renameCollection, etc.Collection-level operations:
insertOne,insertMany,updateOne,updateMany,deleteOne,deleteMany,findOneAndReplace,findOneAndUpdate,findOneAndDelete,bulkWrite,createIndex,dropIndex,drop, etc.Aggregation stages that modify data:
$out,$merge
The following aggregation stages are restricted in read-only mode: $out, $merge. These stages are only available when the server is running in read-write mode.
Security considerations
Recommendations for safe production use of the MCP server:
Use TLS for remote MongoDB clusters. Prefer
mongodb+srv://(TLS is implied) or settls=trueexplicitly in a regularmongodb://connection string. Plaintext connections expose credentials and query payloads to anyone on the network path.Apply least-privilege roles. Create a dedicated MongoDB user with read-only access to only the databases you need. Avoid
root,dbAdmin, or any role that grantseval/ scripting privileges. Default to read-only mode unless write tools are required.Keep the connection string out of MCP host args. Configure
MONGODB_MCP_CONNECTION_STRINGvia environment variables (e.g.,.envfile) rather than passing it throughargsof the MCP host configuration —argsare typically logged when the host launches the server, leaking the password.Disable server-side JavaScript. The MCP server already blocks
$where,$function, and$accumulatoroperators in queries. For defence in depth, run the MongoDB server itself with--javascriptEnabled=false(or the equivalentsecurity.javascriptEnabled: falseinmongod.conf).Restrict the export directory. When using file-export tools, set
MONGODB_MCP_EXPORT_DIRto a directory accessible only to the MCP user (chmod 700). Other users on the machine should not be able to read the dumps that write tools produce.
Concurrency considerations
The MCP server does not provide transactional or ordering guarantees beyond what MongoDB itself enforces. Plan multi-step interactions accordingly:
Tools are independent operations. Each call runs in its own implicit context; the server does not start multi-statement transactions or share a
ClientSessionacross calls. Design atomic multi-step flows by encoding preconditions into thefilterof the sameupdate/deletecall, rather than chaining a separatefindfollowed by a mutating call.Singleton client, parallel operations. A single
MongoClientis shared across all tool calls. Onlyconnect/disconnectare serialised through an internal mutex; ordinary operations (find,aggregate,insert, etc.) execute concurrently against the cluster, with no cross-tool ordering imposed by the MCP server.Connection state is a snapshot.
getConnectionInfo()returns the state at the moment of the call. For decisions that depend on connectivity, rely on the result of the next operation rather than a precedingisConnectedcheck — the connection may drop between the two.File-export uses
wx. Tools that write files open the target with thewxflag and will not overwrite an existing file. Concurrent calls targeting the samefilePathwill fail withEEXIST; callers must pick a fresh path (e.g., include a timestamp or per-call suffix).
Local Development
Quick reference for working with the source.
Prerequisites:
Node.js as specified in
.nvmrc(current LTS, ≥ 22). With nvm:nvm use.npm.
Setup:
git clone https://github.com/VitalyOstanin/mongodb-mcp.git
cd mongodb-mcp
npm installCommon scripts:
Script | Purpose |
| Compile TypeScript to |
| Run |
| Run the compiled server from |
| Type-check sources + tests ( |
| Type-check with extra strict flags ( |
| Run ESLint |
| Run ESLint with |
| Run the Vitest test suite once |
| Run Vitest in watch mode |
| Run Vitest with v8 coverage (opt-in; threshold gate enforced) |
| Run Vitest sequentially ( |
Local connection example:
export MONGODB_MCP_CONNECTION_STRING="mongodb://localhost:27017"
npm run devLayout:
index.ts— CLI entry point.src/server.ts— MCP server bootstrap.src/mongodb-client.ts— singleton MongoDB client with read-only Proxy.src/tools/— one MCP tool per file plus its*.test.ts.src/utils/— shared helpers (streaming exports, schema fragments, date handling, redaction).
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/VitalyOstanin/mongodb-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server