Repository navigation
fix(core): keep published MCP OAuth resource verbatim - #67370
vedantchalke36 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.
53ebd45 to
2785936
Compare
|
Good catch. Fixed in 2785936: when removing an echoed |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Issue for this PR
Closes #58956
Type of change
What does this PR do?
A protected resource that publishes its root as
http://hostwas sent to the authorization and token endpoints ashttp://host/. Our provider validated the metadata resource by parsing it into aURLand handing that to the SDK, andURL#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.tswhere protected-resource metadata publisheshttp://<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 throughURL#toString. Both tests fail ondevand pass with the change.cd packages/core && bun test test/mcp/oauth.test.ts— 38 passcd packages/core && bun run typecheck— no type errorsbun run check— 37/37 tasks passScreenshots / recordings
Not a UI change.
Checklist