Class McpResource

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

public abstract class McpResource extends Object
Base class for a single MCP resource — one class per resource, mirroring McpTool. Declare metadata with @Resource, cache services in onInit(), implement read() for the hot path.

 @Resource(uri = "config://app-settings", description = "Application settings", mimeType = "application/json")
 public class AppSettingsResource extends McpResource {
     @Override public ResourceContents read() {
         return TextResourceContents.of(uri(), "application/json", settingsJson());
     }
 }
 
  • Constructor Details

    • McpResource

      public McpResource()
  • Method Details

    • bind

      public final void bind(dev.relism.flash.extension.FlashContext ctx)
      Called once by the framework after instantiation, before the first resources/read. Infrastructure method — do not call from user code.
    • onInit

      protected void onInit()
    • 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)
    • uri

      protected final String uri()
      URI declared via @Resource, cached at bind time.
    • read

      public abstract ResourceContents read() throws Exception
      Invoked on every matching resources/read request (hot path).
      Throws:
      Exception