Annotation Interface Resource
Parameters
Resource methods may have parameters of the following types:
McpRequest- to access information about the requestCancellation- to allow processing to be stopped if the client cancels the resource fetch requestProgress- 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 contentsbyte[]- Converted to blob resource contentsResourceContentsimplementations - 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 ClassesModifier and TypeClassDescriptionstatic @interfaceNested annotation for resource metadata annotations. -
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionOptional 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.intThe 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
-
Field Details
-
ELEMENT_NAME
Constant value forname()indicating that the annotated element's name should be used as-is.- See Also:
-
-
Element Details
-
name
String nameThe 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 titleA human-readable title for the resource.This is a short, user-friendly display name for the resource.
- Returns:
- the resource title
- Default:
""
-
description
String descriptionA description of what this resource represents.- Returns:
- the resource description
- Default:
""
-
uri
String uriThe URI of this resource.This is a required field that uniquely identifies the resource.
- Returns:
- the resource URI
-
mimeType
String mimeTypeThe MIME type of this resource, if known.Examples:
"text/plain","application/json","image/png"- Returns:
- the MIME type
- Default:
""
-
size
int sizeThe 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
Resource.Annotations annotationsOptional 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
-