Repository navigation
fix(mcp): advertise the scopes the tools require, so a client can ask for them - #121
Conversation
… for them The two discovery documents disagreed. The authorization server offered orbit.read and orbit.write, but the protected resource document, which is the one an MCP client reads to learn what to request, listed only openid, profile, email and offline_access, because it was delegating wholesale to better-auth's default. So a client asked for a token without orbit.read, and every tool call was then refused by the scope enforcement added in #115. Production had one live token and it carried exactly those four scopes. Re-authorising would have minted another broken one, which is why this looked unfixable from the client side. The protected resource document now advertises MCP_SCOPES, the same list the authorization server issues from, and a test pins the two together so adding a scope to one without the other fails the build.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 27 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| const metadata: unknown = await response.json().catch(() => null); | ||
| if (metadata === null || typeof metadata !== 'object' || Array.isArray(metadata)) return response; |
There was a problem hiding this comment.
Preserve metadata parse failures
When the wrapped handler returns malformed or non-JSON content, response.json() consumes the body and suppresses the parsing error before the same response is returned, leaving the client without the original response body or useful diagnostics.
Context Used: CLAUDE.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/src/app/.well-known/oauth-protected-resource/route.ts
Line: 16-17
Comment:
**Preserve metadata parse failures**
When the wrapped handler returns malformed or non-JSON content, `response.json()` consumes the body and suppresses the parsing error before the same response is returned, leaving the client without the original response body or useful diagnostics.
**Context Used:** CLAUDE.md ([source](https://github.com/noveum/orbit/blob/main/CLAUDE.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
The MCP server has been refusing every tool call. This is why, and it is a regression from #115.
The two discovery documents disagreed
/.well-known/oauth-authorization-serveradvertises the full set:/.well-known/oauth-protected-resourceadvertises only four:The protected-resource document is the one an MCP client reads to learn what to ask for, and it was delegating wholesale to better-auth's
oAuthProtectedResourceMetadata, which knows nothing about the Orbit scopes.So the client requested a token without
orbit.read, and #115's scope enforcement, which is correct and should stay, then refused all 74 tools. Checked against production: there is exactly one live access token and its scopes areopenid profile email offline_access.The nasty part is that re-authorising did not help. The client would read the same under-advertised document and mint another token missing the same scope, which is why this looked unfixable from the client end.
The fix
The protected-resource route now advertises
MCP_SCOPES, the same constant the authorization server issues from, and preserves the CORS headers the metadata endpoints need. The/mcpvariant re-exports it, so both stay in step.A test pins the two documents together: adding a scope to the authorization server without adding it here fails the build. That is the invariant that was missing, and it is what let the two drift apart in the first place.
After this deploys
The existing token still lacks
orbit.read, so it needs re-authorising once. I deliberately did not grandfather old tokens into the new scopes: that would undo the enforcement #115 added, and a single re-authorisation is the cheaper price.Greptile Summary
The PR updates OAuth protected-resource metadata to advertise the same MCP scopes configured for token issuance and adds tests pinning that invariant.
scopes_supportedwithMCP_SCOPES./mcproute variant.Confidence Score: 4/5
The PR appears safe to merge, with one non-blocking error-handling issue in the metadata wrapper.
Scope advertisement is correctly synchronized across both protected-resource routes, but a malformed upstream response would have its parsing failure hidden and its consumed body returned to the client.
Files Needing Attention: apps/web/src/app/.well-known/oauth-protected-resource/route.ts
Important Files Changed
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(mcp): advertise the scopes the tools..." | Re-trigger Greptile
Context used: