Annotation Interface ResourceTemplate


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface ResourceTemplate
Method annotation to define an MCP Resource Template handler. The annotated method will be invoked to read the contents of the declared resource template. This allows to define resource templates declaratively. Minimal usage:
 @Singleton
 class MyResourceTemplates {
   @ResourceTemplate(uriTemplate = "example://hello/{locale}", name = "hello", title = "Hello", description = "Hello text", mimeType = "text/plain")
   String hello(String locale) {
     if (locale.equals("es) {
         return "Hola Mundo";
     }
     return "Hello World";
   }
 }
 
Supported method parameters: - parameter of type io.micronaut.mcp.server.context.MicronautMcpTransportContext - parameter of type io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest Supported return types: - String: returned as text content with the configured mimeType() - io.modelcontextprotocol.spec.McpSchema.ReadResourceResult: used as-is
  • Field Details

  • Element Details

    • name

      String name
      Returns:
      Each resource must have a unique name. By default, the name is derived from the name of the annotated method.
      Default:
      "<<element name>>"
    • uriTemplate

      String uriTemplate
      Returns:
      The resource URI this handler serves (e.g. ""file:///{path}").
      Default:
      "pgn://round/{round}"
    • title

      String title
      Returns:
      A concise human-readable title of the resource.
      Default:
      ""
    • description

      String description
      Returns:
      A human-readable description of the resource.
      Default:
      ""
    • mimeType

      String mimeType
      Returns:
      The MIME type of the returned content (e.g. "text/plain", "application/json").
      Default:
      "text/plain"