Package dev.relism.flash.ext.mcp
Class McpTool
java.lang.Object
dev.relism.flash.ext.mcp.McpTool
Base class for a single MCP tool — one class per tool, mirroring
RequestHandler: declare metadata with @Tool,
cache services in onInit(), implement call(ToolArguments) for the hot path.
Discovered via
— instantiated with its public
no-arg constructor and bound once at boot, before the first invalid reference
McpConfig#toolsPackage(String)tools/call request.
@Tool(name = "get_weather", description = "Get current weather for a city",
args = @ToolArg(name = "city", required = true))
public class GetWeatherTool extends McpTool {
private WeatherService weatherService;
@Override protected void onInit() {
weatherService = require(WeatherService.class);
}
@Override public ToolResponse call(ToolArguments args) {
return ToolResponse.success(new TextContent(weatherService.fetch(args.getString("city"))));
}
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidbind(dev.relism.flash.extension.FlashContext ctx) Called once by the framework after instantiation, before the firsttools/call.abstract ToolResponsecall(ToolArguments args) Invoked on every matchingtools/callrequest (hot path).protected <T> Optional<T> protected voidonInit()Override to cache services at boot time.protected <T> Optional<T> protected <T> T
-
Constructor Details
-
McpTool
public McpTool()
-
-
Method Details
-
bind
public final void bind(dev.relism.flash.extension.FlashContext ctx) Called once by the framework after instantiation, before the firsttools/call. Infrastructure method — do not call from user code. -
onInit
protected void onInit()Override to cache services at boot time. Seerequire(java.lang.Class<T>)/find(java.lang.Class<T>). -
require
-
find
-
optional
-
call
Invoked on every matchingtools/callrequest (hot path).argsis a thin accessor over the already-parsed JSON arguments — no databinding.- Throws:
Exception
-