Class McpResourceServerConfig
2026-07-28 MCP endpoint — the
authorization-hardening baseline.
Off by default. isEnabled() is enabled, so an
existing MCP endpoint that does not opt in behaves exactly as before (no bearer requirement, no well-known route).
When enabled, the endpoint:
- Requires a valid RFC 6750 bearer token on the MCP POST endpoint, establishing an authenticated principal.
- Serves an RFC 9728 Protected Resource Metadata document from
.well-known/oauth-protected-resource. - Answers a missing/invalid token with
401+ aWWW-Authenticate: Bearer ...challenge carrying theresource_metadatapointer. - Enforces RFC 8707 audience matching against
the resource identifier.
Mutable during setup, effectively immutable once published — the same builder-less mutable-setup idiom as
McpMrtrConfig / McpCacheConfig: configure it fully via the createMcpOptions() /
getMcpOptions() override, then never mutate it afterward (a request-time reader sees it with no
synchronization).
Token-validation mode:
The validation mode (RFC 7662 introspection vs JWKS/issuer JWT verification) is selected by which
TokenValidator is supplied to setTokenValidator(TokenValidator):
OAuthIntrospectionValidator (from juneau-rest-server-auth-oauth) for opaque tokens, or
JwtTokenValidator (from juneau-rest-server-auth-jwt) for JWT access tokens.
- Since:
- 10.0.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAuthorizationServer(URI value) Adds an authorization-server issuer URI.addOperationScope(String method, String name, String... scopes) Registers the scopes required to invoke a specific MCP operation (SEP-2350 per-operation step-up).addRequiredScope(String value) Adds a required scope (also advertised as supported).addScopeSupported(String value) Adds an advertised supported scope.The RFC 8707 audience this server accepts.The advertisedauthorization_servers(RFC 9728).The advertisedbearer_methods_supported(RFC 9728 / RFC 6750).The dynamic per-operation scope resolver, if one was installed.getRealm()TheWWW-Authenticate: Bearer realm="..."challenge realm.The scopes a token must carry to access the MCP endpoint (baseline insufficient-scope enforcement).This server's canonical resource identifier (RFC 9728resource/ RFC 8707 audience default).The advertisedscopes_supported(RFC 9728).The token validator that verifies presented bearer tokens.booleanWhether RS authentication is enabled for this binding.booleanWhether a validated token must expose audience claims for RFC 8707 audience enforcement to apply.Resolves the scopes required to invoke the given operation.setAudience(String value) Sets an explicit RFC 8707 audience, overriding theresource-identifierdefault.setEnabled(boolean value) Enables or disables RS authentication.Installs a dynamic per-operation scope resolver, overriding the default staticmap.Sets the challenge realm.setRequireAudienceClaim(boolean value) Sets whether a validated token must expose audience claims for audience enforcement to apply.setResource(URI value) Sets the canonical resource identifier.setTokenValidator(TokenValidator value) Sets the token validator (selects introspection vs JWT validation mode).voidValidates that this config is internally consistent for theenabledstate.
-
Field Details
-
DEFAULT_REALM
Default challenge realm.- See Also:
-
DEFAULT_BEARER_METHOD
Default advertised/accepted bearer method.- See Also:
-
-
Constructor Details
-
McpResourceServerConfig
public McpResourceServerConfig()
-
-
Method Details
-
isEnabled
Whether RS authentication is enabled for this binding.- Returns:
true if enabled. Defaults tofalse .
-
setEnabled
Enables or disables RS authentication.- Parameters:
value- The new value.- Returns:
- This object (for method chaining).
-
getResource
This server's canonical resource identifier (RFC 9728resource/ RFC 8707 audience default).- Returns:
- The resource identifier, or
null if not set.
-
setResource
Sets the canonical resource identifier.- Parameters:
value- The new value. Can benull to unset (but is required whenenabled).- Returns:
- This object (for method chaining).
-
getAudience
The RFC 8707 audience this server accepts.- Returns:
- The explicit audience, or (when unset)
the resource identifieras a string, ornull if neither is set.
-
setAudience
Sets an explicit RFC 8707 audience, overriding theresource-identifierdefault.- Parameters:
value- The new value. Can benull to fall back to the resource identifier.- Returns:
- This object (for method chaining).
-
getRealm
TheWWW-Authenticate: Bearer realm="..."challenge realm.- Returns:
- The realm. Never
null ; defaults to "mcp".
-
setRealm
Sets the challenge realm.- Parameters:
value- The new value. Must not benull or blank.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull or blank.
-
isRequireAudienceClaim
Whether a validated token must expose audience claims for RFC 8707 audience enforcement to apply.When
true (the default), a validator that returns a barePrincipalcarrying no claims is rejected (401 invalid_token) rather than silently passing the confused-deputy defense. Set tofalse only when thetoken validatoritself enforces the audience internally (e.g. aJwtTokenValidatorconfigured to verifyaud) so a claims-less principal is a deliberate, trusted signal — pairs with introspection-mode validators that legitimately omitaud.- Returns:
true if a claims-less principal is rejected (the default).
-
setRequireAudienceClaim
Sets whether a validated token must expose audience claims for audience enforcement to apply.- Parameters:
value- The new value. Defaults totrue (fail-closed).- Returns:
- This object (for method chaining).
-
getTokenValidator
The token validator that verifies presented bearer tokens.- Returns:
- The validator, or
null if not set (required whenenabled).
-
setTokenValidator
Sets the token validator (selects introspection vs JWT validation mode).- Parameters:
value- The new value. Can benull to unset (but is required whenenabled).- Returns:
- This object (for method chaining).
-
getAuthorizationServers
The advertisedauthorization_servers(RFC 9728).- Returns:
- A live, mutable list. Never
null .
-
addAuthorizationServer
Adds an authorization-server issuer URI.- Parameters:
value- The issuer URI. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
getScopesSupported
The advertisedscopes_supported(RFC 9728).- Returns:
- A live, mutable set. Never
null .
-
addScopeSupported
Adds an advertised supported scope.- Parameters:
value- The scope. Must not benull or blank.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull or blank.
-
getRequiredScopes
The scopes a token must carry to access the MCP endpoint (baseline insufficient-scope enforcement).- Returns:
- A live, mutable set. Never
null ; empty means no scope is required beyond a valid token.
-
addRequiredScope
Adds a required scope (also advertised as supported).- Parameters:
value- The scope. Must not benull or blank.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull or blank.
-
getBearerMethodsSupported
The advertisedbearer_methods_supported(RFC 9728 / RFC 6750).- Returns:
- A live, mutable set. Never
null ; defaults to[header].
-
addOperationScope
Registers the scopes required to invoke a specific MCP operation (SEP-2350 per-operation step-up).Populates the default static per-operation scope map consulted by
requiredScopesFor(McpOperationContext)when no explicitresolveris set. Anullor blanknameregisters a method-wide entry matching every operation of that JSON-RPCmethod(e.g. everytools/callregardless of tool name); a specificnametakes precedence over the method-wide entry. Each supplied scope is also advertised assupported.- Parameters:
method- The JSON-RPC method (e.g.tools/call). Must not benull or blank.name- The operation name (tool/prompt name or resource URI), ornull /blank for a method-wide entry.scopes- The scopes required to invoke the operation. Must not benull , empty, or contain anull /blank element.- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifmethodisnull /blank orscopesis invalid.
-
getOperationScopeResolver
The dynamic per-operation scope resolver, if one was installed.- Returns:
- The resolver, or
null to use the default staticmap.
-
setOperationScopeResolver
Installs a dynamic per-operation scope resolver, overriding the default staticmap.The seam for a future dynamic resolver; not built for 10.0. When set, it fully replaces the static map for
requiredScopesFor(McpOperationContext).- Parameters:
value- The resolver, ornull to revert to the static map.- Returns:
- This object (for method chaining).
-
requiredScopesFor
Resolves the scopes required to invoke the given operation.Consults the
resolverwhen installed; otherwise the staticmap, preferring aname-specific entry over the method-wide "*" entry. An empty return means "no per-operation requirement beyond the endpoint-widebaseline".- Parameters:
ctx- The resolved operation. Must not benull .- Returns:
- The required scopes (never
null ; possibly empty).
-
validateEnabled
Validates that this config is internally consistent for theenabledstate.A no-op when disabled. When enabled, requires a resource identifier (absolute, with scheme + authority) and a token validator.
- Throws:
IllegalStateException- If enabled but misconfigured.
-