Skip to content

Let the consent page decide what an MCP connection may do - #276

Open
rgarcia wants to merge 4 commits into
mainfrom
hypeship/oauth-permission-consent
Open

rgarcia wants to merge 4 commits into
mainfrom
hypeship/oauth-permission-consent

Conversation

@rgarcia

@rgarcia rgarcia commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two changes so the Kernel MCP server works with permission consent on Kernel's authorization server, where the person connecting chooses what the client may do and in which projects.

  1. The protected-resource metadata no longer lists scopes_supported. It used to tell clients to request openid. With nothing listed here, what a connection may do is decided on the consent page, not by the scopes a client was told to ask for.
  2. The tool list follows the grant. When a Kernel-issued token names the actions it was granted, toolsets that none of those actions can use are left out of tools/list, and get_connection_context reports the granted actions and projects under granted. A grant limited to some projects reports them even when its token names no action.

Details

  • What clients request now. Clients differ in what they do when the resource metadata lists no scopes. Some request none (the MCP TypeScript SDK, unless the client configures its own). Others fall back to the authorization server's scopes_supported and request all of it. Both work: the consent page offers every permission in the first case and the requested ones in the second, and in neither case is anything granted that the person did not check.
  • How a toolset is matched. A toolset is listed when the token holds any action on a resource kind the toolset calls (for example browsers:* for the browser, computer, shell, and Playwright tools). The table is in src/lib/mcp/register.ts. It must name every toolset and its resource kinds are typed, so adding a toolset without deciding this, or misspelling a kind, does not compile. This only trims the list: the API authorizes every call, and its 403 already names the missing permission.
  • Tokens that name no action. Such a token holds its whole grant without listing it, so nothing is known about it and every toolset is listed, as today. API keys and Clerk tokens are unchanged.
  • Never listed for a token that names actions: API key management and workload identity tools. A sign-in cannot hold those permissions, so the API would refuse every call.
  • Projects. The token exchange response may carry projects (the projects a grant is limited to). It is cached with the exchanged token and surfaced in get_connection_context. The exchange cache key is bumped so entries sealed before this change, which carry no project list, are not read as "every project".

Known limitation

The vault and search tools are also gated on the organization's entitlements, which the server reads from the API with the connection's own token. That read needs organizations:read. Someone who unchecks it on the consent page ("view plan entitlements and limits", on by default) gets no vault or search tools, even if they granted vault or search permissions. Scoped API keys already behave this way. It is documented in docs/native-oauth.md and not changed here.

Effect on merge

  • Where MCP clients are still signed in through Clerk, the only change is that scopes_supported is gone from the resource metadata. An absent scope already defaults to openid at /authorize.
  • Tool filtering takes effect only for Kernel-issued tokens that name actions, which the authorization server issues where permission consent is enabled.

Testing

  • bun test passes (1332 tests), including new cases for the metadata, toolset filtering, and the connection context.
  • tsc --noEmit and prettier --check pass.
  • bun run lint fails before and after this change (next lint no longer exists in this Next.js version), so it was not run.
  • Not run against a deployed authorization server: no MCP client has connected to a build of this branch.

The protected-resource metadata no longer lists scopes_supported, so MCP
clients request no scopes and the authorization server's consent page, where
the person connecting chooses permissions and projects, decides.

When a Kernel-issued token names the actions it was granted, toolsets none
of those actions can use are left out of the tool list, and
get_connection_context reports the granted actions and projects. A token
that names no action, and every API key, lists every toolset as before. The
API still authorizes each call.
@vercel

vercel Bot commented Nov 13, 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 8:32pm UTC

Comment thread src/lib/mcp/tools/connection-context.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a6ff090. Configure here.

Comment thread src/lib/mcp/tools/connection-context.ts Resolved
Comment thread src/lib/mcp/tools/connection-context.ts Resolved
…sion-consent

# Conflicts:
#	src/app/[transport]/route.ts
#	src/lib/mcp/tools/connection-context.ts
Make the toolset-to-resource-kind table exhaustive so a new toolset cannot be
added without deciding how a granted permission affects it. Task tools need a
tasks action; workload identity tools, like API key tools, are never listed
for a token that names actions. Document that the vault and search tools also
need organizations:read, because entitlements are read with the connection's
token.

@masnwilliams masnwilliams left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving. the change is small and the shape is reasonable. one thing to fix before merging, plus a few optional notes.

fix before merge

get_connection_context only includes granted when the token names action scopes. A grant that is limited to some projects but names no actions never reports granted.projects, so agents treat the connection as org-wide. A one-line fix:

--- a/src/lib/mcp/tools/connection-context.ts
+++ b/src/lib/mcp/tools/connection-context.ts
@@ -29,3 +29,3 @@
-        ...(permissions !== undefined && {
+        ...((permissions !== undefined || projects !== undefined) && {
           granted: { permissions, projects },
         }),

Please add a test for that case too (exchange response with projects and a token with identity scopes only).

optional

  • In mcpToolsetResourceKinds, null vs [] carries meaning only through the comment. Named values like "any" / "never" would read better. api_keys and workload_identity are both meant to stay hidden for grants, but they get there by different mechanisms, which is worth unifying or commenting on.
  • A typo in a resource-kind string compiles fine and silently hides a toolset. A small union type of the API's resource kinds would catch it.
  • CACHE_KEY_INFO stays at v1 while the sealed payload gains projects. Entries cached before the deploy report "every project" until they expire. Bumping to v2 is free.
  • The JSON.stringify(JSON.stringify(...)).slice(1, -1) assertion in route.test.ts is brittle. Parsing the JSON-RPC response and checking granted directly would be clearer.
  • Longer term, if /auth/context reported the effective policy for these tokens, the server could derive toolsets and project limits from the connection context it already fetches. That would remove the projects plumbing through the exchange cache.

The BugBot "single granted project is not selected" finding looks like a false positive. The API runs requests that name no project in the single granted project, so omitting project already works. A short comment at the tool description pointing at that would help future readers.

Report granted in get_connection_context when the grant is limited to some
projects even if the token names no action. Replace the null and empty-list
markers in the toolset table with "any" and "never", type the resource
kinds so a misspelled one does not compile, and hide API key tools by the
same rule as workload identity tools. Bump the exchange cache key because
the sealed entry now carries projects.

This branch was successfully deployed

1 active deployment
Preview — 7e3df379 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.

2 participants