Annotation Interface ResourceTemplate
Parameters
Resource template methods may have parameters of the following types:
String- the method must have oneStringparameter for each variable in theuriTemplate. In most cases these parameters must be annotated withResourceTemplateArgwith thenameattribute set, unless the code was compiled with the-parametersoption.ResourceTemplateArgalso allows other properties of the argument to be configured.McpRequest- to access information about the requestCancellation- to allow processing to be stopped if the client cancels the tool callProgress- 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)
Resource templates use Level 1 RFC 6570 URI template syntax to support dynamic
resources where parts of the URI are variable.
Method parameters can be configured using ResourceTemplateArg annotations.
- See Also:
-
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionThe Level 1 URI template that can be used to construct resource URIs. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionOptional annotations for the client.A description of what this resource template represents.The MIME type of this resource template.The unique name of the resource template.A human-readable title for the resource template. -
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 template.Each resource template bound to the same MCP server configuration 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 template name
- Default:
"<<element name>>"
-
title
String titleA human-readable title for the resource template.This is a short, user-friendly display name for the template.
- Returns:
- the template title
- Default:
""
-
description
String descriptionA description of what this resource template represents.- Returns:
- the template description
- Default:
""
-
uriTemplate
String uriTemplateThe Level 1 URI template that can be used to construct resource URIs.Examples:
"file:///{path}""db:///{database}/tables/{table}""api:///{version}/users/{userId}"
- Returns:
- the URI template
- See Also:
-
mimeType
String mimeTypeThe MIME type of this resource template.Examples:
"text/plain","application/json","image/png"- Returns:
- the MIME type
- Default:
""
-
annotations
Resource.Annotations annotationsOptional annotations for the client.These provide additional hints to clients about the resource template's metadata. Note that annotations must be declared explicitly to be included in resource metadata.
- Returns:
- the template annotations
- Default:
@org.mcpjava.server.resources.Resource.Annotations
-