Skip to content

Support runtime permission escalation for MCP providers #694

Open

Description

@dcramer

Problem

Junior does not correctly complete the standard MCP incremental-authorization path when an authenticated server returns:

HTTP 403
WWW-Authenticate: Bearer error="insufficient_scope", scope="..."

With @modelcontextprotocol/sdk 1.29.0, the transport forwards the challenged scope into auth(...). If Junior has a cached refresh token, the SDK refreshes it without sending the challenged scope and treats any successful refresh response as AUTHORIZED. The request is retried with effectively unchanged authorization, receives the same 403, and stops at the SDK's duplicate-upscope guard. No new consent redirect is created.

This is distinct from a provider simply not exposing write tools. OAuth can escalate scopes for an existing tool; it cannot manufacture tools the MCP server did not advertise.

Confirmed code path

  • SDK StreamableHTTPClientTransport.send recognizes the 403 insufficient_scope challenge and calls auth with the requested scope.
  • SDK authInternal prefers a cached refresh token before starting a new authorization redirect.
  • SDK refreshAuthorization sends grant_type and refresh_token (plus resource/client auth), but not the challenged scope.
  • Junior's MCP OAuth provider persists the resulting tokens without verifying that they satisfy the challenged scope.

Acceptance criteria

  • A standard 403 Bearer insufficient_scope challenge records the exact requested scope and MCP resource.
  • Existing relevant scopes are retained when constructing the expanded authorization request.
  • A refresh response is accepted as escalation only when it proves the challenged scope is granted; otherwise Junior starts a new interactive authorization attempt.
  • The reauthorization attempt remains bound to workspace subject, resource, issuer, redirect URI, and the paused turn.
  • Repeated identical challenges terminate safely without a refresh/redirect loop.
  • The original paused tool call resumes after successful expanded consent.
  • Missing provider tools remain a separate capability error and do not trigger OAuth.
  • The deterministic MCP OAuth mock covers successful escalation, rejected scope, unchanged refresh scope, denial, and duplicate challenge behavior.

Related: #836, #837, #838, #840.

Activity

  1. added
    enhancement
    on Jun 30, 2026
  2. armorer-labs commented on Jul 1, 2026

    @armorer-labs

    One implementation detail I would make explicit is that scope escalation should be treated as a new authorization event, not as a continuation of the original read-only session.

    A concrete flow that tends to avoid surprises:

    • when the agent hits a missing capability, stop before planning the write and emit a structured capability_required result with provider, missing scope/tier, intended operation class, and a redacted target summary;
    • ask the user to approve the capability delta, not just the final natural-language task;
    • after OAuth reauth or tier upgrade returns, re-resolve the provider tool list and require a fresh approval for the first side-effecting call with normalized args shown;
    • record the escalation grant with actor, provider, scope/tier, duration, originating thread, and the exact tool call that consumed it;
    • make downgrade/revoke first-class, especially for persistent grants.

    The test I would add is a two-step negative case: a read-only Notion connection requests create page, the user declines escalation, and the agent cannot retry through an alternate write path or silently keep the pending intent around. Then the positive case can verify that the post-reauth tool inventory changed and the actual write still passes through the approval/audit path.

    Disclosure: I work on Armorer Labs.

  3. dcramer commented on Jul 11, 2026

    @dcramer
    MemberAuthor

    RCA update: the installed SDK's current 403 step-up path is deterministically broken even before the product-level approval work described here.

    For a 403 Bearer error="insufficient_scope", scope="read write", SDK 1.29.0 refreshes the existing token without sending the challenged scope, retries with an unchanged read-only token, then throws Server returned 403 after trying upscoping. Junior also drops the challenged scope when translating the SDK error, so MCP pending-auth dedupe cannot distinguish escalation attempts.

    Protocol acceptance criteria should include:

    • accumulate previously granted + newly challenged scopes;
    • carry the exact scope through typed error, pending auth, callback, and token storage;
    • include scope in refresh when supported;
    • initiate fresh interactive consent when refresh cannot expand scope;
    • verify the returned scope before retrying;
    • test positive and declined escalation through Expand the mock OAuth E2E server for adversarial protocol coverage #838.

    Umbrella: #843.

  4. added
    bug
    and removed
    enhancement
    on Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions