Class AsyncMcpResourceMethodCallback
java.lang.Object
org.springaicommunity.mcp.method.resource.AbstractMcpResourceMethodCallback
org.springaicommunity.mcp.method.resource.AsyncMcpResourceMethodCallback
- All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.server.McpAsyncServerExchange,io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest, reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.ReadResourceResult>>
public final class AsyncMcpResourceMethodCallback
extends AbstractMcpResourceMethodCallback
implements BiFunction<io.modelcontextprotocol.server.McpAsyncServerExchange,io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.ReadResourceResult>>
Class for creating BiFunction callbacks around resource methods with asynchronous
processing.
This class provides a way to convert methods annotated with
McpResource into
callback functions that can be used to handle resource requests asynchronously. It
supports various method signatures and return types, and handles URI template
variables.- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating AsyncMcpResourceMethodCallback instances.Nested classes/interfaces inherited from class org.springaicommunity.mcp.method.resource.AbstractMcpResourceMethodCallback
AbstractMcpResourceMethodCallback.AbstractBuilder<T extends AbstractMcpResourceMethodCallback.AbstractBuilder<T,R>, R>, AbstractMcpResourceMethodCallback.ContentType -
Field Summary
Fields inherited from class org.springaicommunity.mcp.method.resource.AbstractMcpResourceMethodCallback
bean, contentType, description, method, mimeType, name, resultConverter, uri, uriTemplateManager, uriVariables -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.ReadResourceResult>apply(io.modelcontextprotocol.server.McpAsyncServerExchange exchange, io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest request) Apply the callback to the given exchange and request.protected ObjectassignExchangeType(Class<?> paramType, Object exchange) builder()Create a new builder.protected booleanisExchangeOrContextType(Class<?> paramType) Checks if a parameter type is compatible with the exchange type.protected voidvalidateParamType(Class<?> paramType) protected voidvalidateReturnType(Method method) Validates that the method return type is compatible with the resource callback.Methods inherited from class org.springaicommunity.mcp.method.resource.AbstractMcpResourceMethodCallback
buildArgs, buildArgsWithoutUriVariables, buildArgsWithUriVariables, contentType, validateMethod, validateParametersWithoutUriVariables, validateParametersWithUriVariablesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThen
-
Method Details
-
validateParamType
- Overrides:
validateParamTypein classAbstractMcpResourceMethodCallback
-
assignExchangeType
- Specified by:
assignExchangeTypein classAbstractMcpResourceMethodCallback
-
apply
public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.ReadResourceResult> apply(io.modelcontextprotocol.server.McpAsyncServerExchange exchange, io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest request) Apply the callback to the given exchange and request.This method extracts URI variable values from the request URI, builds the arguments for the method call, invokes the method, and converts the result to a ReadResourceResult.
- Specified by:
applyin interfaceBiFunction<io.modelcontextprotocol.server.McpAsyncServerExchange,io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest, reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.ReadResourceResult>> - Parameters:
exchange- The server exchange, may be null if the method doesn't require itrequest- The resource request, must not be null- Returns:
- A Mono that emits the resource result
- Throws:
McpResourceMethodException- if there is an error invoking the resource methodIllegalArgumentException- if the request is null or if URI variable extraction fails
-
builder
Create a new builder.- Returns:
- A new builder instance
-
validateReturnType
Validates that the method return type is compatible with the resource callback.- Specified by:
validateReturnTypein classAbstractMcpResourceMethodCallback- Parameters:
method- The method to validate- Throws:
IllegalArgumentException- if the return type is not compatible
-
isExchangeOrContextType
Checks if a parameter type is compatible with the exchange type.- 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
-