Annotation Interface McpResource


@Target(METHOD) @Retention(RUNTIME) public @interface McpResource
This annotation is used to mark a method as an MCP (Model Context Protocol) resource method.

The resource's URI must be specified explicitly. Resource metadata such as name, title, description, and MIME type can be specified via the corresponding attributes. If omitted, these metadata fields will default to the value of the name attribute and "text/plain".

Example usage:


 @McpResource(uri = "weather://forecast/{city}/{date}")
 public String getWeather() {
     // Method implementation...
 }
 
Author:
codeboyzhou
See Also:
  • Required Element Summary

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

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The description of the resource.
    The MIME type of the resource.
    The name of the resource.
    double
    The priority of the resource.
    io.modelcontextprotocol.spec.McpSchema.Role[]
    The roles required to access the resource.
    The title of the resource.
  • Element Details

    • uri

      String uri
      The URI of the resource.
      Returns:
      the URI of the resource
    • name

      String name
      The name of the resource. Defaults to the name of the annotated method.
      Returns:
      the name of the resource
      Default:
      ""
    • title

      String title
      The title of the resource. Defaults to the value of the name attribute.
      Returns:
      the title of the resource
      Default:
      ""
    • description

      String description
      The description of the resource. Defaults to the value of the name attribute.
      Returns:
      the description of the resource
      Default:
      ""
    • mimeType

      String mimeType
      The MIME type of the resource. Defaults to "text/plain".
      Returns:
      the MIME type of the resource
      Default:
      "text/plain"
    • roles

      io.modelcontextprotocol.spec.McpSchema.Role[] roles
      The roles required to access the resource. Defaults to McpSchema.Role.ASSISTANT and McpSchema.Role.USER.
      Returns:
      the roles required to access the resource
      Default:
      {ASSISTANT, USER}
    • priority

      double priority
      The priority of the resource. Defaults to 1.0.
      Returns:
      the priority of the resource
      Default:
      1.0