Package dev.tachyonmcp.core.server
Interface RpcMethodHandler
- All Known Implementing Classes:
AbstractAsyncMethodHandler,DiscoverHandler,EmptyResultHandler,InitializeHandler,PingHandler
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 Summary
Modifier and TypeMethodDescriptionhandle(DispatchContext context, @Nullable Object params) Handles the method and returns the result to serialize as JSON-RPC response.default CompletionStage<Object> handleAsync(DispatchContext context, @Nullable Object params) Handles the method asynchronously.method()The JSON-RPC method name this handler dispatches to.
-
Method Details
-
method
String method()The JSON-RPC method name this handler dispatches to.- Returns:
- the method name
-
handle
Handles the method and returns the result to serialize as JSON-RPC response.- Parameters:
context- the dispatch context with server and outbound stream accessparams- the method parameters, ornull- 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 tohandle(dev.tachyonmcp.core.server.session.DispatchContext, java.lang.Object). Override for async handlers that return a future directly.- Parameters:
context- the dispatch contextparams- the method parameters, ornull- Returns:
- a completion stage yielding the result
- Throws:
Exception- on handler failure
-