Add the MongoDB MCP server to Claude Code
Config last verified Jun 1, 2026
The exact config to run MongoDB in Claude Code — paste it in, restart, and the tools load.
Prerequisites
- Claude Code installed.
Setup
1. Open ~/.claude.json
2. Add this configuration
Add to ~/.claude.json
~/.claude.json
json
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"mongodb-mcp-server@latest",
"--readOnly"
],
"env": {
"MDB_MCP_CONNECTION_STRING": "<MDB_MCP_CONNECTION_STRING>"
}
}
}
}Or via CLI
bash
claude mcp add mongodb -- npx -y mongodb-mcp-server@latest --readOnly3. Restart Claude Code and confirm the MongoDB tools load.
Gotchas
Claude Code stores MCP servers under an "mcpServers" object in ~/.claude.json. It also reads a project-scoped .mcp.json and supports adding servers from the command line with "claude mcp add". Each entry must declare either a "type" or a "command"; Claude Code refuses an entry that has neither. Remote servers connect natively over Streamable HTTP with OAuth.