home / mcp / mongodb mcp server
A Model Context Protocol server for interacting with MongoDB Databases and MongoDB Atlas.
Configuration
View docs{
"mcpServers": {
"mongodb-js-mongodb-mcp-server": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server@latest",
"--readOnly"
],
"env": {
"MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret",
"MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase"
}
}
}
}You can run the MongoDB MCP Server to interact with MongoDB databases and Atlas using a Model Context Protocol client. It supports read-only access, Atlas API tools, and a variety of MongoDB tools, exposed through a configurable MCP interface that can run locally or as a service in containers or HTTP endpoints.
You deploy the MongoDB MCP Server and connect to it with an MCP client. Start with a ready configuration that provides either a MongoDB connection string or Atlas API credentials. Run the server in a mode that best fits your environment (local stdio, Docker container, or an HTTP transport when needed). Once running, your MCP client can invoke the MongoDB tools, manage databases and collections, perform queries, and, if permitted, write operations.
Prerequisites you need before starting: a supported Node.js runtime, and a valid MongoDB connection string or Atlas API credentials. Use environment variables for sensitive data when possible.
Step-by-step setup using a local stdio configuration with an environment-provided connection string:
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase"
}
}
}
}If you prefer Atlas API credentials, configure them similarly in your MCP configuration.
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
"env": {
"MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
}
}
}
}You can also run a standalone server using environment variables and the command line, then start with npx, as shown in the examples.
Configuration and security considerations are central to using the MongoDB MCP Server effectively. Use environment variables for sensitive data, enable read-only mode when you only need data access, and consider enabling or disabling tools to match your security posture.
The server supports multiple configuration methods with a recommended preference order: environment variables, then command-line arguments, then configuration files. Sensitive information should be supplied via environment variables whenever possible.
Below are common configuration patterns you may encounter. The examples show how you can provide a MongoDB connection string or Atlas API credentials to the server.
Run an aggregation against a MongoDB collection
Describe the indexes for a collection
Describe the schema for a collection
Gets the size of the collection
Connect to a MongoDB instance
Gets the number of documents in a MongoDB collection using db.collection.count() and query as an optional filter parameter
Creates a new collection in a database. If the database doesn't exist, it will be created automatically.
Create an index for a collection
Returns statistics that reflect the use state of a single database
Removes all documents that match the filter from a MongoDB collection
Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection.
Removes the specified database, deleting the associated data files
Drop an index for the provided database and collection.
Returns statistics describing the execution of the winning plan chosen by the query optimizer for the evaluated method
Export a query or aggregation results in the specified EJSON format.
Run a find query against a MongoDB collection
Insert an array of documents into a MongoDB collection.
List all collections for a given database
List all databases for a MongoDB connection
Returns the most recent logged mongod events
Renames a collection in a MongoDB database
Switch to a different MongoDB connection
Updates all documents that match the specified filter for a collection.
Connect to MongoDB Atlas cluster
Allow IP/CIDR ranges to access your MongoDB Atlas clusters.
Create a MongoDB Atlas database user
Create a free MongoDB Atlas cluster
Create a MongoDB Atlas project
Get MongoDB Atlas performance advisor recommendations and suggestions
Inspect IP/CIDR ranges with access to your MongoDB Atlas clusters.
Inspect metadata of a MongoDB Atlas cluster
List MongoDB Atlas alerts
List MongoDB Atlas clusters
List MongoDB Atlas database users
List MongoDB Atlas organizations
List MongoDB Atlas projects
Connect to a MongoDB Atlas Local deployment
Create a MongoDB Atlas local deployment
Delete a MongoDB Atlas local deployment
List MongoDB Atlas local deployments
List available data sources in the MongoDB Assistant knowledge base.
Search for information in the MongoDB Assistant knowledge base.