Class McpDuplexDispatcher

java.lang.Object
org.apache.juneau.rest.client.mcp.McpDuplexDispatcher

public class McpDuplexDispatcher extends Object
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 Details

  • Method Details

    • register

      Registers (or de-registers) the handler invoked by dispatch(JsonRpcRequest, BeanStore).
      Parameters:
      value - The handler to register. Passing null de-registers any previously-registered handler - a subsequent dispatch(JsonRpcRequest, BeanStore) call then behaves as if no handler was ever registered (see the "no handler" behavior documented there).
      Returns:
      This object.
    • dispatch

      public Object dispatch(JsonRpcRequest request, BeanStore ctx)
      Dispatches a single server-initiated request to the registered handler.

      When no handler is registered: a notification (a null id) is silently dropped (returns null); a request is rejected with a -32601 McpException.

      Parameters:
      request - The inbound request. Must not be null.
      ctx - The request-scoped bean store to hand to the handler. Can be null, in which case BasicBeanStore.INSTANCE is used instead.
      Returns:
      The handler's result, or null for a notification with no registered handler.
      Throws:
      McpException - If no handler is registered and request is not a notification, or if the handler itself throws (an McpException thrown by the handler propagates as-is; any other exception is wrapped as a -32603 internal-error McpException with the original exception preserved as its cause).