Skip to content

Scope MCP connections to a grant's implicit project - #281

Open
masnwilliams wants to merge 1 commit into
mainfrom
hypeship/mcp-implicit-project-scope
Open

masnwilliams wants to merge 1 commit into
mainfrom
hypeship/mcp-implicit-project-scope

Conversation

@masnwilliams

@masnwilliams masnwilliams commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

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/context reports that as credential_scope.project_id: null with effective_scope.project_id: <granted project>. connectionScopeFromAuthContext treated an effective project without a credential project or server pin as inconsistent and returned invalid, and refuseConnection threw on invalid, which surfaced as an unhandled 500 with no body.

Scope (src/lib/mcp/auth-context.ts)

  • When the credential names no project and there is no KERNEL_PROJECT pin, 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.
  • Default-project and all-projects grants are unchanged: the API reports no effective project for either, so they stay organization-wide.
  • Genuinely inconsistent combinations are still refused: credential project ≠ effective project, credential project without a matching effective project, or a server pin that disagrees with the effective or credential project.

Refusals (src/app/[transport]/route.ts)

  • refuseConnection no longer throws on invalid. connectionScopeFailureResponse answers it with a JSON 500 {"error":"server_error","error_description":"Unable to resolve Kernel connection scope"} with CORS headers, and the refusal is logged with console.error.
  • The mcp_connection_scope_failure analytics event now carries response_status_code: 500 for invalid too.

Interaction with #276

#276 also edits route.ts (it adds permissions/projects to AuthInfoExtra and the native credential path) and the get_connection_context description. It doesn't touch auth-context.ts or refuseConnection. A trial merge of this branch with #276 has no conflicts, and the full suite and tsc pass on the merged result.

The behavior fits #276: its tool description says a connection with one granted project can omit project and KERNEL runs the request in that project. With this change, connection_scope reports that project as fixed for a non-default single-project grant. A default-project single grant still reports kind: "organization" (the API clears the effective scope for the default project), while #276's granted.projects lists it.

Testing

  • bun test: 1330 pass, 0 fail.
  • bunx tsc --noEmit, bun run check:managed-auth-app, and the OAuth Redis contract check pass.
  • New and updated tests:
    • unit tests for a non-default single-project grant (fixed to that project), default-project and all-projects grants (organization-wide), and the inconsistent cases that are still refused
    • a native OAuth route test where /auth/context returns no credential project and an effective project; get_connection_context reports the fixed project
    • route tests asserting a JSON 500 for an unaccountable /auth/context failure and for an inconsistent scope, plus the analytics payload
  • The new route test fails without the auth-context.ts change.
  • Not run against a deployed environment.

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/context reports no credential project but an effective project (the grant’s implicit project). connectionScopeFromAuthContext now pins the connection to that effective project instead of treating it as inconsistent.

Invalid scope handling no longer throws: refuseConnection returns a JSON 500 server_error with CORS, logs the stage, and records response_status_code on mcp_connection_scope_failure analytics for invalid outcomes (previously unhandled 500s).

Tests cover grant-scoped OAuth, get_connection_context reporting 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.

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
mcp Ready Ready Preview Nov 22, 2026 9:02pm UTC

This branch was successfully deployed

1 active deployment
Preview — ae9a93ad Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant