Class AsyncMcpPromptMethodCallback

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

public final class AsyncMcpPromptMethodCallback extends AbstractMcpPromptMethodCallback implements BiFunction<io.modelcontextprotocol.server.McpAsyncServerExchange,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. This class provides a way to convert methods annotated with McpPrompt into callback functions that can be used to handle prompt requests asynchronously. 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.server.McpAsyncServerExchange exchange, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest request)
      Apply the callback to the given exchange 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.server.McpAsyncServerExchange,io.modelcontextprotocol.spec.McpSchema.GetPromptRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.GetPromptResult>>
      Parameters:
      exchange - The server exchange, 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

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