{"slug": "how-to-connect-mongodb-to-claude-code-codex-and-cursor", "title": "How to connect MongoDB to Claude Code, Codex and Cursor", "summary": "MongoDB's official `mongodb-mcp-server`, maintained in the mongodb-js/mongodb-mcp-server repository and verified in the official MCP Registry, can be connected to Claude Code, Codex and Cursor by adding it as an MCP server and supplying a connection string in the `MDB_MCP_CONNECTION_STRING` environment variable, letting the agent list databases, read collections, run queries and aggregations, and inspect indexes. The guide recommends starting with a read-only database user, such as Atlas's built-in \"Only read any database\" privilege, or pointing the agent at a staging cluster or local `mongodb://localhost:27017` before granting write access, and notes the server exposes over 50 `MDB_MCP_*` settings including options to disable tools or require confirmation. Atlas API credentials (`MDB_MCP_API_CLIENT_ID` and `MDB_MCP_API_CLIENT_SECRET`) additionally let the same server list projects and clusters, check access lists and create database users.", "body_md": "[Dev blog](https://calyban.com/blog) · [Guides](https://calyban.com/blog#guide) · 2026-11-28\n\n# How to connect MongoDB to Claude Code, Codex and Cursor\n\n**Short answer:** add MongoDB’s official MCP server, `mongodb-mcp-server`, to your agent and give it your connection string in the `MDB_MCP_CONNECTION_STRING` environment variable. In Claude Code that’s one command. The agent can then list databases, read collections, run queries and aggregations, and look at indexes.\n\nOr skip the config files: [Calyban](https://calyban.com/) installs the official MongoDB server into Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI and Claude Desktop in one click, asks for the connection string once, and can undo all of it. Free, no account.\n\nMongoDB publishes and maintains this server itself ([mongodb-js/mongodb-mcp-server](https://github.com/mongodb-js/mongodb-mcp-server)), and it’s verified in the official MCP Registry. Use it before any third-party one.\n\n## Claude Code\n\n```\nclaude mcp add mongodb \\\n  -e MDB_MCP_CONNECTION_STRING=\"mongodb+srv://user:pass@cluster0.example.mongodb.net/\" \\\n  -- npx -y mongodb-mcp-server\n```\n\nOn Windows, put `cmd /c` before `npx` (the reason is in [our Windows guide](https://calyban.com/blog/install-mcp-servers-windows)).\n\nThere’s also an official Claude Code plugin, `mongodb@claude-plugins-official`, which bundles the same server with MongoDB skills for query and schema work. If you live in Claude Code, the plugin is the richer option.\n\n## Codex\n\nCodex reads TOML. In `~/.codex/config.toml`:\n\n```\n[mcp_servers.mongodb]\ncommand = \"npx\"\nargs = [\"-y\", \"mongodb-mcp-server\"]\n\n[mcp_servers.mongodb.env]\nMDB_MCP_CONNECTION_STRING = \"mongodb+srv://user:pass@cluster0.example.mongodb.net/\"\n```\n\n## Cursor\n\nIn `~/.cursor/mcp.json` (or `.cursor/mcp.json` for one project):\n\n```\n{\n  \"mcpServers\": {\n    \"mongodb\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"mongodb-mcp-server\"],\n      \"env\": { \"MDB_MCP_CONNECTION_STRING\": \"mongodb+srv://user:pass@cluster0.example.mongodb.net/\" }\n    }\n  }\n}\n```\n\n## Keep it read-only first\n\nAn agent with write access to a production database is one confident mistake away from a bad afternoon. Two habits keep it safe:\n\n- **Use a read-only database user.** In Atlas, create a database user with the built-in “Only read any database” privilege (or a custom`read` role on just the databases you want the agent to see), and put that user in the connection string. The database enforces it, whatever the agent decides.\n- **Point it at a copy.** A staging cluster or a local`mongodb://localhost:27017` is the right place for an agent to try writes.\n\nThe server has a lot of switches (over 50 `MDB_MCP_*` settings, including ones to disable tools or require confirmation). The connection string is the only one you need to start.\n\n## Atlas admin, not just data\n\nWith Atlas API credentials (`MDB_MCP_API_CLIENT_ID` and `MDB_MCP_API_CLIENT_SECRET`), the same server can also manage Atlas itself: list projects and clusters, check access lists, create database users. Skip those two variables if you only want the agent near your data.\n\n## The Calyban way\n\nSearch “mongodb” in Calyban and open [mongodb-mcp-server](https://calyban.com/mcp/io-github-mongodb-js-mongodb-mcp-server). Press **Install**, tick the agents that should have it (Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Claude Desktop), and paste the connection string when it asks. Calyban writes each agent’s file in its own format, with `cmd /c` on Windows, and checks the `npx` package against the OpenSSF malicious-packages list before anything runs. Updating to a new version keeps your connection string, and **Undo** puts every file back the way it was.\n\nCalyban is free for Windows and Linux at [/#download](https://calyban.com/#download). Questions about a specific setup go to [Discord](https://discord.gg/pHDNtgYvWn).", "url": "https://wpnews.pro/news/how-to-connect-mongodb-to-claude-code-codex-and-cursor", "canonical_source": "https://calyban.com/blog/connect-mongodb-to-claude", "published_at": "2026-11-28 00:00:00+00:00", "updated_at": "2026-11-29 06:14:36.176749+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["MongoDB", "mongodb-mcp-server", "Claude Code", "Codex", "Cursor", "Calyban", "GitHub Copilot", "Gemini CLI"], "also_reported_by": [], "takeaway": "Add MongoDB's official `mongodb-mcp-server` via `npx -y mongodb-mcp-server` with the connection string in `MDB_MCP_CONNECTION_STRING`, and start with a read-only database user so the database itself enforces limits on what the agent can do.", "recommendation": {"advice": "Give the MongoDB MCP server a read-only database user or a staging cluster first, since the database enforces the privilege regardless of what the agent attempts.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/how-to-connect-mongodb-to-claude-code-codex-and-cursor", "markdown": "https://wpnews.pro/news/how-to-connect-mongodb-to-claude-code-codex-and-cursor.md", "text": "https://wpnews.pro/news/how-to-connect-mongodb-to-claude-code-codex-and-cursor.txt", "jsonld": "https://wpnews.pro/news/how-to-connect-mongodb-to-claude-code-codex-and-cursor.jsonld"}}