Class AsyncModernMcpResourceMethodCallback
- All Implemented Interfaces:
io.modelcontextprotocol.modern.server.feature.McpAsyncResource.Handler
SyncModernMcpResourceMethodCallback: serves a
resources/read of a 2026-07-28 ("modern") MCP server by invoking a method
annotated with @McpResource.
A method may declare McpModernRequestContext, the SDK
McpRequestContext, McpAsyncNotifier 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 Mono, a CompletionStage or a Publisher
of a modern McpSchema.ReadResourceOutcome or of any legacy return type, which is
converted. A declared Flux is rejected at startup, and a publisher that emits
more than one element fails the call; see ModernReactiveSupport. A plain,
blocking return value runs through McpModernAsyncUtils.fromBlocking(io.modelcontextprotocol.modern.server.McpRequestContext, java.util.concurrent.Callable<T>). 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 forAsyncModernMcpResourceMethodCallbackinstances.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.booleanreactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.McpAsyncResponse<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 reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.McpAsyncResponse<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.McpAsyncResource.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
-