MongoDB MCP Server

by taki-ta

Not rated
GitHub

About

A server for interacting with MongoDB databases and MongoDB Atlas.

Details

Author
taki-ta
Categories
Database, Other

Option 4 Standalone Service Using Environment Variables

You can use environment variables in the config file or set them and run the server via npx.

- Connection String via environment variables in the MCP file](#atlas-api-access)example
- Atlas API credentials via environment variables in the MCP file
example

- atlas-list-orgs- Lists MongoDB Atlas organizations
- atlas-list-projects- Lists MongoDB Atlas projects
- atlas-create-project- Creates a new MongoDB Atlas project
- atlas-list-clusters- Lists MongoDB Atlas clusters
- atlas-inspect-cluster- Inspect a specific MongoDB Atlas cluster
- atlas-create-free-cluster- Create a free MongoDB Atlas cluster
- atlas-connect-cluster- Connects to MongoDB Atlas cluster
- atlas-inspect-access-list- Inspect IP/CIDR ranges with access to MongoDB Atlas clusters
- atlas-create-access-list- Configure IP/CIDR access list for MongoDB Atlas clusters
- atlas-list-db-users- List MongoDB Atlas database users
- atlas-create-db-user- List MongoDB Atlas database users

NOTE: atlas tools are only available when you set credentials onconfigurationsection.

- connect- Connect to a MongoDB instance
- find- Run a find query against a MongoDB collection
- aggregate- Run an aggregation against a MongoDB collection
- count- Get the number of documents in a MongoDB collection
- insert-one- Insert a single document into a MongoDB collection
- insert-many- Insert multiple documents into a MongoDB collection
- create-index- Create an index for a MongoDB collection
- update-one- Update a single document in a MongoDB collection
- update-many- Update multiple documents in a MongoDB collection
- rename-collection- Rename a MongoDB collection
- delete-one- Delete a single document from a MongoDB collection
- delete-many- Delete multiple documents from a MongoDB collection
- drop-collection- Remove a collection from a MongoDB database
- drop-database- Remove a MongoDB database
- list-databases- List all databases for a MongoDB connection
- list-collections- List all collections for a given database
- collection-indexes- Describe the indexes for a collection
- collection-schema- Describe the schema for a collection
- collection-storage-size- Get the size of a collection in MB
- db-stats- Return statistics about a MongoDB database

The MongoDB MCP Server can be configured using multiple methods, with the following precedence (highest to lowest):
- Command-line arguments
- Environment variables

- Windows:%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs
- macOS/Linux:~/.mongodb/mongodb-mcp/.app-logs

You can disable specific tools or categories of tools by using thedisabledToolsoption. 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:

- Forenvironment variableconfiguration, use a comma-separated string:export MDB_MCP_DISABLED_TOOLS="create,update,delete,atlas,collectionSchema".
- Forcommand-line argumentconfiguration, use a space-separated string:--disabledTools create update delete atlas collectionSchema.

- atlas- MongoDB Atlas tools, such as list clusters, create cluster, etc.
- mongodb- MongoDB database tools, such as find, aggregate, etc.

- 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.

ThereadOnlyconfiguration option allows you to restrict the MCP server to only use tools with "read" 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.

- Environment variable:export MDB_MCP_READ_ONLY=true
- Command-line argument:--readOnly

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.

ThedefaultDatabaseconfiguration option allows you to restrict the MCP server to operate only on a specific database. When configured, all database tools will use the specified database by default, and thelist-databasestool is disabled to prevent discovery of other databases.

This is useful for scenarios where you want to limit access to a specific database for security or operational reasons.

- Environment variable:export MDB_DB=ChatBIorexport MDB_MCP_DEFAULT_DATABASE=ChatBI
- Command-line argument:--database ChatBI
- Docker environment variable:-e MDB_DB=ChatBI

- All database operations will use this database unless explicitly overridden in the tool arguments
- Thelist-databasestool is disabled to prevent database discovery
- Users can still specify a different database name in individual tool calls if needed

Thetelemetryconfiguration option allows you to disable telemetry collection. When enabled, the MCP server will collect usage data and send it to MongoDB.

- Environment variable:export MDB_MCP_TELEMETRY=disabled
- Command-line argument:--telemetry disabled
- DO_NOT_TRACK environment variable:export DO_NOT_TRACK=1

To use the Atlas API tools, you'll need to create a service account in MongoDB Atlas:

- Log in to MongoDB Atlas atcloud.mongodb.com
- Navigate to Access Manager > Organization Access
- Click Add New > Applications > Service Accounts
- Enter name, description and expiration for your service account (e.g., "MCP, MCP Server Access, 7 days")
- Select appropriate permissions (for full access, use Organization Owner)
- Click "Create"

To learn more about Service Accounts, check theMongoDB Atlas documentation.

- After creation, you'll be shown the Client ID and Client Secret
- Important:Copy and save the Client Secret immediately as it won't be displayed again

- Add your IP address to the API access list

- Use one of the configuration methods below to set yourapiClientIdandapiClientSecret

Set environment variables with the prefixMDB_MCP_followed by the option name in uppercase with underscores:

# 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 default database for operations (limits MCP to only use this database) export MDB_MCP_DEFAULT_DATABASE="ChatBI" # Or alternatively, use the shorter form: export MDB_DB="ChatBI" export MDB_MCP_LOG_PATH="/path/to/logs"
{ "mcpServers": { "MongoDB": { "command": "npx", "args": ["-y", "mongodb-mcp-server"], "env": { "MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:password@cluster.mongodb.net/myDatabase" } } } }
{ "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:

npx -y mongodb-mcp-server --apiClientId="your-atlas-service-accounts-client-id" --apiClientSecret="your-atlas-service-accounts-client-secret" --connectionString="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" --database="ChatBI" --logPath=/path/to/logs
{ "mcpServers": { "MongoDB": { "command": "npx", "args": [ "-y", "mongodb-mcp-server", "--connectionString", "mongodb+srv://username:password@cluster.mongodb.net/myDatabase" ] } } }
{ "mcpServers": { "MongoDB": { "command": "npx", "args": [ "-y", "mongodb-mcp-server", "--apiClientId", "your-atlas-service-accounts-client-id", "--apiClientSecret", "your-atlas-service-accounts-client-secret" ] } } }

Interested in contributing? Great! Please check ourContributing Guidefor guidelines on code contributions, standards, adding new tools, and troubleshooting information.

Interact with MongoDB databases and MongoDB Atlas.

Update various databases (PostgreSQL, MySQL, MongoDB, SQLite) using data from CSV and Excel files.

Connects to and interacts with various database systems like SQLite, PostgreSQL, SQL Server, and MongoDB.

An MCP server that enables LLMs to interact with databases like MongoDB using natural language.

Interact with MongoDB databases using natural language to query collections, inspect schemas, and manage data.

Interact with MongoDB databases using natural language. Query collections, inspect schemas, and manage data.

Provides read-only access to MongoDB databases through standardized MCP tools and resources.

An MCP server providing tools and prompts for interacting with a MongoDB database.

A server for performing CRUD operations on a MongoDB database.

An MCP server for MongoDB with optional Mongoose schema support.

A Model Context Protocol server for interacting with MongoDB Databases and MongoDB Atlas.

- 🚀 Getting Started

- Prerequisites
-
Setup

- Quick Start

- MongoDB Atlas Tools
-
MongoDB Database Tools

- Configuration Options
-
Atlas API Access
-
Configuration Methods

- Environment Variables
-
Command-Line Arguments
-
MCP Client Configuration

- A MongoDB connection string or Atlas API credentials,the Server will not start unless configured.

- Service Accounts Atlas API credentialsare required to use the Atlas tools. You can create a service account in MongoDB Atlas and use its credentials for authentication. SeeAtlas API Accessfor more details.
- If you have a MongoDB connection string, you can use it directly to connect to your MongoDB instance.

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:

- Windsurf:https://docs.windsurf.com/windsurf/mcp
- VSCode:
https://code.visualstudio.com/docs/copilot/chat/mcp-servers
- Claude Desktop:
https://modelcontextprotocol.io/quickstart/user
- Cursor:
https://docs.cursor.com/context/model-context-protocol
- 访问
GitHub Actions页面
- 选择最新的构建运行记录
- 在 "Artifacts" 部分下载mongodb-mcp-server-{version}-amd64.tar.gz

# 解压并加载镜像 gunzip mongodb-mcp-server-{version}-amd64.tar.gz docker load -i mongodb-mcp-server-{version}-amd64.tar # 运行容器 docker run -d -p 8000:8000 \ -e MDB_MCP_CONNECTION_STRING="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" \ -e MDB_DB="myDatabase" \ mongodb-mcp-server:latest # 或使用Atlas API凭据 docker run -d -p 8000:8000 \ -e MDB_MCP_API_CLIENT_ID="your-client-id" \ -e MDB_MCP_API_CLIENT_SECRET="your-client-secret" \ mongodb-mcp-server:latest

- PORT: 服务端口 (默认: 8000)
- MDB_MCP_CONNECTION_STRING: MongoDB连接字符串
- MDB_DB: 默认数据库名称 (默认: ChatBI)
- MDB_MCP_API_CLIENT_ID: Atlas API客户端ID
- MDB_MCP_API_CLIENT_SECRET: Atlas API客户端密钥

You can pass your connection string via args, make sure to use a valid username and password.

{ "mcpServers": { "MongoDB": { "command": "npx", "args": [ "-y", "mongodb-mcp-server", "--connectionString", "mongodb+srv://username:password@cluster.mongodb.net/myDatabase" ] } } }

Use your Atlas API Service Accounts credentials. Must follow all the steps inAtlas API Accesssection.

{ "mcpServers": { "MongoDB": { "command": "npx", "args": [ "-y", "mongodb-mcp-server", "--apiClientId", "your-atlas-service-accounts-client-id", "--apiClientSecret", "your-atlas-service-accounts-client-secret" ] } } }

Option 3: Standalone Service using command arguments

npx -y mongodb-mcp-server --apiClientId="your-atlas-service-accounts-client-id" --apiClientSecret="your-atlas-service-accounts-client-secret"

- For a complete list of arguments seeConfiguration Options
- To configure your Atlas Service Accounts credentials please refer to
Atlas API Access

Option 4: Standalone Service using environment variables

You can use environment variables in the config file or set them and run the server via npx.

- Connection String via environment variables in the MCP fileexample
- Atlas API credentials via environment variables in the MCP file
example

- atlas-list-orgs- Lists MongoDB Atlas organizations
- atlas-list-projects- Lists MongoDB Atlas projects
- atlas-create-project- Creates a new MongoDB Atlas project
- atlas-list-clusters- Lists MongoDB Atlas clusters
- atlas-inspect-cluster- Inspect a specific MongoDB Atlas cluster
- atlas-create-free-cluster- Create a free MongoDB Atlas cluster
- atlas-connect-cluster- Connects to MongoDB Atlas cluster
- atlas-inspect-access-list- Inspect IP/CIDR ranges with access to MongoDB Atlas clusters
- atlas-create-access-list- Configure IP/CIDR access list for MongoDB Atlas clusters
- atlas-list-db-users- List MongoDB Atlas database users
- atlas-create-db-user- List MongoDB Atlas database users

NOTE: atlas tools are only available when you set credentials onconfigurationsection.

- connect- Connect to a MongoDB instance
- find- Run a find query against a MongoDB collection
- aggregate- Run an aggregation against a MongoDB collection
- count- Get the number of documents in a MongoDB collection
- insert-one- Insert a single document into a MongoDB collection
- insert-many- Insert multiple documents into a MongoDB collection
- create-index- Create an index for a MongoDB collection
- update-one- Update a single document in a MongoDB collection
- update-many- Update multiple documents in a MongoDB collection
- rename-collection- Rename a MongoDB collection
- delete-one- Delete a single document from a MongoDB collection
- delete-many- Delete multiple documents from a MongoDB collection
- drop-collection- Remove a collection from a MongoDB database
- drop-database- Remove a MongoDB database
- list-databases- List all databases for a MongoDB connection
- list-collections- List all collections for a given database
- collection-indexes- Describe the indexes for a collection
- collection-schema- Describe the schema for a collection
- collection-storage-size- Get the size of a collection in MB
- db-stats- Return statistics about a MongoDB database

The MongoDB MCP Server can be configured using multiple methods, with the following precedence (highest to lowest):
- Command-line arguments
- Environment variables

- Windows:%LOCALAPPDATA%\mongodb\mongodb-mcp\.app-logs
- macOS/Linux:~/.mongodb/mongodb-mcp/.app-logs

You can disable specific tools or categories of tools by using thedisabledToolsoption. 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:

- Forenvironment variableconfiguration, use a comma-separated string:export MDB_MCP_DISABLED_TOOLS="create,update,delete,atlas,collectionSchema".
- Forcommand-line argumentconfiguration, use a space-separated string:--disabledTools create update delete atlas collectionSchema.

- atlas- MongoDB Atlas tools, such as list clusters, create cluster, etc.
- mongodb- MongoDB database tools, such as find, aggregate, etc.

- 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.

ThereadOnlyconfiguration option allows you to restrict the MCP server to only use tools with "read" 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.

- Environment variable:export MDB_MCP_READ_ONLY=true
- Command-line argument:--readOnly

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.

ThedefaultDatabaseconfiguration option allows you to restrict the MCP server to operate only on a specific database. When configured, all database tools will use the specified database by default, and thelist-databasestool is disabled to prevent discovery of other databases.

This is useful for scenarios where you want to limit access to a specific database for security or operational reasons.

- Environment variable:export MDB_DB=ChatBIorexport MDB_MCP_DEFAULT_DATABASE=ChatBI
- Command-line argument:--database ChatBI
- Docker environment variable:-e MDB_DB=ChatBI

- All database operations will use this database unless explicitly overridden in the tool arguments
- Thelist-databasestool is disabled to prevent database discovery
- Users can still specify a different database name in individual tool calls if needed

Thetelemetryconfiguration option allows you to disable telemetry collection. When enabled, the MCP server will collect usage data and send it to MongoDB.

- Environment variable:export MDB_MCP_TELEMETRY=disabled
- Command-line argument:--telemetry disabled
- DO_NOT_TRACK environment variable:export DO_NOT_TRACK=1

To use the Atlas API tools, you'll need to create a service account in MongoDB Atlas:

- Log in to MongoDB Atlas atcloud.mongodb.com
- Navigate to Access Manager > Organization Access
- Click Add New > Applications > Service Accounts
- Enter name, description and expiration for your service account (e.g., "MCP, MCP Server Access, 7 days")
- Select appropriate permissions (for full access, use Organization Owner)
- Click "Create"

To learn more about Service Accounts, check theMongoDB Atlas documentation.

- After creation, you'll be shown the Client ID and Client Secret
- Important:Copy and save the Client Secret immediately as it won't be displayed again

- Add your IP address to the API access list

- Use one of the configuration methods below to set yourapiClientIdandapiClientSecret

Set environment variables with the prefixMDB_MCP_followed by the option name in uppercase with underscores:

# 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 default database for operations (limits MCP to only use this database) export MDB_MCP_DEFAULT_DATABASE="ChatBI" # Or alternatively, use the shorter form: export MDB_DB="ChatBI" export MDB_MCP_LOG_PATH="/path/to/logs"
{ "mcpServers": { "MongoDB": { "command": "npx", "args": ["-y", "mongodb-mcp-server"], "env": { "MDB_MCP_CONNECTION_STRING": "mongodb+srv://username:password@cluster.mongodb.net/myDatabase" } } } }
{ "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:

npx -y mongodb-mcp-server --apiClientId="your-atlas-service-accounts-client-id" --apiClientSecret="your-atlas-service-accounts-client-secret" --connectionString="mongodb+srv://username:password@cluster.mongodb.net/myDatabase" --database="ChatBI" --logPath=/path/to/logs
{ "mcpServers": { "MongoDB": { "command": "npx", "args": [ "-y", "mongodb-mcp-server", "--connectionString", "mongodb+srv://username:password@cluster.mongodb.net/myDatabase" ] } } }
{ "mcpServers": { "MongoDB": { "command": "npx", "args": [ "-y", "mongodb-mcp-server", "--apiClientId", "your-atlas-service-accounts-client-id", "--apiClientSecret", "your-atlas-service-accounts-client-secret" ] } } }

Interested in contributing? Great! Please check ourContributing Guidefor guidelines on code contributions, standards, adding new tools, and troubleshooting information.

Interact with MongoDB databases and MongoDB Atlas.

Update various databases (PostgreSQL, MySQL, MongoDB, SQLite) using data from CSV and Excel files.

Connects to and interacts with various database systems like SQLite, PostgreSQL, SQL Server, and MongoDB.

An MCP server that enables LLMs to interact with databases like MongoDB using natural language.

Interact with MongoDB databases using natural language to query collections, inspect schemas, and manage data.

Interact with MongoDB databases using natural language. Query collections, inspect schemas, and manage data.

Provides read-only access to MongoDB databases through standardized MCP tools and resources.

An MCP server providing tools and prompts for interacting with a MongoDB database.

A server for performing CRUD operations on a MongoDB database.

An MCP server for MongoDB with optional Mongoose schema support.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.