feat: add OIDC authentication support for atlas-connect-cluster#1198
Draft
gmishkin wants to merge 3 commits into
Draft
feat: add OIDC authentication support for atlas-connect-cluster#1198gmishkin wants to merge 3 commits into
gmishkin wants to merge 3 commits into
Conversation
Adds mongodb-oidc as an alternative authentication mechanism for the atlas-connect-cluster tool, controlled via server-level config (MDB_MCP_ATLAS_AUTH_MECHANISM=mongodb-oidc). When enabled, the tool connects using OIDC rather than creating a temporary Atlas database user, allowing deployments with lower-privilege Atlas API credentials. Supports both workforce identity federation (human browser/device-code flows) and workload identity federation (non-interactive cloud identity, e.g. Azure Managed Identity, GCP, Kubernetes) via the companion MDB_MCP_ATLAS_OIDC_MECHANISM_PROPERTIES config option.
Collaborator
Coverage Report for CI Build 26189473402Warning No base build found for commit Coverage: 78.953%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
Address review feedback on #1189: - Use ConnectionString from mongodb-connection-string-url instead of new URL() to correctly handle multi-host connection strings - Use semver.coerce/lt instead of manual parseInt for MongoDB version comparison to be robust against MongoDB 10+
gmishkin
commented
May 20, 2026
| private async prepareClusterConnectionOIDC( | ||
| projectId: string, | ||
| clusterName: string, | ||
| connectionType: "standard" | "private" | "privateEndpoint" | undefined = "standard" |
Collaborator
Author
There was a problem hiding this comment.
@addaleax when you said deduplicating on the other PR is this what you were getting at?
diff --git a/src/common/atlas/cluster.ts b/src/common/atlas/cluster.ts
index ... 100644
--- a/src/common/atlas/cluster.ts
+++ b/src/common/atlas/cluster.ts
@@ -129,8 +129,10 @@ }
/**
* Returns a connection string for the specified connectionType.
* For "privateEndpoint", it returns the first private endpoint connection string available.
*/
+export type ClusterConnectionType = "standard" | "private" | "privateEndpoint";
+
export function getConnectionString(
connectionStrings: ClusterConnectionStrings,
- connectionType: "standard" | "private" | "privateEndpoint"
+ connectionType: ClusterConnectionType
): string | undefined {
diff --git a/src/tools/atlas/connect/connectCluster.ts b/src/tools/atlas/connect/connectCluster.ts
index ... 100644
--- a/src/tools/atlas/connect/connectCluster.ts
+++ b/src/tools/atlas/connect/connectCluster.ts
@@ -7,7 +7,7 @@
-import { getConnectionString, inspectCluster } from "../../../common/atlas/cluster.js";
+import { getConnectionString, inspectCluster, type ClusterConnectionType } from "../../../common/atlas/cluster.js";
- ): Promise<AtlasClusterConnectionInfo> { // prepareClusterConnection, line 89
- connectionType: "standard" | "private" | "privateEndpoint" | undefined = "standard"
+ connectionType: ClusterConnectionType | undefined = "standard"
- ): Promise<{ connectionString: string; atlas: AtlasClusterConnectionInfo } | null> { // prepareClusterConnectionOIDC, line 157
- connectionType: "standard" | "private" | "privateEndpoint" | undefined = "standard"
+ connectionType: ClusterConnectionType | undefined = "standard"Extract oidcDeviceFlowContent() from connectionErrorHandler and reuse it in the Atlas connect cluster polling path, removing the duplicate inline message and the redundant "call this tool again" instruction.
Contributor
|
This PR has gone 30 days without any activity and meets the project's definition of "stale". This will be auto-closed if there is no new activity over the next 30 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
mongodb-oidcas an alternative authentication mechanism foratlas-connect-cluster, controlled by two new server-level config options:MDB_MCP_ATLAS_AUTH_MECHANISM=mongodb-oidc— opt in to OIDC instead of temporary user creationMDB_MCP_ATLAS_OIDC_MECHANISM_PROPERTIES— optionalauthMechanismPropertiesstring for workload identity federation (e.g.ENVIRONMENT:k8s,TOKEN_RESOURCE:<audience>)When OIDC is enabled, the tool skips creating a temporary Atlas database user entirely, allowing deployments with lower-privilege Atlas API credentials (no user management permissions required —
Project Read Only+Project IP Access List Adminis sufficient).Supports both:
authMechanismPropertiesneeded)MDB_MCP_ATLAS_OIDC_MECHANISM_PROPERTIESEditor's note: See here for an acknowledgment of the limitations of the workload identity federation support.
Design decisions and tradeoffs
Auth mechanism is server-level config, not a tool argument.
An earlier approach exposed
authMechanismas a tool argument. We moved it to server config because the LLM agent has no way to know whether a given Atlas project has OIDC configured — that's deployment-specific knowledge the operator holds. A single MCP server deployment is already implicitly scoped to one Atlas org (the API credentials are org-scoped), and OIDC availability is also org/federation-scoped, so a server-level toggle is the right boundary.authMechanismPropertiesis also server-only for the same reason: which cloud environment the server is running in (ENVIRONMENT:azure,ENVIRONMENT:k8s, etc.) is a property of the deployment, not something the agent should determine at call time.Tool-level
authMechanism: "username-password"override retained as escape hatch.If the server is configured for OIDC but the OIDC identity lacks sufficient database access on a specific cluster (wrong cluster scope or insufficient roles), the agent's only recourse without this override would be a server restart. The tool now accepts an optional
authMechanism: "username-password"argument that forces the temp-user path for that connection. The description is intentionally restrictive: agents are instructed only to set this after observing authorization errors on a previous OIDC-authenticated connection to the cluster.No preflight check for OIDC user access.
We considered checking whether the OIDC identity has appropriate cluster scopes and roles before connecting, but there is no clean way to do this: the check would require additional Atlas API calls, and authorization errors only surface through actual database operations after the connection is established. The config description documents the requirement that operators ensure their OIDC database user in Atlas has appropriate cluster scopes and roles.
Fallback to temp-user for pre-7.0 clusters.
When
atlasAuthMechanism=mongodb-oidcis set but the target cluster is detected as running MongoDB < 7.0 (which does not support OIDC), the tool automatically falls back to temporary user creation and includes a note in the response. This requires the Atlas API credentials to have user management permissions for pre-7.0 clusters in a mixed-version org.AtlasClusterConnectionInforefactored to a discriminated union.Editor's note: This one is not super interesting. Check the edit history of this description to see the details
IP access list check is unchanged for OIDC.
Editor's note: I think this should be considered for https://jira.mongodb.org/browse/MCP-334
We briefly considered skipping
ensureCurrentIpInAccessListin OIDC mode (since lower-privilege credentials can't write to the access list). However, reading the access list and theapi/private/ipinfoendpoint both work withProject IP Access List Admin, which is a reasonable permission to grant alongsideProject Read Onlyfor an OIDC deployment. Skipping the check was reverted — operators should grantProject IP Access List Adminto their service account.Test plan
pnpm run check:typespassespnpm run test:localpasses (pre-existing failures inexportsManager,dropIndex,collectionIndexesare unrelated)MDB_MCP_ATLAS_AUTH_MECHANISM=mongodb-oidc— connection succeeds without creating a DB userauthMechanism: "username-password"— switches to temp user