by mongodb-js
Provides a Model Context Protocol server that enables interaction with MongoDB databases and MongoDB Atlas clusters through a unified API.
MongoDB MCP Server offers a standardized interface for performing database operations, Atlas management tasks, and data exports directly from MCP‑compatible clients. It supports both connection‑string based access to any MongoDB instance and Atlas Service Account authentication for cloud‑native management.
npx without a global install:
npx -y mongodb-mcp-server@latest --readOnly
MDB_MCP_CONNECTION_STRING, MDB_MCP_API_CLIENT_ID, MDB_MCP_API_CLIENT_SECRET). These can be added to an MCP client configuration file.--transport http and optional host/port flags.find, aggregate, atlas-list-clusters) from any MCP‑enabled editor or CLI.mcp, disk, stderr) and custom log paths.Q: Do I need both a connection string and Atlas API credentials? A: No. Use a connection string for direct database access, or Atlas API credentials for cloud‑only management tools.
Q: How can I restrict write operations?
A: Set MDB_MCP_READ_ONLY=true or add the --readOnly flag when starting the server.
Q: Can I disable specific tools?
A: Yes, provide a comma‑separated list in MDB_MCP_DISABLED_TOOLS (e.g., create,delete,atlas).
Q: What transport should I use for production?
A: The default stdio is recommended for local client integrations. If HTTP is required, secure it with TLS, authentication, and firewalls.
Q: Where are exported files stored?
A: By default under ~/.mongodb/mongodb-mcp/exports (Linux/macOS) or %LOCALAPPDATA%\mongodb\mongodb-mcp\exports (Windows), cleaned up based on exportTimeoutMs.
A Model Context Protocol server for interacting with MongoDB Databases and MongoDB Atlas.
node -v
🔒 Security Recommendation 1: When using Atlas API credentials, be sure to assign only the minimum required permissions to your service account. See Atlas API Permissions for details.
🔒 Security Recommendation 2: For enhanced security, we strongly recommend using environment variables to pass sensitive configuration such as connection strings and API credentials instead of command line arguments. Command line arguments can be visible in process lists and logged in various system locations, potentially exposing your secrets. Environment variables provide a more secure way to handle sensitive information.
Most MCP clients require a configuration file to be created or modified to add the MCP server.
Note: The configuration file syntax can be different across clients. Please refer to the following links for the latest expected syntax:
Default Safety Notice: All examples below include
--readOnlyby default to ensure safe, read-only access to your data. Remove--readOnlyif you need to enable write operations.
You can pass your connection string via environment variables, make sure to use a valid username and password.
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server@latest", "--readOnly"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017/myDatabase"
}
}
}
}
NOTE: The connection string can be configured to connect to any MongoDB cluster, whether it's a local instance or an Atlas cluster.
Use your Atlas API Service Accounts credentials. Must follow all the steps in Atlas API Access section.
{
"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 source environment variables defined in a config file or explicitly set them like we do in the example below and run the server via npx.
# Set your credentials as environment variables first
export MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
export MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
# Then start the server
npx -y mongodb-mcp-server@latest --readOnly
💡 Platform Note: The examples above use Unix/Linux/macOS syntax. For Windows users, see Environment Variables for platform-specific instructions.
You can run the MongoDB MCP Server in a Docker container, which provides isolation and doesn't require a local Node.js installation.
You may provide either a MongoDB connection string OR Atlas API credentials:
Option A: No configuration
docker run --rm -i \
mongodb/mongodb-mcp-server:latest
Option B: With MongoDB connection string
# Set your credentials as environment variables first
export MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
# Then start the docker container
docker run --rm -i \
-e MDB_MCP_CONNECTION_STRING \
-e MDB_MCP_READ_ONLY="true" \
mongodb/mongodb-mcp-server:latest
💡 Platform Note: The examples above use Unix/Linux/macOS syntax. For Windows users, see Environment Variables for platform-specific instructions.
Option C: With Atlas API credentials
# Set your credentials as environment variables first
export MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
export MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
# Then start the docker container
docker run --rm -i \
-e MDB_MCP_API_CLIENT_ID \
-e MDB_MCP_API_CLIENT_SECRET \
-e MDB_MCP_READ_ONLY="true" \
mongodb/mongodb-mcp-server:latest
💡 Platform Note: The examples above use Unix/Linux/macOS syntax. For Windows users, see Environment Variables for platform-specific instructions.
Docker in MCP Configuration File
Without options:
{
"mcpServers": {
"MongoDB": {
"command": "docker",
"args": [
"run",
"--rm",
"-e",
"MDB_MCP_READ_ONLY=true",
"-i",
"mongodb/mongodb-mcp-server:latest"
]
}
}
}
With connection string:
{
"mcpServers": {
"MongoDB": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
"MDB_MCP_CONNECTION_STRING",
"-e",
"MDB_MCP_READ_ONLY=true",
"mongodb/mongodb-mcp-server:latest"
],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
}
}
}
}
With Atlas API credentials:
{
"mcpServers": {
"MongoDB": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
"MDB_MCP_READ_ONLY=true",
"-e",
"MDB_MCP_API_CLIENT_ID",
"-e",
"MDB_MCP_API_CLIENT_SECRET",
"mongodb/mongodb-mcp-server:latest"
],
"env": {
"MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
}
}
}
}
⚠️ Security Notice: This server now supports Streamable HTTP transport for remote connections. HTTP transport is NOT recommended for production use without implementing proper authentication and security measures.
Suggested Security Measures Examples:
For more details, see MCP Security Best Practices.
You can run the MongoDB MCP Server as an HTTP server instead of the default stdio transport. This is useful if you want to interact with the server over HTTP, for example from a web client or to expose the server on a specific port.
To start the server with HTTP transport, use the --transport http option:
npx -y mongodb-mcp-server@latest --transport http
By default, the server will listen on http://127.0.0.1:3000. You can customize the host and port using the --httpHost and --httpPort options:
npx -y mongodb-mcp-server@latest --transport http --httpHost=0.0.0.0 --httpPort=8080
--httpHost (default: 127.0.0.1): The host to bind the HTTP server.--httpPort (default: 3000): The port number for the HTTP server.Note: The default transport is
stdio, which is suitable for integration with most MCP clients. Usehttptransport if you need to interact with the server over HTTP.
atlas-list-orgs - Lists MongoDB Atlas organizationsatlas-list-projects - Lists MongoDB Atlas projectsatlas-create-project - Creates a new MongoDB Atlas projectatlas-list-clusters - Lists MongoDB Atlas clustersatlas-inspect-cluster - Inspect a specific MongoDB Atlas clusteratlas-create-free-cluster - Create a free MongoDB Atlas clusteratlas-connect-cluster - Connects to MongoDB Atlas clusteratlas-inspect-access-list - Inspect IP/CIDR ranges with access to MongoDB Atlas clustersatlas-create-access-list - Configure IP/CIDR access list for MongoDB Atlas clustersatlas-list-db-users - List MongoDB Atlas database usersatlas-create-db-user - Creates a MongoDB Atlas database useratlas-list-alerts - List MongoDB Atlas Alerts for a ProjectNOTE: atlas tools are only available when you set credentials on configuration section.
connect - Connect to a MongoDB instancefind - Run a find query against a MongoDB collectionaggregate - Run an aggregation against a MongoDB collectioncount - Get the number of documents in a MongoDB collectioninsert-one - Insert a single document into a MongoDB collectioninsert-many - Insert multiple documents into a MongoDB collectioncreate-index - Create an index for a MongoDB collectionupdate-one - Update a single document in a MongoDB collectionupdate-many - Update multiple documents in a MongoDB collectionrename-collection - Rename a MongoDB collectiondelete-one - Delete a single document from a MongoDB collectiondelete-many - Delete multiple documents from a MongoDB collectiondrop-collection - Remove a collection from a MongoDB databasedrop-database - Remove a MongoDB databaselist-databases - List all databases for a MongoDB connectionlist-collections - List all collections for a given databasecollection-indexes - Describe the indexes for a collectioncollection-schema - Describe the schema for a collectioncollection-storage-size - Get the size of a collection in MBdb-stats - Return statistics about a MongoDB databaseexport - Export query or aggregation results to EJSON format. Creates a uniquely named export accessible via the exported-data resource.config - Server configuration, supplied by the user either as environment variables or as startup arguments with sensitive parameters redacted. The resource can be accessed under URI config://config.debug - Debugging information for MongoDB connectivity issues. Tracks the last connectivity attempt and error information. The resource can be accessed under URI debug://mongodb.exported-data - A resource template to access the data exported using the export tool. The template can be accessed under URI exported-data://{exportName} where exportName is the unique name for an export generated by the export tool.🔒 Security Best Practice: We strongly recommend using environment variables for sensitive configuration such as API credentials (
MDB_MCP_API_CLIENT_ID,MDB_MCP_API_CLIENT_SECRET) and connection strings (MDB_MCP_CONNECTION_STRING) instead of command-line arguments. Environment variables are not visible in process lists and provide better security for your sensitive data.
The MongoDB MCP Server can be configured using multiple methods, with the following precedence (highest to lowest):
| CLI Option | Environment Variable | Default | Description |
|---|---|---|---|
apiClientId |
MDB_MCP_API_CLIENT_ID |
Atlas API client ID for authentication. Required for running Atlas tools. | |
apiClientSecret |
MDB_MCP_API_CLIENT_SECRET |
Atlas API client secret for authentication. Required for running Atlas tools. | |
connectionString |
MDB_MCP_CONNECTION_STRING |
MongoDB connection string for direct database connections. Optional, if not set, you'll need to call the connect tool before interacting with MongoDB data. |
|
loggers |
MDB_MCP_LOGGERS |
disk,mcp | Comma separated values, possible values are mcp, disk and stderr. See Logger Options for details. |
logPath |
MDB_MCP_LOG_PATH |
see note* | Folder to store logs. |
disabledTools |
MDB_MCP_DISABLED_TOOLS |
An array of tool names, operation types, and/or categories of tools that will be disabled. | |
confirmationRequiredTools |
MDB_MCP_CONFIRMATION_REQUIRED_TOOLS |
create-access-list,create-db-user,drop-database,drop-collection,delete-many | An array of tool names that require user confirmation before execution. Requires the client to support elicitation. |
readOnly |
MDB_MCP_READ_ONLY |
false | When set to true, only allows read, connect, and metadata operation types, disabling create/update/delete operations. |
indexCheck |
MDB_MCP_INDEX_CHECK |
false | When set to true, enforces that query operations must use an index, rejecting queries that perform a collection scan. |
telemetry |
MDB_MCP_TELEMETRY |
enabled | When set to disabled, disables telemetry collection. |
transport |
MDB_MCP_TRANSPORT |
stdio | Either 'stdio' or 'http'. |
httpPort |
MDB_MCP_HTTP_PORT |
3000 | Port number. |
httpHost |
MDB_MCP_HTTP_HOST |
127.0.0.1 | Host to bind the http server. |
idleTimeoutMs |
MDB_MCP_IDLE_TIMEOUT_MS |
600000 | Idle timeout for a client to disconnect (only applies to http transport). |
notificationTimeoutMs |
MDB_MCP_NOTIFICATION_TIMEOUT_MS |
540000 | Notification timeout for a client to be aware of diconnect (only applies to http transport). |
exportsPath |
MDB_MCP_EXPORTS_PATH |
see note* | Folder to store exported data files. |
exportTimeoutMs |
MDB_MCP_EXPORT_TIMEOUT_MS |
300000 | Time in milliseconds after which an export is considered expired and eligible for cleanup. |
exportCleanupIntervalMs |
MDB_MCP_EXPORT_CLEANUP_INTERVAL_MS |
120000 | Time in milliseconds between export cleanup cycles that remove expired export files. |
atlasTemporaryDatabaseUserLifetimeMs |
MDB_MCP_ATLAS_TEMPORARY_DATABASE_USER_LIFETIME_MS |
14400000 | Time in milliseconds that temporary database users created when connecting to MongoDB Atlas clusters will remain active before being automatically deleted. |
The loggers configuration option controls where logs are sent. You can specify one or more logger types as a comma-separated list. The available options are:
mcp: Sends logs to the MCP client (if supported by the client/transport).disk: Writes logs to disk files. Log files are stored in the log path (see logPath above).stderr: Outputs logs to standard error (stderr), useful for debugging or when running in containers.Default: disk,mcp (logs are written to disk and sent to the MCP client).
You can combine multiple loggers, e.g. --loggers disk stderr or export MDB_MCP_LOGGERS="mcp,stderr".
Example: Set logger via environment variable
export MDB_MCP_LOGGERS="disk,stderr"
💡 Platform Note: For Windows users, see Environment Variables for platform-specific instructions.
Example: Set logger via command-line argument
npx -y mongodb-mcp-server@latest --loggers mcp stderr
Log File Location
When using the disk logger, log files are stored in:
%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs~/.mongodb/mongodb-mcp/.app-logsYou can override the log directory with the logPath option.
You can disable specific tools or categories of tools by using the disabledTools option. This option accepts an array of strings,
where each string can be a tool name, operation type, or category.
The way the array is constructed depends on the type of configuration method you use:
export MDB_MCP_DISABLED_TOOLS="create,update,delete,atlas,collectionSchema".--disabledTools create update delete atlas collectionSchema.Categories of tools:
atlas - MongoDB Atlas tools, such as list clusters, create cluster, etc.mongodb - MongoDB database tools, such as find, aggregate, etc.Operation types:
create - Tools that create resources, such as create cluster, insert document, etc.update - Tools that update resources, such as update document, rename collection, etc.delete - Tools that delete resources, such as delete document, drop collection, etc.read - Tools that read resources, such as find, aggregate, list clusters, etc.metadata - Tools that read metadata, such as list databases, list collections, collection schema, etc.connect - Tools that allow you to connect or switch the connection to a MongoDB instance. If this is disabled, you will need to provide a connection string through the config when starting the server.If your client supports elicitation, you can set the MongoDB MCP server to request user confirmation before executing certain tools.
When a tool is marked as requiring confirmation, the server will send an elicitation request to the client. The client with elicitation support will then prompt the user for confirmation and send the response back to the server. If the client does not support elicitation, the tool will execute without confirmation.
You can set the confirmationRequiredTools configuration option to specify the names of tools which require confirmation. By default, the following tools have this setting enabled: drop-database, drop-collection, delete-many, atlas-create-db-user, atlas-create-access-list.
The readOnly configuration option allows you to restrict the MCP server to only use tools with "read", "connect", and "metadata" operation types. When enabled, all tools that have "create", "update" or "delete" operation types will not be registered with the server.
This is useful for scenarios where you want to provide access to MongoDB data for analysis without allowing any modifications to the data or infrastructure.
You can enable read-only mode using:
export MDB_MCP_READ_ONLY=true--readOnly💡 Platform Note: For Windows users, see Environment Variables for platform-specific instructions.
When read-only mode is active, you'll see a message in the server logs indicating which tools were prevented from registering due to this restriction.
The indexCheck configuration option allows you to enforce that query operations must use an index. When enabled, queries that perform a collection scan will be rejected to ensure better performance.
This is useful for scenarios where you want to ensure that database queries are optimized.
You can enable index check mode using:
export MDB_MCP_INDEX_CHECK=true--indexCheck💡 Platform Note: For Windows users, see Environment Variables for platform-specific instructions.
When index check mode is active, you'll see an error message if a query is rejected due to not using an index.
The data exported by the export tool is temporarily stored in the configured exportsPath on the machine running the MCP server until cleaned up by the export cleanup process. If the exportsPath configuration is not provided, the following defaults are used:
%LOCALAPPDATA%\mongodb\mongodb-mcp\exports~/.mongodb/mongodb-mcp/exportsThe exportTimeoutMs configuration controls the time after which the exported data is considered expired and eligible for cleanup. By default, exports expire after 5 minutes (300000ms).
The exportCleanupIntervalMs configuration controls how frequently the cleanup process runs to remove expired export files. By default, cleanup runs every 2 minutes (120000ms).
The telemetry configuration option allows you to disable telemetry collection. When enabled, the MCP server will collect usage data and send it to MongoDB.
You can disable telemetry using:
export MDB_MCP_TELEMETRY=disabled--telemetry disabledexport DO_NOT_TRACK=1💡 Platform Note: For Windows users, see Environment Variables for platform-specific instructions.
To use the Atlas API tools, you'll need to create a service account in MongoDB Atlas:
ℹ️ Note: For a detailed breakdown of the minimum required permissions for each Atlas operation, see the Atlas API Permissions section below.
To learn more about Service Accounts, check the MongoDB Atlas documentation.
Save Client Credentials:
Add Access List Entry:
Configure the MCP Server:
apiClientId and apiClientSecretSecurity Warning: Granting the Organization Owner role is rarely necessary and can be a security risk. Assign only the minimum permissions needed for your use case.
| What you want to do | Safest Role to Assign (where) |
|---|---|
| List orgs/projects | Org Member or Org Read Only (Org) |
| Create new projects | Org Project Creator (Org) |
| View clusters/databases in a project | Project Read Only (Project) |
| Create/manage clusters in a project | Project Cluster Manager (Project) |
| Manage project access lists | Project IP Access List Admin (Project) |
| Manage database users | Project Database Access Admin (Project) |
For a full list of roles and their privileges, see the Atlas User Roles documentation.
Set environment variables with the prefix MDB_MCP_ followed by the option name in uppercase with underscores:
Linux/macOS (bash/zsh):
# Set Atlas API credentials (via Service Accounts)
export MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
export MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
# Set a custom MongoDB connection string
export MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
# Set log path
export MDB_MCP_LOG_PATH="/path/to/logs"
Windows Command Prompt (cmd):
set "MDB_MCP_API_CLIENT_ID=your-atlas-service-accounts-client-id"
set "MDB_MCP_API_CLIENT_SECRET=your-atlas-service-accounts-client-secret"
set "MDB_MCP_CONNECTION_STRING=mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
set "MDB_MCP_LOG_PATH=C:\path\to\logs"
Windows PowerShell:
# Set Atlas API credentials (via Service Accounts)
$env:MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
$env:MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
# Set a custom MongoDB connection string
$env:MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
# Set log path
$env:MDB_MCP_LOG_PATH="C:\path\to\logs"
Connection String with environment variables
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server"],
"env": {
"MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
}
}
}
}
Atlas API credentials with environment variables
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": ["-y", "mongodb-mcp-server"],
"env": {
"MDB_MCP_API_CLIENT_ID": "your-atlas-service-accounts-client-id",
"MDB_MCP_API_CLIENT_SECRET": "your-atlas-service-accounts-client-secret"
}
}
}
}
Pass configuration options as command-line arguments when starting the server:
🔒 Security Note: For sensitive configuration like API credentials and connection strings, use environment variables instead of command-line arguments.
# Set sensitive data as environment variable
export MDB_MCP_API_CLIENT_ID="your-atlas-service-accounts-client-id"
export MDB_MCP_API_CLIENT_SECRET="your-atlas-service-accounts-client-secret"
export MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase"
# Start the server with command line arguments
npx -y mongodb-mcp-server@latest --logPath=/path/to/logs --readOnly --indexCheck
💡 Platform Note: The examples above use Unix/Linux/macOS syntax. For Windows users, see Environment Variables for platform-specific instructions.
Connection String with command-line arguments
🔒 Security Note: We do not recommend passing connection string as command line argument. Connection string might contain credentials which can be visible in process lists and logged in various system locations, potentially exposing your credentials. Instead configure connection string through environment variables
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server",
"--connectionString",
"mongodb+srv://username:password@cluster.mongodb.net/myDatabase",
"--readOnly"
]
}
}
}
Atlas API credentials with command-line arguments
🔒 Security Note: We do not recommend passing Atlas API credentials as command line argument. The provided credentials can be visible in process lists and logged in various system locations, potentially exposing your credentials. Instead configure Atlas API credentials through environment variables
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server",
"--apiClientId",
"your-atlas-service-accounts-client-id",
"--apiClientSecret",
"your-atlas-service-accounts-client-secret",
"--readOnly"
]
}
}
}
The MCP Server will detect typical PROXY environment variables and use them for
connecting to the Atlas API, your MongoDB Cluster, or any other external calls
to third-party services like OID Providers. The behaviour is the same as what
mongosh does, so the same settings will work in the MCP Server.
Interested in contributing? Great! Please check our Contributing Guide for guidelines on code contributions, standards, adding new tools, and troubleshooting information.
Please log in to share your review and rating for this MCP.
{
"mcpServers": {
"MongoDB": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server"
],
"env": {
"MDB_MCP_CONNECTION_STRING": "<YOUR_CONNECTION_STRING>"
}
}
}
}claude mcp add MongoDB npx -y mongodb-mcp-serverExplore related MCPs that share similar capabilities and solve comparable challenges
by googleapis
An MCP server that streamlines database tool development by handling connection pooling, authentication, observability, and secure access, allowing agents to interact with databases via natural language.
by bytebase
Provides a universal gateway that lets MCP‑compatible clients explore and query MySQL, PostgreSQL, SQL Server, MariaDB, and SQLite databases through a single standardized interface.
by designcomputer
Enables secure interaction with MySQL databases via the Model Context Protocol, allowing AI applications to list tables, read contents, and execute queries safely.
by benborla
Provides read‑only access to MySQL databases for large language models, allowing schema inspection and safe execution of SQL queries.
by neo4j-contrib
Enables natural‑language interaction with Neo4j databases, allowing large language models to query, modify, and manage graph data through multiple transport modes.
by ClickHouse
Enables AI assistants to run read‑only ClickHouse queries, list databases and tables, and execute embedded chDB queries through an MCP interface.
by neondatabase
Interact with Neon Postgres databases using natural language commands through the Model Context Protocol, enabling conversational database creation, migration, and query execution.
by motherduckdb
Enables SQL analytics on DuckDB and MotherDuck databases via a Model Context Protocol server, allowing AI assistants and IDEs to query data directly.
by chroma-core
Offers an MCP server exposing Chroma's vector database capabilities for LLM applications, supporting collection and document management, multiple embedding functions, and flexible client types such as in‑memory, persistent, HTTP, and cloud.