Class McpStepUpAuthorizer
401/403 insufficient_scope
challenge, it computes the required-scope union (McpScopeAccumulator), drives (re-)authorization via a
caller-supplied McpStepUpAuthorizer.Reauthorizer, and retries the original call — bounded by a hard attempt cap with
per-(resource, operation) attempt tracking so a misconfigured server can't drive an unbounded
re-authorization loop (spec "no more than a few times").
Step-up for user-delegation clients is inherently interactive (a fresh auth-code + PKCE round-trip), so this is an
explicit orchestration helper the caller wraps around MCP calls — not a silent interceptor retry. The
caller's McpStepUpAuthorizer.ScopedCall performs the actual MCP request and throws McpInsufficientScopeException (carrying
the parsed WwwAuthenticateChallenge) when the server responds with a step-up challenge; the
McpStepUpAuthorizer.Reauthorizer performs the (re-)authorization with the widened scope union (e.g. via
McpAuthorizationCodeAcquirer for user clients or a client-credentials re-acquire) and installs the new token.
client_credentials (own-behalf) clients MAY abort immediately rather than attempt step-up
(attemptStepUp(false)).
Attempt-counter lifetime
Per-(resource, operation) attempt counts exist only to bound a single step-up burst. A counter is
cleared automatically when execute returns successfully for that operation,
so a long-lived authorizer does not permanently refuse a later legitimate step-up for the same operation. A counter
that reaches the cap without a success (a permanent failure) is not auto-cleared — the caller can reset it
explicitly with reset(String) (one operation) or resetAll() (all operations) once the underlying
cause is resolved.
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder.static interfaceDrives (re-)authorization with the computed scope union and installs the resulting token.static interfaceA caller-supplied MCP call that throwsMcpInsufficientScopeExceptionon a step-up challenge. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of step-up attempts recorded for the given operation.static McpStepUpAuthorizer.Buildercreate()Static creator.<T> Texecute(String operation, McpStepUpAuthorizer.ScopedCall<T> call) Executes an MCP call, transparently handling SEP-2350 step-up: on aninsufficient_scopechallenge it unions the challenge scopes onto the accumulated set, re-authorizes, and retries — up to the configured attempt cap, after which it throws a permanentMcpAuthException.voidClears the recorded step-up attempt count for a single operation (e.g. after the caller has resolved the cause of a prior permanent failure), so a subsequentexecute(String, ScopedCall)may step up again.voidresetAll()Clears all recorded step-up attempt counts for this authorizer's resource across every operation.
-
Constructor Details
-
McpStepUpAuthorizer
Constructor.- Parameters:
b- The builder.
-
-
Method Details
-
create
Static creator.- Returns:
- A new builder.
-
execute
Executes an MCP call, transparently handling SEP-2350 step-up: on aninsufficient_scopechallenge it unions the challenge scopes onto the accumulated set, re-authorizes, and retries — up to the configured attempt cap, after which it throws a permanentMcpAuthException.- Type Parameters:
T- The call result type.- Parameters:
operation- The operation identifier (e.g.tools/call:deploy) used for per-operation attempt tracking. Must not benull or blank.call- The MCP call. Must not benull .- Returns:
- The successful call result.
- Throws:
McpAuthException- If step-up is disabled, or the attempt cap is exceeded (permanent authorization failure).
-
attempts
Returns the number of step-up attempts recorded for the given operation.- Parameters:
operation- The operation identifier. Must not benull or blank.- Returns:
- The recorded attempt count.
-
reset
Clears the recorded step-up attempt count for a single operation (e.g. after the caller has resolved the cause of a prior permanent failure), so a subsequentexecute(String, ScopedCall)may step up again.- Parameters:
operation- The operation identifier. Must not benull or blank.
-
resetAll
Clears all recorded step-up attempt counts for this authorizer's resource across every operation.
-