Repository navigation
Scope MCP connections to a grant's implicit project - #281
Open
masnwilliams wants to merge 1 commit into
Open
masnwilliams wants to merge 1 commit into
masnwilliams wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Summary
A native OAuth grant limited to one project that isn't the organization's default made every authenticated MCP request fail with a bare HTTP 500.
For such a grant, the API runs requests that name no project in the granted project.
GET /auth/contextreports that ascredential_scope.project_id: nullwitheffective_scope.project_id: <granted project>.connectionScopeFromAuthContexttreated an effective project without a credential project or server pin as inconsistent and returnedinvalid, andrefuseConnectionthrew oninvalid, which surfaced as an unhandled 500 with no body.Scope (
src/lib/mcp/auth-context.ts)KERNEL_PROJECTpin, an effective project now fixes the connection to that project (kind: "project",source: "credential"). Project selection then rejects any other project, which matches what the grant allows.Refusals (
src/app/[transport]/route.ts)refuseConnectionno longer throws oninvalid.connectionScopeFailureResponseanswers it with a JSON500 {"error":"server_error","error_description":"Unable to resolve Kernel connection scope"}with CORS headers, and the refusal is logged withconsole.error.mcp_connection_scope_failureanalytics event now carriesresponse_status_code: 500forinvalidtoo.Interaction with #276
#276 also edits
route.ts(it addspermissions/projectstoAuthInfoExtraand the native credential path) and theget_connection_contextdescription. It doesn't touchauth-context.tsorrefuseConnection. A trial merge of this branch with #276 has no conflicts, and the full suite andtscpass on the merged result.The behavior fits #276: its tool description says a connection with one granted project can omit
projectand KERNEL runs the request in that project. With this change,connection_scopereports that project as fixed for a non-default single-project grant. A default-project single grant still reportskind: "organization"(the API clears the effective scope for the default project), while #276'sgranted.projectslists it.Testing
bun test: 1330 pass, 0 fail.bunx tsc --noEmit,bun run check:managed-auth-app, and the OAuth Redis contract check pass./auth/contextreturns no credential project and an effective project;get_connection_contextreports the fixed project/auth/contextfailure and for an inconsistent scope, plus the analytics payloadauth-context.tschange.Note
Medium Risk
Changes authentication scope resolution for native OAuth and alters failure paths from throws to HTTP 500 responses, affecting which credentials succeed and how clients see scope bugs.
Overview
Single-project OAuth grants no longer fail MCP connections when
/auth/contextreports no credential project but an effective project (the grant’s implicit project).connectionScopeFromAuthContextnow pins the connection to that effective project instead of treating it as inconsistent.Invalid scope handling no longer throws:
refuseConnectionreturns a JSON 500server_errorwith CORS, logs the stage, and recordsresponse_status_codeonmcp_connection_scope_failureanalytics forinvalidoutcomes (previously unhandled 500s).Tests cover grant-scoped OAuth,
get_connection_contextreporting the fixed project, and structured 500 responses for unaccountable or inconsistent scope resolution.Reviewed by Cursor Bugbot for commit ae9a93a. Bugbot is set up for automated code reviews on this repo. Configure here.