Class AsyncStatelessMcpCompleteMethodCallback

java.lang.Object
org.springaicommunity.mcp.method.complete.AbstractMcpCompleteMethodCallback
org.springaicommunity.mcp.method.complete.AsyncStatelessMcpCompleteMethodCallback
All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CompleteRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CompleteResult>>

public final class AsyncStatelessMcpCompleteMethodCallback extends AbstractMcpCompleteMethodCallback implements BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CompleteRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CompleteResult>>
Class for creating BiFunction callbacks around complete methods with asynchronous processing for stateless contexts. This class provides a way to convert methods annotated with McpComplete into callback functions that can be used to handle completion requests asynchronously in stateless environments. It supports various method signatures and return types, and handles both prompt and URI template completions.
Author:
Christian Tzolov
  • Method Details

    • apply

      public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CompleteResult> apply(io.modelcontextprotocol.common.McpTransportContext context, io.modelcontextprotocol.spec.McpSchema.CompleteRequest request)
      Apply the callback to the given context and request.

      This method builds the arguments for the method call, invokes the method, and converts the result to a CompleteResult.

      Specified by:
      apply in interface BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.CompleteRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CompleteResult>>
      Parameters:
      context - The transport context, may be null if the method doesn't require it
      request - The complete request, must not be null
      Returns:
      A Mono that emits the complete result
      Throws:
      AbstractMcpCompleteMethodCallback.McpCompleteMethodException - if there is an error invoking the complete method
      IllegalArgumentException - if the request is null
    • 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 complete callback.
      Specified by:
      validateReturnType in class AbstractMcpCompleteMethodCallback
      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 AbstractMcpCompleteMethodCallback
      Parameters:
      paramType - The parameter type to check
      Returns:
      true if the parameter type is compatible with the exchange type, false otherwise