Skip to content

fix(core): keep published MCP OAuth resource verbatim - #67370

Open
vedantchalke36 wants to merge 2 commits into
anomalyco:devfrom
vedantchalke36:mcp-oauth-resource
Open

vedantchalke36 wants to merge 2 commits into
anomalyco:devfrom
vedantchalke36:mcp-oauth-resource

Conversation

@vedantchalke36

@vedantchalke36 vedantchalke36 commented Nov 30, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #58956

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A protected resource that publishes its root as http://host was sent to the authorization and token endpoints as http://host/. Our provider validated the metadata resource by parsing it into a URL and handing that to the SDK, and URL#toString() adds / to a bare origin. Entra ID compares the value exactly, so it rejected the request.

The provider now keeps the published resource string verbatim and lets the SDK send it as-is. The configured-URL fallback (for servers that publish no resource metadata) and the resource-coverage check are unchanged. If a resource echoes the transport's ?codemode=false, only that query parameter is still removed.

How did you verify your code works?

Added a sign-in row in packages/core/test/mcp/oauth.test.ts where protected-resource metadata publishes http://<origin> with no path. It asserts the authorize URL, token request, and saved discovery all keep the value without a trailing slash. A refresh test covers the edge case where the resource also echoes the transport's ?codemode=false: removing the query keeps the pathless form instead of round-tripping through URL#toString. Both tests fail on dev and pass with the change.

  • cd packages/core && bun test test/mcp/oauth.test.ts — 38 pass
  • cd packages/core && bun run typecheck — no type errors
  • bun run check — 37/37 tasks pass

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix works. I reproduced the bug on the base and it's gone with this PR.

I ran the reproduction script from #58956 against both checkouts with mcp auth. On the base, the authorize URL carried resource=http://localhost:18080/. With this PR it carries http://localhost:18080, exactly as published.

Leaving out validateResourceURL when resource metadata exists is safe with the bundled SDK. In that case the SDK sends resourceMetadata.resource as the original string, and the PR runs that value through resourceIndicator first, so the resource coverage check and the ?codemode=false removal still apply.

oauth.test.ts passes (37 tests), and the new test fails on the base. The package type-checks with tsc.

Public API: unchanged.

One small edge case, not blocking: a root resource that also echoes ?codemode=false still goes through URL#toString and gets the slash.

@vedantchalke36

Copy link
Copy Markdown
Author

Good catch. Fixed in 2785936: when removing an echoed ?codemode=false leaves a pathless resource, it now keeps the published authority form instead of serializing URL with a trailing slash. Added a refresh regression test for that case; the OAuth suite is 38 passing.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new commit fixes the edge case I raised last time. A pathless resource that echoes ?codemode=false now loses only the query and no longer gains a trailing slash. A resource that already ends in / keeps its slash.

I checked it with oauth.test.ts: all 38 tests pass with this PR, and the two new tests fail on the base. The package type-checks with tsc.

Public API: unchanged.

I found nothing new to flag.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new push only merges dev. The MCP OAuth fix and its tests are the same as in the version I reviewed last time.

oauth.test.ts still passes on the merged head (38 tests).

Public API: this PR doesn't change it. The merged dev commits bring in their own changes.

Nothing new to flag.

This branch has not been deployed

No deployments
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.

Forward slash is being added on root resource URIs with oauth challenge

1 participant