Annotation Interface Resource


@Target(METHOD) @Retention(RUNTIME) @Documented public @interface Resource
Marks a method as providing an MCP resource.

Parameters

Resource methods may have parameters of the following types:

  • McpRequest - to access information about the request
  • Cancellation - to allow processing to be stopped if the client cancels the resource fetch request
  • Progress - to send progress reports back to the client
  • Implementations may define additional types that can be used as parameters

Return Type Handling

The result of a "resource read" operation is represented as a resource response. The annotated method can return various types that will be converted according to framework-specific rules:

  • String - Converted to text resource contents
  • byte[] - Converted to blob resource contents
  • ResourceContents implementations - Used directly in the response
  • List of ResourceContents - Multiple content items in the response
  • ResourceResponse - Used directly as the response
  • Other types - Encoded according to framework-specific rules (typically as JSON)
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Nested annotation for resource metadata annotations.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The URI of this resource.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Optional annotations for the client.
    A description of what this resource represents.
    The MIME type of this resource, if known.
    The unique name of the resource.
    int
    The size of the raw resource content, in bytes (before base64 encoding or any tokenization), if known.
    A human-readable title for the resource.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constant value for name() indicating that the annotated element's name should be used as-is.
  • Field Details

    • ELEMENT_NAME

      static final String ELEMENT_NAME
      Constant value for name() indicating that the annotated element's name should be used as-is.
      See Also:
  • Element Details

    • name

      String name
      The unique name of the resource.

      Each resource must have a unique name. This is intended for programmatic or logical use, but may be used for UI display as a fallback if title() is not present.

      By default, the name is derived from the annotated method name.

      Returns:
      the resource name
      Default:
      "<<element name>>"
    • title

      String title
      A human-readable title for the resource.

      This is a short, user-friendly display name for the resource.

      Returns:
      the resource title
      Default:
      ""
    • description

      String description
      A description of what this resource represents.
      Returns:
      the resource description
      Default:
      ""
    • uri

      String uri
      The URI of this resource.

      This is a required field that uniquely identifies the resource.

      Returns:
      the resource URI
    • mimeType

      String mimeType
      The MIME type of this resource, if known.

      Examples: "text/plain", "application/json", "image/png"

      Returns:
      the MIME type
      Default:
      ""
    • size

      int size
      The size of the raw resource content, in bytes (before base64 encoding or any tokenization), if known.
      Returns:
      the resource size, or -1 if unknown
      Default:
      -1
    • annotations

      Optional annotations for the client.

      These provide additional hints to clients about the resource's metadata. Note that annotations must be declared explicitly to be included in resource metadata.

      Returns:
      the resource annotations
      Default:
      @org.mcpjava.server.resources.Resource.Annotations