mongodb-mcp-setup
Guide users through installing and configuring the MongoDB MCP server. Use this skill when a user wants to connect their agent to MongoDB/Atlas through MCP, when the MongoDB MCP server is installed but its environment variables aren't configured, or when they don't have the server or credentials set
- 01Installs
- New
- 02Files scanned
- 1
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 df93ff42fab2284d… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
MongoDB MCP Server Setup
This skill guides users through configuring the MongoDB MCP server for use with an agentic client.
Overview
The MongoDB MCP server requires authentication. Users have three options:
-
Connection String (Option A): Direct connection to a specific cluster
- Quick setup for single cluster
- Requires
MDB_MCP_CONNECTION_STRINGenvironment variable
-
Service Account Credentials (Option B): MongoDB Atlas Admin API access
- Recommended for Atlas users - simplifies authentication and data access
- Access to Atlas Admin API and dynamic cluster connection via
atlas-connect-cluster - No manual DB user credential management
- Requires
MDB_MCP_API_CLIENT_IDandMDB_MCP_API_CLIENT_SECRETenvironment variables
-
Atlas Local (Option C): Local development with Docker
- Best for local testing - zero configuration required
- Runs Atlas locally in Docker, requires Docker installed
- No credentials or cloud cluster access
This is an interactive step-by-step guide. The agent detects the user's environment and provides tailored instructions, but never asks for or handles credentials — users add those directly to their shell profile or agentic client config in Step 5. Make this clear to the user whenever credentials come up in Steps 3a and 3b.
Step 0: Detect Client
Before anything else, determine which agentic client the user is running. This controls how credentials are configured in Step 1 and Step 5.
Run:
env | grep "^CODEX_"
- If no
CODEX_*variables are present → the user is running a shell-based client (Claude, Cursor, Gemini CLI, Copilot CLI, etc.). Credentials are configured via shell profile environment variables. - If any
CODEX_*variables are present → the user is running Codex. Credentials are stored in~/.codex/config.toml(macOS/Linux) or%USERPROFILE%\.codex\config.toml(Windows), not in shell environment variables. The desktop app does not inherit shell env vars when launched from Finder, Launchpad, or the Windows Start menu.
Carry this client type (Codex vs. shell-based) forward through every subsequent step.
Step 0.5: Confirm the MCP Server Is Installed
Check your own available tools for MongoDB MCP server tools such as list-databases, find, or connect (clients often prefix them with the server name, e.g. mcp__mongodb__find).
-
Tools present → the server is installed. If you are running in Codex, record the server name as it appears in the tool identifiers for use in Step 5. Continue to Step 1.
-
Tools absent → work through these checks in order, and stop at the first one that gives a clear answer:
- Config entry. Look for a
mongodbMCP entry in the client's MCP configuration. If there isn't one and the MongoDB plugin isn't enabled, the server is not installed. Go to Not installed below. - Bundled plugin. If the MongoDB plugin is enabled, the server is bundled and can't be missing because it was never added. Go to Failed to start below.
- Client status. If the client has a way to list MCP server status (for example,
/mcpin Claude Code), check it. A server listed as failed means Failed to start. A server listed as connected, with no tools in this session, means Needs restart. - Prerequisites. Confirm that
nodeandnpxare available. If either is missing, that is the likely cause of Failed to start.
If the checks don't settle it, ask the user: "Did you add the MongoDB server to your client, and have you restarted the client since?" Use the answer to choose the branch below.
- Needs restart: fully quit and reopen the client, then return to this step. Don't reinstall, because that can create a duplicate entry.
- Failed to start: the server is installed but not running. Check that Node.js and
npxare available, then see https://www.mongodb.com/docs/mcp-server/local-mcp/configuration/troubleshooting.md. If the plugin is bundled, don't send the user to install it. - Not installed: Fetch https://www.mongodb.com/docs/mcp-server/get-started.md, use only the section for the user's client (the page covers every client), and give the user those steps. Its install paths are the user's to run: plugin installs are slash commands, and
npx mongodb-mcp-server@latest setupprompts for a connection string. Afterwards tell them to fully restart the client and run this skill again.
- Config entry. Look for a
Step 1: Check Existing Configuration
Check whether credentials are already configured.
For shell-based clients — check the current environment:
env | grep "^MDB_MCP" | sed '/^MDB_MCP_READ_ONLY=/!s/=.*/=[set]/'
For Codex — search ~/.codex/config.toml (macOS/Linux) or %USERPROFILE%\.codex\config.toml (Windows):
grep -E 'MDB_MCP_(CONNECTION_STRING|API_CLIENT_ID|API_CLIENT_SECRET|READ_ONLY)' ~/.codex/config.toml 2>/dev/null | sed '/MDB_MCP_READ_ONLY/!s/[[:space:]]*=[[:space:]].*/ = "[set]"/'
Interpretation (both):
- If
MDB_MCP_CONNECTION_STRINGappears → connection string auth is configured - If both
MDB_MCP_API_CLIENT_IDandMDB_MCP_API_CLIENT_SECRETappear → service account auth is configured. If only one is present, treat it as incomplete. - If
MDB_MCP_READ_ONLYappears → read-only mode is enabled
Partial Configuration Handling:
- User wants to add read-only to existing setup (has auth, no read-only flag) → skip to Step 4
- User wants to switch authentication methods → explain they should remove the old credentials first (from
config.tomlfor Codex, from their shell profile for shell-based clients), then proceed with Steps 2–5 - User wants to update credentials → skip to Step 5
Important: If the user wants an Atlas Admin API action (managing clusters, creating users, performance advisor) but only has MDB_MCP_CONNECTION_STRING, explain they need service account credentials and offer to walk through setup.
Step 2: Present Configuration Options
If no valid configuration exists, present the options:
Connection String (Option A) — Best for:
- Single cluster access
- Existing database credentials
- Self-hosted MongoDB or no Atlas Admin API needs
Service Account Credentials (Option B) — Best for:
- MongoDB Atlas users (recommended)
- Multi-cluster switching
- Atlas Admin API access (cluster management, user creation, performance monitoring)
Atlas Local (Option C) — Best for:
- Local development/testing without cloud setup
- Fastest setup with Docker, no credentials required
Ask the user which option they'd like to proceed with.
Step 3a: Connection String Setup
If the user chooses Option A:
3a.1: Explain How to Find the Connection String
Explain where and how to obtain their connection string:
For MongoDB Atlas:
- Go to cloud.mongodb.com
- Select your cluster → click Connect
- Choose Drivers or Shell → copy the connection string
- Replace
<username>and<password>with your database user credentials
For self-hosted MongoDB:
- The connection string is typically configured by your DBA or in your application config
- Format:
mongodb://username:password@host:port/database
Expected formats:
mongodb://username:password@host:port/databasemongodb+srv://username:[email protected]/databasemongodb://host:port(local, no auth)
Proceed to Step 4 (Determine Read-Only Access).
Step 3b: Service Account Setup
If the user chooses Option B:
3b.1: Guide Through Atlas Service Account Creation
Direct the user to create a MongoDB Atlas Service Account:
Full documentation: https://www.mongodb.com/docs/mcp-server/prerequisites/?utm_source=agent-skills
Walk them through the key steps:
- Navigate to MongoDB Atlas — cloud.mongodb.com
- Select your organization from the ORGANIZATION section near the top of the page
- Go to "Project Identity and Access" on the left sidebar → Applications → Create Service Account
- Set Permissions — Grant Organization Member or Project Owner (see docs for exact permission mappings)
- Generate Credentials — Create Client ID and Secret
- ⚠️ The Client Secret is shown only once — save it immediately before leaving the page
- Note both values — you'll need Client ID and Client Secret for Step 5
3b.2: API Access List Configuration
⚠️ CRITICAL: The user MUST add their IP address to the service account's API Access List, or all Atlas Admin API operations will fail.
Steps:
- On the service account details page, find API Access List
- Click Add Access List Entry
- Add your current IP address. Use a specific IP or CIDR range whenever possible.
- ⚠️
0.0.0.0/0allows access from any IP — this is a significant security risk. Only use it as a last resort for temporary testing and remove it immediately afterward. It should never be used in production.
- ⚠️
- Save changes
This is more secure than global Network Access settings as it only affects API access, not database connections.
Proceed to Step 4 (Determine Read-Only Access).
Step 3c: Atlas Local Setup
If the user chooses Option C:
3c.1: Check Docker Installation
Verify Docker is installed:
docker info
If not installed, direct them to: https://www.docker.com/get-started
3c.2: Confirm Setup Complete
Atlas Local requires no credentials — the user is ready to go:
- Create deployments:
atlas-local-create-deployment - List deployments:
atlas-local-list-deployments - All operations work out of the box with Docker
Skip Steps 4 and 5 (no configuration needed) and proceed to Step 6 (Next Steps).
Step 4: Determine Read-Only vs Read-Write Access
Only applies to Options A and B. Skip to Step 6 for Option C.
Ask whether they want read-only or read-write access:
-
Read-Write (default): Full data access, modifications allowed
- Best for: Development, testing, administrative tasks
-
Read-Only: Data reads only, no modifications
- Best for: Production data safety, reporting, compliance
If read-only: include the read-only flag in the credential snippet in Step 5. If read-write: omit it (defaults to read-write).
Proceed to Step 5 (Configure Credentials).
Step 5: Configure Credentials
Do not ask for or handle credentials — provide exact instructions so the user can add them directly.
5.1: Add credentials
For shell-based clients — store credentials in a dedicated ~/.mcp-env file (not directly in the shell profile), then source it from the profile. This keeps credentials out of files that are often group/world readable by default and prevents accidentally committing them to git.
For Codex — add to ~/.codex/config.toml (macOS/Linux) or %USERPROFILE%\.codex\config.toml (Windows). The snippets below only take effect when a [mcp_servers.mongodb] entry with a command exists. If Step 0.5 recorded a different server name, use that name in place of mongodb in every [mcp_servers.mongodb.env] header.
Show the user the appropriate snippet:
For Connection String (Option A):
Shell-based clients (~/.mcp-env):
export MDB_MCP_CONNECTION_STRING="<paste-your-connection-string-here>"
Codex (config.toml):
[mcp_servers.mongodb.env]
MDB_MCP_CONNECTION_STRING = "<paste-your-connection-string-here>"
For Service Account (Option B):
Shell-based clients (~/.mcp-env):
export MDB_MCP_API_CLIENT_ID="<paste-your-client-id-here>"
export MDB_MCP_API_CLIENT_SECRET="<paste-your-client-secret-here>"
Codex (config.toml):
[mcp_servers.mongodb.env]
MDB_MCP_API_CLIENT_ID = "<paste-your-client-id-here>"
MDB_MCP_API_CLIENT_SECRET = "<paste-your-client-secret-here>"
If read-only was chosen (Step 4), also add:
Shell-based: export MDB_MCP_READ_ONLY="true" in ~/.mcp-env.
Codex: MDB_MCP_READ_ONLY = "true" under the same [mcp_servers.mongodb.env] section.
⚠️ Both config.toml and ~/.mcp-env are stored in plaintext. Do not commit them to version control.
5.2: Finalize (shell-based clients only)
Restrict permissions on ~/.mcp-env:
# adjust for windows if needed
chmod 600 ~/.mcp-env
Add source ~/.mcp-env to the shell profile (e.g. ~/.zshrc). Adjust for the detected shell (e.g. for fish: bass source ~/.mcp-env or set -x; for PowerShell: dot-source a .ps1 file instead).
Detect the shell and profile file by running echo $SHELL if needed.
5.3: Verify
Shell-based clients — reload the profile first, then verify:
source ~/.zshrc # adjust to match the profile file
env | grep "^MDB_MCP" | sed '/^MDB_MCP_READ_ONLY=/!s/=.*/=[set]/'
Codex:
# adjust path if on Windows
grep -E 'MDB_MCP_(CONNECTION_STRING|API_CLIENT_ID|API_CLIENT_SECRET|READ_ONLY)' ~/.codex/config.toml 2>/dev/null | sed '/MDB_MCP_READ_ONLY/!s/[[:space:]]*=[[:space:]].*/ = "[set]"/'
Expected output shows the configured key(s) with values redacted to [set]. If nothing appears, check that credentials were saved and (for shell-based clients) that the profile was reloaded.
Proceed to Step 6 (Next Steps).
Step 6: Next Steps
For Options A & B (Connection String / Service Account):
-
Restart the agentic client:
- Shell-based clients: Fully quit the client, then run
source <profile-file>to load the new variables, and reopen the client from that same terminal session so it inherits the environment. - Codex: Fully quit and relaunch the app. No terminal session needed — credentials come from
config.toml.
- Shell-based clients: Fully quit the client, then run
-
Verify MCP Server: After restart, test by performing a MongoDB operation.
-
Using the Tools:
- Option A: Direct database access tools available
- Option B: Additionally has Atlas Admin API tools and
atlas-connect-cluster - Important (Option B): Ensure your IP is in the service account's API Access List or all API calls will fail
For Option C (Atlas Local):
-
Ready to use: No restart or configuration needed!
-
Next steps:
- Create deployments:
atlas-local-create-deployment - List deployments:
atlas-local-list-deployments - Use standard database operations once connected
- Create deployments:
Troubleshooting
- Variables not appearing after
source(shell-based clients): Check the profile file path and confirm the file was saved - Client doesn't pick up variables: Ensure full restart (quit + reopen), not just a reload
- Codex desktop app not picking up credentials: If launched from Finder, Launchpad, or the Windows Start menu, Codex does not inherit shell environment variables from
.zshrc/.zprofile/PowerShell profiles. Use~/.codex/config.toml(macOS/Linux) or%USERPROFILE%\.codex\config.toml(Windows) instead (see Step 5) - Invalid connection string format: Re-check the format; must start with
mongodb://ormongodb+srv:// - Atlas Admin API errors (Option B): Verify your IP is in the service account's API Access List
- Read-only mode not working: Check that
MDB_MCP_READ_ONLYis set — inconfig.tomlunder[mcp_servers.mongodb.env]for Codex, or viaenv | grep ^MDB_MCP_READ_ONLYfor shell-based clients - fish/PowerShell: Syntax differs — use
set -x(fish) or$env:(PowerShell) instead ofexport
Files
1- SKILL.md
b3bd9b245a15.8 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from mongodb/agent-skills8
Front door for MongoDB and MongoDB Atlas. Use it before answering which database, MongoDB deployment, Atlas tier, or database hosting to use, even for advice-only questions. MongoDB updates frequently, so check this skill first. Also use it before setting up, provisioning, or connecting to MongoDB o
Manages MongoDB Atlas Stream Processing (ASP) workflows. Handles workspace provisioning, data source/sink connections, processor lifecycle operations, debugging diagnostics, and tier sizing. Supports Kafka, Atlas clusters, S3, HTTPS, and Lambda integrations for streaming data workloads and event pro
Manages MongoDB Atlas Stream Processing (ASP) workflows. Handles workspace provisioning, data source/sink connections, processor lifecycle operations, debugging diagnostics, and tier sizing. Supports Kafka, Atlas clusters, S3, HTTPS, and Lambda integrations for streaming data workloads and event pro
Optimize MongoDB client connection configuration (pools, timeouts, patterns) for any supported driver language. Use this skill when working/updating/reviewing on functions that instantiate or configure a MongoDB client (eg, when calling `connect()`), configuring connection pools, troubleshooting con
Optimize MongoDB client connection configuration (pools, timeouts, patterns) for any supported driver language. Use this skill when working/updating/reviewing on functions that instantiate or configure a MongoDB client (eg, when calling `connect()`), configuring connection pools, troubleshooting con
Guide users through configuring key MongoDB MCP server options. Use this skill when a user has the MongoDB MCP server installed but hasn't configured the required environment variables, or when they ask about connecting to MongoDB/Atlas and don't have the credentials set up.
Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents. Use this skill whenever the user asks to write, create, or generate MongoDB queries, wants to filter/query/aggregate data in MongoDB, asks "how do I query..
Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents. Use this skill whenever the user asks to write, create, or generate MongoDB queries, wants to filter/query/aggregate data in MongoDB, asks "how do I query..
Related database skillsscan passed
Use when developing WordPress (Gutenberg) blocks: block.json metadata, register_block_type(_from_metadata), attributes/serialization, supports, dynamic rendering (render.php/render_callback), deprecations/migrations, viewScript vs viewScriptModule, and @wordpress/scripts/@wordpress/create-block buil
Diagnose slow Elasticsearch Query DSL searches and propose measured fixes. Use when a search is slow, profile output shows an expensive clause, exact-match filters sit in scoring context, or leading wildcards dominate latency. Ground every recommendation in search profiling — move non-scoring clause
Plans, implements, and reviews migrations from other CMSes and content systems into Sanity. Use when migrating or replatforming to Sanity from AEM, Adobe Experience Manager, Contentful, Strapi, Webflow, WordPress, Payload, Drupal, Markdown/MDX/frontmatter files, WXR/XML exports, CMS APIs, database d
Provides authoritative compatibility checks, pricing estimates, connection troubleshooting, pre-warming guidance, and infrastructure mutations for Amazon Keyspaces (for Apache Cassandra). Covers LWT/batch operations, secondary indexes, materialized views, capacity modes, TTL, PITR, CDC, auto-scaling
This file generates or explains Cloud SQL resources. Use this file when the user asks to create a Cloud SQL instance or database for MySQL, PostgreSQL, or SQL Server. Cloud SQL manages third-party MySQL, PostgreSQL, and SQL Server instances as resources in Cloud SQL. For example, when Cloud SQL crea
Pick Jetson-compatible containers, vLLM runtime images, and Jetson AI Lab PyPI indexes; maps Orin SM 8.7 vs Thor SM 11.0 and JetPack-specific package choices.