MongoDB MCP server
MongoDB's official server for querying and inspecting MongoDB databases, with optional MongoDB Atlas management tools. This example runs read-only through npx with a connection string.
Local (stdio)Credential
Set up MongoDB
Configuration examples, not tested connections. Replace placeholders and review the upstream documentation before use.
Claude Code
Run in your terminal.
claude mcp add mongodb --env MDB_MCP_CONNECTION_STRING="$MDB_MCP_CONNECTION_STRING" -- npx -y mongodb-mcp-server@latest --readOnly
Cursor
Merge into ~/.cursor/mcp.json
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server@latest",
"--readOnly"
],
"env": {
"MDB_MCP_CONNECTION_STRING": "REPLACE_WITH_MDB_MCP_CONNECTION_STRING"
}
}
}
}
Codex
Run in your terminal.
codex mcp add mongodb --env MDB_MCP_CONNECTION_STRING="$MDB_MCP_CONNECTION_STRING" -- npx -y mongodb-mcp-server@latest --readOnly
Gemini CLI
Merge into ~/.gemini/settings.json
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server@latest",
"--readOnly"
],
"env": {
"MDB_MCP_CONNECTION_STRING": "REPLACE_WITH_MDB_MCP_CONNECTION_STRING"
}
}
}
}
OpenCode
Merge into ~/.config/opencode/opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mongodb": {
"type": "local",
"command": [
"npx",
"-y",
"mongodb-mcp-server@latest",
"--readOnly"
],
"enabled": true,
"environment": {
"MDB_MCP_CONNECTION_STRING": "REPLACE_WITH_MDB_MCP_CONNECTION_STRING"
}
}
}
}
VS Code
Merge into .vscode/mcp.json
{
"servers": {
"mongodb": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server@latest",
"--readOnly"
],
"env": {
"MDB_MCP_CONNECTION_STRING": "${input:MDB_MCP_CONNECTION_STRING}"
}
}
},
"inputs": [
{
"id": "MDB_MCP_CONNECTION_STRING",
"type": "promptString",
"description": "MDB_MCP_CONNECTION_STRING",
"password": true
}
]
}
Using more than one server?Add to a config with other servers
Step-by-step setup guides: Claude Code and Codex CLI, Cursor and VS Code. In Claude Desktop, the Cursor JSON goes in claude_desktop_config.json. This is a local server that runs on your machine; see remote vs local servers and authentication and security basics.
Overview
The MongoDB MCP Server is MongoDB's official implementation, maintained in mongodb-js/mongodb-mcp-server. Version 3.0.5 was released on 1 October 2026, and commits continued through October. It works with any MongoDB deployment you can reach, and it can also manage MongoDB Atlas when you give it Atlas API credentials.
For data work, list-databases, list-collections and collection-schema explore what exists. find, aggregate and count query it, and explain shows how a query will run. Other tools report collection indexes, storage size and database statistics. With Atlas service account credentials, a separate group of atlas- tools lists and creates clusters, projects, database users and access lists. When we started version 3.0.5 in read-only mode on 11 October 2026, it listed only the non-destructive database tools.
The example starts npx -y mongodb-mcp-server@latest --readOnly, which keeps the agent from writing, and reads the connection string from MDB_MCP_CONNECTION_STRING. That string usually contains a password, so keep it out of shared configuration and use a database user with only the access the task needs. Remove --readOnly only when you want the agent to insert or update data. For Atlas, MongoDB also offers a hosted Atlas MCP server over OAuth through its client plugins, and the README describes that path.
Example tools
list-databaseslist-collectionscollection-schemafindaggregatecount
Tool names are upstream examples. The server's live tool list can differ.
Related Database servers
Sources
This page was written from the upstream documentation below and last reviewed on 11 October 2026. Listing is not a security or compatibility endorsement. Report a correction through the contact page.