Class AsyncStatelessMcpResourceMethodCallback

java.lang.Object
org.springaicommunity.mcp.method.resource.AbstractMcpResourceMethodCallback
org.springaicommunity.mcp.method.resource.AsyncStatelessMcpResourceMethodCallback
All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.ReadResourceResult>>

public final class AsyncStatelessMcpResourceMethodCallback extends AbstractMcpResourceMethodCallback implements BiFunction<io.modelcontextprotocol.common.McpTransportContext,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 for stateless contexts. This class provides a way to convert methods annotated with McpResource into callback functions that can be used to handle resource requests asynchronously in stateless environments. It supports various method signatures and return types, and handles URI template variables.
Author:
Christian Tzolov
  • Method Details

    • validateParamType

      protected void validateParamType(Class<?> paramType)
      Overrides:
      validateParamType in class AbstractMcpResourceMethodCallback
    • assignExchangeType

      protected Object assignExchangeType(Class<?> paramType, Object exchange)
      Specified by:
      assignExchangeType in class AbstractMcpResourceMethodCallback
    • apply

      public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.ReadResourceResult> apply(io.modelcontextprotocol.common.McpTransportContext context, io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest request)
      Apply the callback to the given context 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:
      apply in interface BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.ReadResourceResult>>
      Parameters:
      context - The transport context, may be null if the method doesn't require it
      request - 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 method
      IllegalArgumentException - if the request is null or if URI variable extraction fails
    • builder

      Create a new builder.
      Returns:
      A new builder instance
    • validateReturnType

      protected void validateReturnType(Method method)
      Validates that the method return type is compatible with the resource callback.
      Specified by:
      validateReturnType in class AbstractMcpResourceMethodCallback
      Parameters:
      method - The method to validate
      Throws:
      IllegalArgumentException - if the return type is not compatible
    • isExchangeOrContextType

      protected boolean isExchangeOrContextType(Class<?> paramType)
      Checks if a parameter type is compatible with the exchange type.
      Specified by:
      isExchangeOrContextType in class AbstractMcpResourceMethodCallback
      Parameters:
      paramType - The parameter type to check
      Returns:
      true if the parameter type is compatible with the exchange type, false otherwise