Annotation Interface McpResource


@Target({METHOD,ANNOTATION_TYPE}) @Retention(RUNTIME) @Documented public @interface McpResource
Marks a method as a MCP Resource.
Author:
Christian Tzolov, Alexandros Pappas, Vadzim Shurmialiou, Craig Walls
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Optional annotations for the client.
    io.modelcontextprotocol.modern.McpSchema.CacheScope
    Who may reuse a cached result of reading this resource.
    A description of what this resource represents.
    Optional icons for clients that render a catalogue.
    Class<? extends MetaProvider>
    Optional meta provider class that supplies data for "_meta" field for this resource declaration.
    The MIME type of this resource, if known.
    Intended for programmatic or logical use, but used as a display name in past specs or fallback (if title isn’t present).
    Client capabilities the resource cannot work without.
    long
    Optional size of the resource content in bytes, when known up front.
    Optional human-readable name of the prompt for display purposes.
    long
    How long, in milliseconds, a client may cache the result of reading this resource.
    the URI of the resource.
  • Element Details

    • name

      String name
      Intended for programmatic or logical use, but used as a display name in past specs or fallback (if title isn’t present).
      Default:
      ""
    • title

      String title
      Optional human-readable name of the prompt for display purposes.
      Default:
      ""
    • uri

      String uri
      the URI of the resource.
      Default:
      ""
    • description

      String description
      A description of what this resource represents. This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
      Default:
      ""
    • mimeType

      String mimeType
      The MIME type of this resource, if known.
      Default:
      "text/plain"
    • annotations

      Optional annotations for the client. Note: The default annotations value is ignored.
      Default:
      @org.springframework.ai.mcp.annotation.McpResource.McpAnnotations(audience={USER}, lastModified="", priority=0.5)
    • metaProvider

      Class<? extends MetaProvider> metaProvider
      Optional meta provider class that supplies data for "_meta" field for this resource declaration. Defaults to DefaultMetaProvider implementation.
      Returns:
      the meta provider class to use for this resource
      Default:
      org.springframework.ai.mcp.annotation.context.DefaultMetaProvider.class
    • icons

      McpIcon[] icons
      Optional icons for clients that render a catalogue.
      Since:
      2.1.0
      Default:
      {}
    • size

      long size
      Optional size of the resource content in bytes, when known up front. -1 (the default) leaves it unset.
      Since:
      2.1.0
      Default:
      -1L
    • ttlMs

      long ttlMs
      How long, in milliseconds, a client may cache the result of reading this resource. 0 (the default) means the result must not be cached.

      Only honoured by the 2026-07-28 ("modern") MCP server, which puts the value into the ttlMs field of the resources/read result when the method returns a legacy type. A method that returns a modern ReadResourceResult sets its own hints and this attribute is ignored. The legacy servers log a warning and ignore it, because the legacy protocol has no cache hints.

      Since:
      2.1.0
      Default:
      0L
    • cacheScope

      io.modelcontextprotocol.modern.McpSchema.CacheScope cacheScope
      Who may reuse a cached result of reading this resource. McpSchema.CacheScope.PRIVATE (the default) restricts reuse to the same authorization context. McpSchema.CacheScope.PUBLIC asserts the result carries no user-specific data and may be served to any client.

      Only honoured by the 2026-07-28 ("modern") MCP server, under the same rules as ttlMs().

      Since:
      2.1.0
      Default:
      PRIVATE
    • requiredCapabilities

      McpClientCapability[] requiredCapabilities
      Client capabilities the resource cannot work without. A client whose request does not declare all of them is answered with JSON-RPC error -32021 Missing required client capability, listing the missing ones, before the method runs.

      Input the resource can do without is requested only when McpModernSyncRequestContext.clientCapabilities() declares its capability, and needs no entry here.

      Only honoured by the 2026-07-28 ("modern") MCP server. The legacy servers ignore it, because their request context checks the capabilities the client sent at initialization.

      experimental and extension capabilities cannot be required this way; a method that depends on one is registered programmatically with ClientCapabilities.

      Since:
      2.1.0
      Default:
      {}