Class McpOptions
2026-07-28 MCP endpoint behaves) — the single
v2-only aggregate consolidating every per-binding tunable McpEndpoint/McpRestServlet previously
exposed as six separate hooks: capabilities, instructions, cache, mrtr,
subscriptions, and subscriptionBroker.
Mutable during setup, effectively immutable once published. Same builder-less mutable-setup idiom as
McpCacheConfig/McpMrtrConfig/McpSubscriptionsConfig and the neutral
org.apache.juneau.rest.server.mcp.McpServerConfig it sits next to: configure fully via the single
createMcpOptions() (servlet-subclass path) / getMcpOptions() (mixin path) override, then never
mutate it afterward. The framework memoizes exactly one instance per binding (see McpRestServlet.getMcpOptions()
and McpEndpoint.getMcpOptions()), so a request-time reader sees a stable, request-independent snapshot.
The three nested configs (cache, mrtr, subscriptions) are framework-owned instances created once, here, at construction time. Use the
cache(Consumer)/mrtr(Consumer)/subscriptions(Consumer) configure-blocks to mutate
them in place — callers never new a replacement nested config, so the "must return a stable
instance" footgun the pre-consolidation hooks warned about cannot recur.
The subscription broker default:
getSubscriptionBroker() defaults to BasicMcpSubscriptionBroker sized from getSubscriptions()'s
queueSize the first time a broker is needed, and memoizes that
one derived instance for the lifetime of the binding (a fresh broker per call would silently split live
subscribers and publishers across unrelated registries). Call setSubscriptionBroker(McpSubscriptionBroker)
to supply a custom broker instead (for example one shared across multiple bindings on purpose).
The idleTimeoutMs / heartbeatIntervalMs caveat:
When configuring subscriptions(Consumer), keep
heartbeatIntervalMs below
idleTimeoutMs (see that method's Javadoc) — otherwise
the idle-timeout watchdog can reap a perfectly healthy connection between two heartbeats.
Example:
McpOptionsoptions =new McpOptions() .setInstructions("Use tool 'echo' to test." ) .cache(c ->c .setToolsList(new McpCacheHint().setTtlMs(60_000))) .subscriptions(s ->s .setQueueSize(2048));
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncache(Consumer<McpCacheConfig> consumer) Mutates this binding's cache configuration in place.getCache()This binding's cache-hint configuration.Optional explicit capabilities advertisement forserver/discover.Optional free-formserver/discoverusage instructions advertised to clients.getMrtr()This binding's MRTR (Multi-Round-Trip Request) configuration.This binding's OAuth 2.1 resource-server (RS) configuration.The explicit subscription broker for this binding, if one was supplied.This binding'ssubscriptions/listenconfiguration.mrtr(Consumer<McpMrtrConfig> consumer) Mutates this binding's MRTR configuration in place.ReturnsgetSubscriptionBroker()if explicitly set, otherwise lazily derives and memoizes aBasicMcpSubscriptionBrokersized fromgetSubscriptions()'s queue bound.resourceServer(Consumer<McpResourceServerConfig> consumer) Mutates this binding's resource-server configuration in place.setCache(McpCacheConfig value) Replaces this binding's cache configuration outright.Sets the explicitserver/discovercapabilities advertisement.setInstructions(String value) Sets theserver/discoverusage instructions.setMrtr(McpMrtrConfig value) Replaces this binding's MRTR configuration outright.Replaces this binding's resource-server configuration outright.Sets an explicit subscription broker, bypassing the framework-derived default.Replaces this binding's subscriptions configuration outright.subscriptions(Consumer<McpSubscriptionsConfig> consumer) Mutates this binding's subscriptions configuration in place.
-
Constructor Details
-
McpOptions
public McpOptions()
-
-
Method Details
-
getCapabilities
Optional explicit capabilities advertisement forserver/discover.- Returns:
- The explicit capabilities, or
null to auto-derive from the registered tool / prompt / resource lists (the default).
-
setCapabilities
Sets the explicitserver/discovercapabilities advertisement.A non-
null value bypasses auto-derivation entirely and advertises exactly what is supplied.- Parameters:
value- The new value. Can benull to auto-derive.- Returns:
- This object (for method chaining).
-
getInstructions
Optional free-formserver/discoverusage instructions advertised to clients.- Returns:
- The instructions, or
null to omit them from the discovery result (the default).
-
setInstructions
Sets theserver/discoverusage instructions.- Parameters:
value- The new value. Can benull to omit them.- Returns:
- This object (for method chaining).
-
getCache
This binding's cache-hint configuration.- Returns:
- The framework-owned cache configuration. Never
null .
-
setCache
Replaces this binding's cache configuration outright.- Parameters:
value- The new value. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
cache
Mutates this binding's cache configuration in place.Preferred over
setCache(McpCacheConfig)for incremental configuration since it operates on the framework-owned instance rather than requiring the caller to construct a replacement.- Parameters:
consumer- Callback invoked with the framework-ownedMcpCacheConfig. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifconsumerisnull .
-
getMrtr
This binding's MRTR (Multi-Round-Trip Request) configuration.- Returns:
- The framework-owned MRTR configuration. Never
null .
-
setMrtr
Replaces this binding's MRTR configuration outright.- Parameters:
value- The new value. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
mrtr
Mutates this binding's MRTR configuration in place.- Parameters:
consumer- Callback invoked with the framework-ownedMcpMrtrConfig. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifconsumerisnull .
-
getResourceServer
This binding's OAuth 2.1 resource-server (RS) configuration.- Returns:
- The framework-owned RS configuration. Never
null . Disabled by default.
-
setResourceServer
Replaces this binding's resource-server configuration outright.- Parameters:
value- The new value. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
resourceServer
Mutates this binding's resource-server configuration in place.- Parameters:
consumer- Callback invoked with the framework-ownedMcpResourceServerConfig. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifconsumerisnull .
-
getSubscriptions
This binding'ssubscriptions/listenconfiguration.- Returns:
- The framework-owned subscriptions configuration. Never
null .
-
setSubscriptions
Replaces this binding's subscriptions configuration outright.- Parameters:
value- The new value. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifvalueisnull .
-
subscriptions
Mutates this binding's subscriptions configuration in place.- Parameters:
consumer- Callback invoked with the framework-ownedMcpSubscriptionsConfig. Must not benull .- Returns:
- This object (for method chaining).
- Throws:
IllegalArgumentException- Ifconsumerisnull .
-
getSubscriptionBroker
The explicit subscription broker for this binding, if one was supplied.- Returns:
- The explicit broker, or
null if none was supplied (the default) — in which case the binding lazily derives and memoizes one (seeresolveSubscriptionBroker()).
-
setSubscriptionBroker
Sets an explicit subscription broker, bypassing the framework-derived default.Setting this after
resolveSubscriptionBroker()has already derived and published a default broker for this instance does not retroactively clear or replace that already-published derived broker —resolveSubscriptionBroker()always prefers an explicit value set here over a previously-derived one, but under the never-mutate-after-setup contract this method should only be called during configuration, before the binding is handed to the framework.- Parameters:
value- The new value. Can benull to revert to the framework-derived default.- Returns:
- This object (for method chaining).
-
resolveSubscriptionBroker
ReturnsgetSubscriptionBroker()if explicitly set, otherwise lazily derives and memoizes aBasicMcpSubscriptionBrokersized fromgetSubscriptions()'s queue bound.This is the effective broker accessor: unlike
getSubscriptionBroker()(which returnsnull by default), this method never returnsnull , deriving a default the first time one is needed. Internal plumbing forMcpEndpoint.subscriptionBroker()/McpRestServlet.getSubscriptionBroker(). Since thisMcpOptionsinstance is itself memoized once per binding, the derived broker this method publishes is likewise stable for the binding's lifetime — publication uses double-checked locking (not a plain lazy read) because twoBasicMcpSubscriptionBrokerinstances are not equivalent: each holds distinct live per-connection subscription state, so a benign publication race would silently split subscribers and publishers across two unrelated registries.- Returns:
- The subscription broker to use. Never
null .
-