deploy-mongodb-agents
Skill8 starsChanged 26 days agoApache-2.0View on GitHub
Run the steps to deploy Atlas Explorer or Atlas Query Insights with the agentengine and Atlas CLIs: create the MCP configuration, set platform secrets, build, deploy, and diagnose a failed or stuck deploy or new conversations that fail to start. Use when asked to deploy, redeploy, ship, set up credentials, or troubleshoot a failed deploy or conversations that fail to start. Not for changing agent code or tool policy; use atlas-agent-engine.
- Reads credentials
- Installs packages
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 5 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Run agentengine commands from the agent directory, or from the repo root with --workspace <name>.
- Distinctive: line 23
Ask the user, rather than assuming:
- Very specific: line 42
Leave the roles read-only (GROUP_DATA_ACCESS_READ_ONLY) unless section 3 applies.
- Very specific: line 69
Run it once. Creating the configuration again makes a duplicate that also grants access.
- Very specific: line 78
If it's there, take mcpConfigId and clientId from that entry instead of creating another.
- Distinctive: line 98
When you hand this over, also tell them:
- Very specific: line 100
Keep the same terminal open for step 2.
- Very specific: line 125
If the user uses another provider, they set that provider's key name instead of OPENAI_API_KEY.
- Distinctive: line 129
Do this only if the user has stated a concrete need for writes (see the ground rules).
- Distinctive: line 140
Update all three together, or the deploy will start but model calls will fail:
- Distinctive: line 152
Ask the user to type the answers.
- Very specific: line 173
Leave it as {} for no restriction, so the agent can use every project, cluster, and database that the MCP configuration can reach.
- Very specific: line 234
If status isn't ready, or invoke fails, read references/troubleshooting.md.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Deploy an Atlas agent to Agent Engine
Deploys one agent from agents/<name> (atlas-explorer or atlas-query-insights) to your own Agent Engine project. Both agents follow the same steps. Each agent's README is the source of truth for details; if it disagrees with this skill, follow the README.
Run agentengine commands from the agent directory, or from the repo root with --workspace <name>.
Ground rules
- Keep secrets out of your context. Never run a command that prints a secret, and never read
.env,.env.*, or any file the user saved a secret to. Steps marked User runs are run by the user in their own terminal, not with the!prefix and not by you, because anything they print lands in the conversation. Everyagentengine secret setis a user-run step. - Confirm before granting access. Creating an MCP configuration and enabling writes both grant access. Before each, show the user exactly what will be created or changed and wait for an explicit yes. Don't batch these into one approval.
- Never run commands that don't exit or need a person. Don't use
-for any follow flag (deploy logs -f,deploy get -f,logs -f); they never exit and will hang you.agentengine auth login,atlas auth login, andagentengine initare interactive or state-changing, so stop and ask the user to run them. - Don't pass
--yesor--autotoagentengine deploy.--yesaccepts billed Flex cluster defaults and IP access-list changes.--autobuilds and then tails the deployment. Plainagentengine deployrun non-interactively never prompts, never runsinit, and never starts a build; it prints any missing setup instead, which you then hand to the user. - Ask before changing the environment again. The user asking for a deploy covers one
agentengine deploy. Ask before any redeploy, and show the user anyagent.yamlchange before saving it. - Narrowest access by default. Read-only is the default because the roles on the MCP configuration are the hard limit on what the agent can do in Atlas. A leaked credential, a prompt injection, or a model mistake can then read data but can't change it. Only move to a write role when the user states a concrete need (for example "it needs to create indexes on
ordersin staging"). "Might be useful" isn't a need.
Before you start
Ask the user, rather than assuming:
- Which agent, and which environment (local, staging, production). Each environment gets its own MCP configuration and credentials. Never reuse them across environments.
- Which Atlas project the agent should see. The MCP configuration is scoped to one project.
- Whether writes are needed, and if so what for. Atlas Query Insights is read-only and must stay that way. Atlas Explorer is read-only unless both opt-ins in section 3 are done.
- Which model provider. The default is OpenAI.
- For a local environment only: their public IPv4. Ask for it. Don't look it up with an external service.
Prerequisites: agentengine CLI installed, Atlas CLI 1.58 or later, Node.js 24 or later, pnpm, and a model API key. Run agentengine status. If it says not logged in or not initialized, stop and ask the user to run agentengine auth login (and agentengine init) themselves.
1. Create the Atlas MCP configuration
Skip this if the environment already has a configuration and stored credentials.
cp mcp-config.example.json mcp-config.json(the copy is git-ignored).mcp-secret-metadata.jsonis checked in next to it and needs no copy. It sets how long the minted secret lasts (secretExpiresAfterHours).- Edit
mcp-config.json:
- Replace
{environment}inmcpConfigName(for exampleatlas-explorer-prod). The example already sets the roles. YOUR_LOCAL_PUBLIC_IP: for a local environment, replace it with the IPv4 the user gave you. For staging or production, delete that whole{ "ipAddress": ... }entry fromipAccessList. Don't leave the placeholder in, and don't put a developer's IP on a deployed configuration.- The two Agent Engine egress IPs are already in
ipAccessList(see https://www.mongodb.com/docs/agentengine/network-egress/). Check they still match that page, since a deployed workspace can't reach Managed MCP without them.
- Leave the roles read-only (
GROUP_DATA_ACCESS_READ_ONLY) unless section 3 applies. - Confirm no placeholders are left. This must print nothing:
grep -nE 'YOUR_LOCAL_PUBLIC_IP|\{environment\}|AGENT_ENGINE_IP' mcp-config.json- Confirmation gate. Show the user the final
mcp-config.jsonand say in one line what it grants: the Atlas project (GROUP_ID), the roles, and every IP inipAccessList. Wait for a yes. Don't run the next command without it. - Create the configuration and keep its ID. The user must already be logged in (
atlas auth login -P mcpis interactive, so they run it). Don't run it yourself. The response includesmcpConfigId(the configuration's UUID) andclientId(themdb_sa_id_...OAuth client ID). The response also has anegressClientId, which is managed by Atlas and is not the one to use. Neither value you need is a secret, so you can run this:
export GROUP_ID="<atlas-project-id>"
read -r MCP_CONFIG_ID CLIENT_ID <<< "$(atlas api remoteMcpConfigurations createGroupMcpConfig \
--groupId "$GROUP_ID" --file mcp-config.json -P mcp \
-o '{{.mcpConfigId}} {{.clientId}}' | awk 'NF && !/^warning:/' | tail -n 1)"
echo "mcpConfigId: $MCP_CONFIG_ID"
echo "clientId (ATLAS_MCP_CLIENT_ID): $CLIENT_ID"
test -n "$MCP_CONFIG_ID" -a -n "$CLIENT_ID" || echo "IDs not found in the output; don't rerun"This uses the Atlas CLI's own output template, so jq isn't needed. The
CLI can print a warning, such as warning: using default API version, and a
blank line in the same output. The awk filter drops those lines, and
tail -n 1 keeps the last one left.
Run it once. Creating the configuration again makes a duplicate that also
grants access. If the IDs come back empty, the configuration may still have
been created. Before any retry, look for it by its mcpConfigName:
atlas api remoteMcpConfigurations listGroupMcpConfigs \
--groupId "$GROUP_ID" -P mcp -o jsonIf it's there, take mcpConfigId and clientId from that entry instead of
creating another.
- User runs: mint the client secret. The command prints the secret, so the user runs it in their own terminal and sends the output to a private temporary file outside the repo. Give them this, with
<atlas-project-id>and<mcpConfigId>filled in. Your shell variables don't carry over to their terminal. PassmcpConfigId, notclientId:
SECRET_FILE="$(mktemp)"
atlas api remoteMcpConfigurations createGroupMcpSecret \
--groupId "<atlas-project-id>" --mcpConfigId "<mcpConfigId>" \
--file mcp-secret-metadata.json -P mcp -o json > "$SECRET_FILE"
echo "$SECRET_FILE"mktemp creates an owner-only file with a random name in the system's
temporary directory, so the secret isn't left in the home directory if the
user forgets to delete it. A fixed name under /tmp would let another user
on a shared machine create the file first.
The secret is returned once. Tell the user to open the file themselves, store the values in step 2, then delete it. Don't read that file.
When you hand this over, also tell them:
- Keep the same terminal open for step 2.
$SECRET_FILEholds the path, andechoprinted it in case they need it from another terminal. An editor's file tree won't show the file. They can open it withcat "$SECRET_FILE". - The value for
ATLAS_MCP_CLIENT_SECRETis thesecretfield, which starts withmdb_sa_sk_. - The
idfield is the secret's own ID, not the client ID. The client ID is theclientIdfrom step 6.
2. Store secrets on the platform
User runs each of these. Each prompts for the value, which stays out of the conversation:
agentengine secret set ATLAS_MCP_CLIENT_ID --workspace-scope # the clientId from step 1
agentengine secret set ATLAS_MCP_CLIENT_SECRET --workspace-scope # the secret field in $SECRET_FILE
agentengine secret set OPENAI_API_KEYsecret set writes a project-scoped secret by default, shared by every workspace in the Agent Engine project. Atlas Explorer and Atlas Query Insights use the same names (ATLAS_MCP_CLIENT_ID, ATLAS_MCP_CLIENT_SECRET) but should have different MCP configurations, so a project-wide value would be overwritten by whichever agent was set up last. The two Atlas secrets above therefore use --workspace-scope. Neither the help text nor the published docs say which scope wins when both exist, so check after setting them. Run both commands below. secret list shows only project-scoped secrets by default, so the two Atlas secrets appear only with --workspace-scope. Neither command prints secret values.
agentengine secret list
agentengine secret list --workspace-scopeIf the user uses another provider, they set that provider's key name instead of OPENAI_API_KEY. Secret names must match the names listed under required_secrets in agent.yaml. MONGODB_URI is injected, so don't set it. Afterwards the user deletes the file with rm "$SECRET_FILE".
3. Enable writes (Atlas Explorer only, optional)
Do this only if the user has stated a concrete need for writes (see the ground rules). Query Insights never gets this step.
Writes need both of these. Leaving either out keeps the agent read-only.
- An MCP configuration with a write-capable Atlas role such as
GROUP_DATA_ACCESS_READ_WRITE, scoped to what the environment needs. This is a new configuration or a change to a configuration that grants access, so it needs its own confirmation gate. ALLOW_WRITE_OPERATIONSdeclared underrequired_secrets.aerinagent.yaml, then User runsagentengine secret set ALLOW_WRITE_OPERATIONSwith a non-empty value other thanfalse. The checked-in manifest doesn't declare it.
Confirmation gate. Before changing either, show the user the role you'll grant, the Atlas project and environment it applies to, the agent.yaml diff, and the stated need. Say that every write tool then pauses for approval and that $out and $merge aggregations also require approval. Wait for a yes. Tell the user the agent.yaml change should be reviewed and committed deliberately.
4. Changing the model provider (optional)
Update all three together, or the deploy will start but model calls will fail:
- Provider and model in
config.ts(src/agent_atlas_explorer/config.tsorsrc/agent_atlas_query_insights/config.ts). - The provider's key under
required_secrets.aerandrequired_secrets.tools.invoke_llm. - The provider's API host under
network.egresswithcomponent: tool.
Outbound traffic is blocked by default. The agent can reach only the hosts listed in agent.yaml.
5. Tell the agent where to look (optional)
Without this, the agent often has to ask which cluster to use before it can do anything. Offer it once: "Do you want to set a default cluster and anything the agent should always know?" If the user says no, skip it.
Ask the user to type the answers. Don't look them up and don't read their cluster to fill them in. You need:
- Any of these they want to set: project id, cluster name, database name, collection name. Each one is a string. They can skip any of them.
- Optional notes in plain words, such as what the data is for or which databases to ignore.
Then edit config.ts and show the user the diff before saving:
Either agent (
config.ts): put the strings insystemPrompt.defaultData. Leave a field""orundefinedwhen they did not give one.defaultData: { projectId: "<project id>", clusterName: "<cluster name>", databaseName: "<database name>", collectionName: "<collection name>", },The strings go into the system prompt. They are not checked. A project or cluster outside
dataAccess.projects, or a database outsidedataAccess.databaseNames, still fails when the agent uses it.- Either agent (
config.ts): put other notes insystemPrompt.customInstructions, for exampleThe orders database holds customer orders.Leave it empty to skip extra prompt text. Built-in safety rules still apply. Either agent (
config.ts): to limit the agent, setdataAccess. Leave it as{}for no restriction, so the agent can use every project, cluster, and database that the MCP configuration can reach. Otherwise set either or both of its keys:projectslimits the clusters.- Each project ID must be a 24-character hex ID.
- Omit
projectsto allow every cluster.
databaseNameslimits the databases, on every allowed cluster.- A string must equal the database name.
- A regular expression is tested as written, so anchor it
(
/^orders$/) to match the whole name. - Omit
databaseNamesto allow every database.[]allows none.
dataAccess: { projects: { // Only the prod-orders cluster in this project. "<projectId>": { clusterNames: ["prod-orders"] }, // Every cluster in this project. "<otherProjectId>": {}, }, // Only these databases, on every allowed cluster. databaseNames: ["orders", /^tenant_\d+$/], } satisfies DataAccessConfig,
Atlas Explorer users can also add a data map: a list of databases, collections and fields so the agent can skip exploring. It goes stale, so offer it only if the user asks or says they'd like it, and only if this coding agent already has the MongoDB MCP connected. Then follow references/data-map.md.
Rules:
- The text goes into the system prompt and into git. Never include credentials, connection strings, or personal data. Keep it short and factual.
dataAccess.projectsis in the system prompt, and the agent rejects tool calls that name any other project or cluster. That is a guardrail in the agent. The hard boundary is still the Atlas project and roles on the MCP configuration.dataAccess.databaseNamesis in the system prompt, and the agent rejects tool calls whosedatabaseargument doesn't match. It also checks$outand$mergetargets. It doesn't filter tool results, so the agent can still see other database names, and it doesn't inspect other parts of an aggregation pipeline. Say so if the user asks how strict it is: it's a guardrail in the agent. The hard boundary is the MCP configuration's project and roles, and Atlas can't limit that token to specific databases yet.- This is a code change, so the agent needs a rebuild (
pnpm build) and a deploy to pick it up. It doesn't change what the agent is allowed to do.
6. Check before deploying
pnpm install
pnpm test
pnpm typecheck
pnpm build
agentengine agent validatepnpm build produces dist/, which is what runs on the platform. Rebuild after any source change. agentengine agent validate checks agent.yaml only (older CLIs call it agentengine validate). Do not edit .agentengine/; the CLI generates it.
Review git diff agent.yaml before continuing and make sure every change is intended.
7. Build, deploy, smoke test
agentengine build
agentengine deploy
agentengine status --verbose
agentengine invoke "List the databases in my cluster and their sizes."For Atlas Query Insights, invoke it for a report instead. Its Performance Advisor needs an M10 or larger cluster with recent slow query logs.
To watch a deploy live, ask the user to run agentengine deploy logs -f in their own terminal. Never run it yourself.
If status isn't ready, or invoke fails, read references/troubleshooting.md. That file says when a redeploy is allowed: at most once per distinct cause, and never on a fast failure.
Report back
Say what was actually done and verified: which agent and environment, which commands ran, agentengine status output, and whether the smoke test passed. If a step was skipped or failed, say so.
In this repository21 other files it gives its agents.
- AGENTS.mdAGENTS.md
- mongodb-atlas-stream-processingSkill
- mongodb-connectionSkill
- mongodb-mcp-setupSkill
- mongodb-natural-language-queryingSkill
- mongodb-qe-size-estimationSkill
- mongodb-query-optimizerSkill
- mongodb-schema-designSkill
- mongodb-search-and-aiSkill
- mongodb-connectionSkill
- mongodb-natural-language-queryingSkill
- mongodb-query-optimizerSkill
- mongodb-schema-designSkill
- mongodb-search-and-aiSkill
- agent-engine-feature-validationsSkill
- agent-engine-troubleshoot-deploySkill
- atlas-agent-engine-docsSkill
- atlas-agent-engineSkill
- chat-sdk-add-adapterSkill
- chat-sdkSkill
- gh-stackSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

