Class SyncModernMcpResourceMethodCallback
- All Implemented Interfaces:
io.modelcontextprotocol.modern.server.feature.McpSyncResource.Handler
resources/read of a 2026-07-28 ("modern") MCP server by invoking a
method annotated with @McpResource.
Beyond the parameters the stateless callback supports, a method may declare
McpModernSyncRequestContext, the SDK McpRequestContext,
McpSyncNotifier or the modern McpSchema.ReadResourceRequest (which carries the
MRTR fields). A method that declares the notifier is served as a streaming response so
that progress notifications can be pushed before the result; the context alone leaves
the response a plain result.
The method may return a modern McpSchema.ReadResourceOutcome (a
ReadResourceResult, possibly with cache hints, or an
InputRequiredResult) or any of the legacy return types, which are converted. A
converted legacy result carries the ttlMs() and cacheScope() hints
configured on the callback (from @McpResource); a modern result is passed
through untouched and its own hints win.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forSyncModernMcpResourceMethodCallbackinstances.Nested classes/interfaces inherited from class org.springframework.ai.mcp.annotation.method.resource.AbstractMcpResourceMethodCallback
AbstractMcpResourceMethodCallback.AbstractBuilder<T extends AbstractMcpResourceMethodCallback.AbstractBuilder<T,R>, R>, AbstractMcpResourceMethodCallback.ContentType -
Field Summary
Fields inherited from class org.springframework.ai.mcp.annotation.method.resource.AbstractMcpResourceMethodCallback
bean, contentType, description, meta, method, mimeType, name, resultConverter, uri, uriTemplateManager, uriVariables -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectassignExchangeType(Class<?> paramType, Object exchange) builder()io.modelcontextprotocol.modern.McpSchema.CacheScopeThecacheScopecache hint applied to converted legacy results.protected booleanisExchangeOrContextType(Class<?> paramType) Checks if a parameter type is compatible with the exchange type.static booleanisModernInfrastructureParameter(Class<?> parameterType) Whether a parameter of this type is injected by the modern callback rather than bound from the request URI.booleanio.modelcontextprotocol.modern.server.McpSyncResponse<io.modelcontextprotocol.modern.McpSchema.ReadResourceOutcome>read(io.modelcontextprotocol.modern.server.McpRequestContext context, io.modelcontextprotocol.modern.McpSchema.ReadResourceRequest request) longttlMs()ThettlMscache hint applied to converted legacy results.protected voidvalidateMethod(Method method) Validates that the method signature is compatible with the resource callback.protected voidvalidateReturnType(Method method) Validates that the method return type is compatible with the resource callback.Methods inherited from class org.springframework.ai.mcp.annotation.method.resource.AbstractMcpResourceMethodCallback
buildArgs, buildArgsWithoutUriVariables, buildArgsWithUriVariables, contentType, validateParametersWithoutUriVariables, validateParametersWithUriVariables, validateParamType
-
Method Details
-
isModernInfrastructureParameter
Whether a parameter of this type is injected by the modern callback rather than bound from the request URI. -
isStreaming
public boolean isStreaming() -
ttlMs
public long ttlMs()ThettlMscache hint applied to converted legacy results. -
cacheScope
public io.modelcontextprotocol.modern.McpSchema.CacheScope cacheScope()ThecacheScopecache hint applied to converted legacy results. -
read
public io.modelcontextprotocol.modern.server.McpSyncResponse<io.modelcontextprotocol.modern.McpSchema.ReadResourceOutcome> read(io.modelcontextprotocol.modern.server.McpRequestContext context, io.modelcontextprotocol.modern.McpSchema.ReadResourceRequest request) - Specified by:
readin interfaceio.modelcontextprotocol.modern.server.feature.McpSyncResource.Handler
-
validateMethod
Description copied from class:AbstractMcpResourceMethodCallbackValidates that the method signature is compatible with the resource callback.This method checks that the return type is valid and that the parameters match the expected pattern based on whether URI variables are present.
- Overrides:
validateMethodin classAbstractMcpResourceMethodCallback- Parameters:
method- The method to validate
-
validateReturnType
Description copied from class:AbstractMcpResourceMethodCallbackValidates that the method return type is compatible with the resource callback. This method should be implemented by subclasses to handle specific return type validation.- Specified by:
validateReturnTypein classAbstractMcpResourceMethodCallback- Parameters:
method- The method to validate
-
assignExchangeType
- Specified by:
assignExchangeTypein classAbstractMcpResourceMethodCallback
-
isExchangeOrContextType
Description copied from class:AbstractMcpResourceMethodCallbackChecks if a parameter type is compatible with the exchange type. This method should be implemented by subclasses to handle specific exchange type checking.- Specified by:
isExchangeOrContextTypein classAbstractMcpResourceMethodCallback- Parameters:
paramType- The parameter type to check- Returns:
- true if the parameter type is compatible with the exchange type, false otherwise
-
builder
-