Skip to content

fix: apply mongosh CLI options (e.g. oidcTrustedEndpoint) in connect-tool path#1121

Open
KyriosGN0 wants to merge 4 commits into
mongodb-js:mainfrom
KyriosGN0:fix-device-auth-oidc-endpoint
Open

fix: apply mongosh CLI options (e.g. oidcTrustedEndpoint) in connect-tool path#1121
KyriosGN0 wants to merge 4 commits into
mongodb-js:mainfrom
KyriosGN0:fix-device-auth-oidc-endpoint

Conversation

@KyriosGN0
Copy link
Copy Markdown

When a user calls the MCP 'connect' tool with a non-Atlas MongoDB host
and MONGODB-OIDC auth, the driver raised:

MongoInvalidArgumentError: Host 'foo.example.com' is not valid for OIDC
authentication with ALLOWED_HOSTS of '*.mongodb.net,...'

Root cause: generateConnectionInfoFromCliArgs was called with only
defaultDriverOptions, omitting the mongosh CLI options stored in
userConfig. The startup (connectToConfiguredConnection) path already
spread the full userConfig; this commit makes the connect-tool path
consistent by extracting the mongosh-specific subset via
getMongoshUserConfig() and merging it in.

Fixes: the existing OIDC integration test workaround comment at
tests/integration/common/connectionManager.oidc.test.ts:~142

NOTE: i wrote this PR with Claude Code, i verified this works with my case (mongodb running on k8s, the mcp is running also in k8s, the client is a local claude code session that is using connect tool)

Checklist

@KyriosGN0 KyriosGN0 requested a review from a team as a code owner April 30, 2026 08:12
@KyriosGN0 KyriosGN0 requested review from gagik and removed request for a team April 30, 2026 08:12
@gagik
Copy link
Copy Markdown
Collaborator

gagik commented May 1, 2026

Hey, thanks for the contribution! I will first investigate this usecase a bit more and see if there are alternative solutions that could also work here 🙂

@KyriosGN0
Copy link
Copy Markdown
Author

Hey @gagik, have you had a chance to look at this PR (and use case)? is there something i can do to help you?

@gagik
Copy link
Copy Markdown
Collaborator

gagik commented May 18, 2026

@KyriosGN0 hey, sorry there was some focus on #1045 past week. The changes and the usecase overall makes sense, I'll add a couple comments to address and we can get that in 🙂

Comment thread src/common/connectionManager.ts Outdated

private getMongoshUserConfig(): Partial<UserConfig> {
const mongoshKeys = Object.keys(MongoshCliOptionsSchema.shape) as (keyof UserConfig)[];
return Object.fromEntries(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd not be a problem to pass the whole userConfig object as it'd be a superset anyway generateConnectionInfoFromCliArgs

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gagik done

KyriosGN0 added 4 commits May 26, 2026 10:58
…tool path

When a user calls the MCP 'connect' tool with a non-Atlas MongoDB host
and MONGODB-OIDC auth, the driver raised:

  MongoInvalidArgumentError: Host 'foo.example.com' is not valid for OIDC
  authentication with ALLOWED_HOSTS of '*.mongodb.net,...'

Root cause: generateConnectionInfoFromCliArgs was called with only
defaultDriverOptions, omitting the mongosh CLI options stored in
userConfig. The startup (connectToConfiguredConnection) path already
spread the full userConfig; this commit makes the connect-tool path
consistent by extracting the mongosh-specific subset via
getMongoshUserConfig() and merging it in.

Fixes: the existing OIDC integration test workaround comment at
tests/integration/common/connectionManager.oidc.test.ts:~142

Signed-off-by: AvivGuiser <avivguiser@gmail.com>
The previous workaround bypassed the connect tool because mongosh CLI
options (e.g. oidcTrustedEndpoint) weren't propagated in that path.
Now that the bug is fixed, use the proper connect() helper so the test
exercises the same code path as a real MCP client.

Signed-off-by: AvivGuiser <avivguiser@gmail.com>
Signed-off-by: AvivGuiser <avivguiser@gmail.com>
Signed-off-by: AvivGuiser <avivguiser@gmail.com>
@KyriosGN0 KyriosGN0 force-pushed the fix-device-auth-oidc-endpoint branch from 2462a08 to aa87e1a Compare May 26, 2026 08:03
@KyriosGN0 KyriosGN0 requested a review from gagik May 26, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants