Class AsyncMcpSamplingMethodCallback

java.lang.Object
org.springaicommunity.mcp.method.sampling.AbstractMcpSamplingMethodCallback
org.springaicommunity.mcp.method.sampling.AsyncMcpSamplingMethodCallback
All Implemented Interfaces:
Function<io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CreateMessageResult>>

public final class AsyncMcpSamplingMethodCallback extends AbstractMcpSamplingMethodCallback implements Function<io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CreateMessageResult>>
Class for creating Function callbacks around sampling methods that return Mono. This class provides a way to convert methods annotated with McpSampling into callback functions that can be used to handle sampling requests in a reactive way. It supports methods with a single CreateMessageRequest parameter.
Author:
Christian Tzolov
  • Method Details

    • apply

      public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CreateMessageResult> apply(io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest request)
      Apply the callback to the given request.

      This method builds the arguments for the method call, invokes the method, and returns a Mono that completes with the result.

      Specified by:
      apply in interface Function<io.modelcontextprotocol.spec.McpSchema.CreateMessageRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CreateMessageResult>>
      Parameters:
      request - The sampling request, must not be null
      Returns:
      A Mono that completes with the result of the method invocation
      Throws:
      AbstractMcpSamplingMethodCallback.McpSamplingMethodException - if there is an error invoking the sampling method
      IllegalArgumentException - if the request is null
    • validateReturnType

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

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

      public static AsyncMcpSamplingMethodCallback.Builder builder()
      Create a new builder.
      Returns:
      A new builder instance