Annotation Interface Resource


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface Resource
Method annotation to define an MCP Resource handler. The annotated method will be invoked to read the contents of the declared resource URI. This mirrors Prompt for prompts and allows declaring Resources declaratively. Minimal usage:
 @Singleton
 class MyResources {
   @Resource(uri = "example://hello", name = "hello", title = "Hello", description = "Hello text", mimeType = "text/plain")
   String hello() {
     return "Hello World";
   }
 }
 
Supported method signatures: - No parameters - Single parameter of type String (receives the requested URI) - Single 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 Future improvements may add support for additional content types.
  • Field Details

  • Element Details

    • uri

      String uri
      Returns:
      The resource URI this handler serves (e.g. "pgn://round/1"). For now this is a concrete URI, not a template.
    • 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>>"
    • 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"