Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 17cf198. Configure here.
masnwilliams
left a comment
There was a problem hiding this comment.
Approving. The behavior looks right and the change is small (about 110 lines of logic outside tests and docs).
Before merging: per the rollout note, wait until kernel/kernel#5800 is deployed, then check in staging with a real MCP client that a native OAuth token missing a grantable scope (1) gets the transport 403 and is sent to step-up consent through this server's resource_metadata, and (2) gets the reconnect text on a tool call that hits the missing scope.
Suggestions. The first is strongly recommended; the rest are optional.
returnScopeChallengesand analytics. The wrapper turns a thrownToolCallErrorback into a returnedisErrorresult. This contradicts thethrowToolErrordocstring ("Throws rather than returning an isError result: analytics reads the error category from a thrown error's name"), and the PostHog event losesKernelApiError403. The wrapper also only looks for the challenge aterror.cause, so anAPIErrorthat escapes a tool without going throughthrowToolErroris missed. Consider detecting the challenge once inToolCallError's constructor (this.scopeChallenge = scopeChallengeOf(cause)) and checkingerror instanceof ToolCallError && error.scopeChallengein the wrapper. Type the context as the SDK'sServerContextinstead ofparams.at(-1) as { http?: { req?: Request } }. Parsemissing_scopesinscopeChallengeOftoo, rather than castingcauseagain inreconnectNote. At minimum, update the docstring.- One
WWW-Authenticatebuilder.createAuthErrorResponse(401) andmcpScopeChallenge(403) now differ: one includesrealmand the other doesn't, and one escapes nothing while the other strips quotes and backslashes. One shared builder, or the SDK'sbearerAuthChallengeResponse, would keep them consistent.resourceMetadataUrlcould also be required, rather than falling back tomcpServerOrigin(). - Store the description once. The rejected-403 failure keeps it in
descriptionand inchallenge.description, and each producer sets only one. That's what forces the??chain inconnectionScopeFailureResponseand thechallenge: {}marker inexchangeFailure. If producers always setdescriptionand the 403 variant haschallenge: { scope?: string } | null, the route needs no fallback logic. - Nits:
- The identical challenge block in the
open_auth_loginandbegin_auth_logincatches could be one helper. - Most of
scope-challenge-results.test.tstestssrc/lib/scope-challenge.tsand could move toscope-challenge.test.ts;apiScopeChallengeis exported only for those tests. - The comment above
classifyAuthContextErrorstill describes 403 only as "not entitled to this project".
- The identical challenge block in the

Summary
The Kernel API is getting an RFC 6750
insufficient_scopechallenge for native OAuth sign-ins that lack a permission the consent page can grant (WWW-Authenticate: Bearer error="insufficient_scope", scope="<held + missing actions>", resource_metadata="<API metadata>", plusmissing_scopesin the JSON body). This server now passes that on to MCP clients so they can re-authorize (MCP step-up authorization), pointing them at this server's own protected resource metadata.src/app/[transport]/route.ts):invalid_scopeanswers 403 withWWW-Authenticate: Bearer error="insufficient_scope", resource_metadata="<origin>/.well-known/oauth-protected-resource/mcp", error_description=..../auth/context403 that carries the API's challenge is forwarded with the API'sscopeand this server'sresource_metadata; the JSON body uses the challenge's description./auth/context403 without a challenge (for example a credential scoped to another project) no longer getsWWW-Authenticate. The oldBearer realm="OAuth", error="insufficient_scope"invited a re-authorization that could not fix it.src/lib/mcp/scope-challenge-results.ts): a tool that is already running cannot be turned into an HTTP 403, since a client retrying the call could repeat work it already did. When the API refuses a tool's request with a challenge, the call fails as a tool error (isError) whose text names the missing permissions and asks the user to reconnect, with the challenge in_meta["mcp/www_authenticate"], naming the metadata of the host the client connected to (as the transport 403s do).ToolCallErrorkeeps the API error as itscauseso the challenge survivesthrowToolError.open_auth_login,begin_auth_login) route challenged denials throughthrowToolErrorinstead of a generic retry message.manage_auth_connectionswait loop stops at a challenged denial instead of polling until timeout.docs/native-oauth.mddocuments the outcomes.mcp_connection_scope_failureevents keep the same stage, outcome and status codes. One analytics difference: tool calls answered with a challenge return a tool error instead of throwing, so their PostHog tool event records a generic error type rather thanKernelApiError403.Rollout
Safe before and after the API change ships: with an API that sends no challenge, every path behaves as before, except that a
/auth/context403 no longer carries the old challenge header. Rolling back restores the old headers.Merge after kernel/kernel#5800, the API change that sends the challenge, has deployed. It is stacked on kernel/kernel#5799, the step-up consent page.
Testing
bun test: 1364 pass, 0 fail. New tests cover challenge parsing, rewritingresource_metadata, tool-result_meta, the forwarded and unforwarded/auth/context403, the exchange 403, the wait loop and the panel.bunx tsc --noEmitclean.bun run check:managed-auth-apppasses.format:checkon main and are left untouched.Reviewed with sol-loop: 4 rounds with openai-codex/gpt-6.2-sol on extra-high reasoning. Sol verdict: approved.