Class McpDuplexDispatcher
java.lang.Object
org.apache.juneau.rest.client.mcp.McpDuplexDispatcher
Dispatches server-initiated JSON-RPC requests delivered over an MCP client's duplex event-stream channel to a
single registered
McpServerRequestHandler.
Requests are handed to the registered handler untouched, with their params left as the generic,
revision-neutral wire representation - never projected into a typed request bean - since the set of
server-initiated methods (for example sampling/createMessage; illustrative only, as sampling is
deprecated per SEP-2577) is revision- and deployment-specific and this dispatcher has no knowledge of it.
- Since:
- 10.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondispatch(JsonRpcRequest request, BeanStore ctx) Dispatches a single server-initiated request to the registered handler.register(McpServerRequestHandler value) Registers (or de-registers) the handler invoked bydispatch(JsonRpcRequest, BeanStore).
-
Constructor Details
-
McpDuplexDispatcher
public McpDuplexDispatcher()
-
-
Method Details
-
register
Registers (or de-registers) the handler invoked bydispatch(JsonRpcRequest, BeanStore).- Parameters:
value- The handler to register. Passingnull de-registers any previously-registered handler - a subsequentdispatch(JsonRpcRequest, BeanStore)call then behaves as if no handler was ever registered (see the "no handler" behavior documented there).- Returns:
- This object.
-
dispatch
Dispatches a single server-initiated request to the registered handler.When no handler is registered: a notification (a
null id) is silently dropped (returnsnull ); a request is rejected with a-32601McpException.- Parameters:
request- The inbound request. Must not benull .ctx- The request-scoped bean store to hand to the handler. Can benull , in which caseBasicBeanStore.INSTANCEis used instead.- Returns:
- The handler's result, or
null for a notification with no registered handler. - Throws:
McpException- If no handler is registered andrequestis not a notification, or if the handler itself throws (anMcpExceptionthrown by the handler propagates as-is; any other exception is wrapped as a-32603internal-errorMcpExceptionwith the original exception preserved as its cause).
-