Class AbstractToolHandler
java.lang.Object
dev.tachyonmcp.api.server.features.tools.AbstractToolHandler
- All Implemented Interfaces:
ToolHandler,ServerFeature<ToolDescriptor>
- Direct Known Subclasses:
EchoToolHandler,YouComSearchTool
Experimental base class for class-based tool handlers.
Prefer Tools.register(ToolDescriptor, ToolFn) or Tools.registerAsync(ToolDescriptor, AsyncToolFn). Override exactly one of handle(InteractionContext, ToolRequest) or handleAsync(InteractionContext, ToolRequest).
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.tachyonmcp.api.server.ServerFeature
ServerFeature.Descriptor, ServerFeature.Request -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractToolHandler(ToolDescriptor descriptor) Creates a handler for the given descriptor. -
Method Summary
Modifier and TypeMethodDescriptionfinal ToolDescriptorReturns the tool descriptor.handle(InteractionContext context, ToolRequest request) Handles a tool request synchronously.CompletionStage<? extends ToolResult> handleAsync(InteractionContext context, ToolRequest request) Handles a tool request asynchronously.
-
Constructor Details
-
AbstractToolHandler
Creates a handler for the given descriptor.- Parameters:
descriptor- the tool descriptor
-
-
Method Details
-
descriptor
Returns the tool descriptor.- Specified by:
descriptorin interfaceServerFeature<ToolDescriptor>- Specified by:
descriptorin interfaceToolHandler- Returns:
- the tool descriptor
-
handleAsync
public CompletionStage<? extends ToolResult> handleAsync(InteractionContext context, ToolRequest request) Handles a tool request asynchronously.The default implementation delegates to
handle(InteractionContext, ToolRequest).- Specified by:
handleAsyncin interfaceToolHandler- Parameters:
context- the interaction contextrequest- the tool request- Returns:
- the pending tool result
-
handle
Handles a tool request synchronously.- Parameters:
context- the interaction contextrequest- the tool request- Returns:
- the tool result
- Throws:
Exception- when handling fails
-