Summary
Add support for OAuth device flow authentication for Atlas Admin API, similar to how atlas auth login works in the official Atlas CLI.
Motivation
Today, the only options for Atlas Admin API auth in the MCP server are:
MDB_MCP_API_CLIENT_ID + MDB_MCP_API_CLIENT_SECRET (Service Account via OAuth 2.0 client_credentials grant)
MDB_MCP_CONNECTION_STRING (DB-user level, no Admin API)
For developers running the MCP server locally (e.g. inside Claude Code, Cursor, Cline), the Service Account path requires:
- Creating a long-lived Client Secret
- Storing it in
~/.mcp-env or a shell profile
- Manually managing rotation and IP allowlists
This is a meaningful difference vs. the user-flow OAuth that atlas auth login, gh auth login, az login, and gcloud auth login all provide — where credentials live in OS-managed storage and inherit the user's existing org permissions without a separate principal.
Proposed feature
Add a new auth mode, e.g.:
MDB_MCP_AUTH_MODE=oauth-device
When set, the server should:
- On first start, perform an OAuth 2.0 device authorization flow against
account.mongodb.com (the same endpoint Atlas CLI uses).
- Display the verification URL + user code in stderr.
- Persist the resulting refresh token in the OS-native keychain (macOS Keychain / Windows Credential Manager / libsecret), or fall back to a token file at
~/.config/mongodb-mcp/credentials.json with chmod 600.
- Refresh access tokens transparently before they expire.
- Use the access token as
Authorization: Bearer ... against the Atlas Admin API.
Alternatively (or in addition), the server could read the existing Atlas CLI token from ~/Library/Application Support/atlascli/config.toml (or platform equivalent) — letting users authenticate once via atlas auth login and have the MCP server pick it up automatically.
Why this matters
- Security: no long-lived secret on disk; refresh tokens are revocable; access tokens expire short.
- Permissions parity: the user gets the exact set of permissions they have in the Atlas web UI, no risk of granting an over-privileged Service Account.
- Onboarding: removes the Service Account creation + Client ID/Secret + API Access List dance for individual developers.
- Precedent: this is the standard pattern across major cloud CLIs and developer tools.
Acceptance criteria
- New
MDB_MCP_AUTH_MODE=oauth-device option (or equivalent)
- Device authorization flow implemented against MongoDB's existing OAuth provider
- Refresh-token storage in keychain or
chmod 600 file
- Documentation updated in https://www.mongodb.com/docs/mcp-server/prerequisites/
- Existing Service Account auth remains supported
Related
Summary
Add support for OAuth device flow authentication for Atlas Admin API, similar to how
atlas auth loginworks in the official Atlas CLI.Motivation
Today, the only options for Atlas Admin API auth in the MCP server are:
MDB_MCP_API_CLIENT_ID+MDB_MCP_API_CLIENT_SECRET(Service Account via OAuth 2.0 client_credentials grant)MDB_MCP_CONNECTION_STRING(DB-user level, no Admin API)For developers running the MCP server locally (e.g. inside Claude Code, Cursor, Cline), the Service Account path requires:
~/.mcp-envor a shell profileThis is a meaningful difference vs. the user-flow OAuth that
atlas auth login,gh auth login,az login, andgcloud auth loginall provide — where credentials live in OS-managed storage and inherit the user's existing org permissions without a separate principal.Proposed feature
Add a new auth mode, e.g.:
When set, the server should:
account.mongodb.com(the same endpoint Atlas CLI uses).~/.config/mongodb-mcp/credentials.jsonwithchmod 600.Authorization: Bearer ...against the Atlas Admin API.Alternatively (or in addition), the server could read the existing Atlas CLI token from
~/Library/Application Support/atlascli/config.toml(or platform equivalent) — letting users authenticate once viaatlas auth loginand have the MCP server pick it up automatically.Why this matters
Acceptance criteria
MDB_MCP_AUTH_MODE=oauth-deviceoption (or equivalent)chmod 600fileRelated