Class McpTool

java.lang.Object
dev.relism.flash.ext.mcp.McpTool

public abstract class McpTool extends Object
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

invalid reference
McpConfig#toolsPackage(String)
— instantiated with its public no-arg constructor and bound once at boot, before the first 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 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 first tools/call. Infrastructure method — do not call from user code.
    • onInit

      protected void onInit()
      Override to cache services at boot time. See require(java.lang.Class<T>)/find(java.lang.Class<T>).
    • require

      protected <T> T require(Class<T> type)
    • find

      protected <T> Optional<T> find(Class<T> type)
    • optional

      protected <T> Optional<T> optional(Class<T> type)
    • call

      public abstract ToolResponse call(ToolArguments args) throws Exception
      Invoked on every matching tools/call request (hot path). args is a thin accessor over the already-parsed JSON arguments — no databinding.
      Throws:
      Exception