Interface RpcMethodHandler

All Known Implementing Classes:
AbstractAsyncMethodHandler, DiscoverHandler, EmptyResultHandler, InitializeHandler, PingHandler

@InternalApi public interface RpcMethodHandler
Handles a single JSON-RPC method. Internal/advanced SPI — receives the rich DispatchContext (server, response mapper, outbound stream).

handle(dev.tachyonmcp.core.server.session.DispatchContext, java.lang.Object) runs on a virtual thread per request. Handler code may block for I/O — that is the intended VT contract — but must never use synchronized, call native methods, or otherwise pin the carrier thread. Use ReentrantLock over synchronized for mutual exclusion. For CPU-bound work or third-party code that may synchronize, offload to context.engine().executor() and join the result:


 var future = CompletableFuture.supplyAsync(
         () -> heavyWork(), context.engine().executor());
 return HandlerFutures.joinInterruptibly(future);
 
  • Method Details

    • method

      String method()
      The JSON-RPC method name this handler dispatches to.
      Returns:
      the method name
    • handle

      Object handle(DispatchContext context, @Nullable Object params) throws Exception
      Handles the method and returns the result to serialize as JSON-RPC response.
      Parameters:
      context - the dispatch context with server and outbound stream access
      params - the method parameters, or null
      Returns:
      the result to serialize
      Throws:
      Exception - on handler failure
    • handleAsync

      default CompletionStage<Object> handleAsync(DispatchContext context, @Nullable Object params) throws Exception
      Handles the method asynchronously. Default delegates to handle(dev.tachyonmcp.core.server.session.DispatchContext, java.lang.Object). Override for async handlers that return a future directly.
      Parameters:
      context - the dispatch context
      params - the method parameters, or null
      Returns:
      a completion stage yielding the result
      Throws:
      Exception - on handler failure