fix(ai): follow MCP protected-resource OAuth discovery - #1591
Open
sethkarten wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2a499d2. Configure here.
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.

Context
Fixes the path-scoped persistent MCP OAuth discovery failure reported in Discussion #1574 and tracked in ENG-5416.
Prime Agent previously reduced every MCP resource URL to its origin and selected root authorization-server metadata. For Plane’s
/http/mcpresource, that produces a token for the legacy/sseaudience and the MCP endpoint rejects it.Changes
WWW-Authenticateor the exact path-and-query well-known URL.resourceindicator in authorization, code exchange, and refresh requests for protected-resource flows.ACP-provided session MCP credentials remain out of scope.
Validation
npm run checkcd packages/ai && npx tsx ../../node_modules/vitest/dist/cli.js --run test/mcp-oauth.test.ts— 14 passedNote
High Risk
Changes OAuth discovery, token exchange, and refresh binding (HTTPS-only endpoints, no redirects, exact issuer/resource matching). Incorrect validation could leak tokens or block legitimate MCP logins.
Overview
MCP OAuth no longer collapses every resource URL to origin-level metadata. Discovery now prefers RFC 9728 protected-resource metadata (from
WWW-Authenticateor the path-and-query well-known URL), then pathful RFC 8414/OIDC authorization-server metadata, so path-scoped servers like Plane/http/mcpget the correct audience instead of a root/ssetoken.Login and refresh send the RFC 8707
resourceindicator when PRM is present, persistresource/issuerwith credentials, and fail closed if endpoint, resource, issuer, discovery mode, or token endpoint no longer match. Fetches reject redirects, require HTTPS endpoints, and validate JSON metadata. Origin-only discovery remains only when PRM is absent.Reviewed by Cursor Bugbot for commit 3d23df3. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix MCP OAuth to follow RFC 9728 protected-resource discovery
resourcein authorization and token requests. Returned credentials are bound to endpoint, resource, and issuer.resourceon refresh when bound.McpCredentialsgains optionalresourceandissuerfields;AuthServerMetadata.issueris now required.📊 Macroscope summarized 3d23df3. 1 file reviewed, 1 issue evaluated, 1 issue filtered, 0 comments posted
🗂️ Filtered Issues
packages/ai/src/mcp/oauth.ts — 0 comments posted, 1 evaluated, 1 filtered
404, this returnsundefinedimmediately and never probes the required root/.well-known/oauth-protected-resourcefallback. MCP permits a path endpoint to publish its metadata at the root; for such a server this falls through to origin authorization-server discovery instead of using the resource's advertised authorization server, so OAuth login obtains the wrong token or fails. [ Out of scope (triage) ]