Class AsyncStatelessMcpPromptMethodCallback

java.lang.Object
org.springaicommunity.mcp.method.prompt.AbstractMcpPromptMethodCallback
org.springaicommunity.mcp.method.prompt.AsyncStatelessMcpPromptMethodCallback
All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.GetPromptRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.GetPromptResult>>

public final class AsyncStatelessMcpPromptMethodCallback extends AbstractMcpPromptMethodCallback implements BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.GetPromptRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.GetPromptResult>>
Class for creating BiFunction callbacks around prompt methods with asynchronous processing for stateless contexts. This class provides a way to convert methods annotated with McpPrompt into callback functions that can be used to handle prompt requests asynchronously in stateless environments. It supports various method signatures and return types.
Author:
Christian Tzolov
  • Method Details

    • validateParamType

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

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

      public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.GetPromptResult> apply(io.modelcontextprotocol.common.McpTransportContext context, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest 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 GetPromptResult.

      Specified by:
      apply in interface BiFunction<io.modelcontextprotocol.common.McpTransportContext,io.modelcontextprotocol.spec.McpSchema.GetPromptRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.GetPromptResult>>
      Parameters:
      context - The transport context, may be null if the method doesn't require it
      request - The prompt request, must not be null
      Returns:
      A Mono that emits the prompt result
      Throws:
      McpPromptMethodException - if there is an error invoking the prompt method
      IllegalArgumentException - if the request is null
    • isSupportedExchangeOrContextType

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

      protected void validateReturnType(Method method)
      Description copied from class: AbstractMcpPromptMethodCallback
      Validates that the method return type is compatible with the prompt callback.
      Specified by:
      validateReturnType in class AbstractMcpPromptMethodCallback
      Parameters:
      method - The method to validate
    • builder

      Create a new builder.
      Returns:
      A new builder instance