Class AbstractMcpPromptMethodCallback

java.lang.Object
org.springaicommunity.mcp.method.prompt.AbstractMcpPromptMethodCallback
Direct Known Subclasses:
AsyncMcpPromptMethodCallback, AsyncStatelessMcpPromptMethodCallback, SyncMcpPromptMethodCallback, SyncStatelessMcpPromptMethodCallback

public abstract class AbstractMcpPromptMethodCallback extends Object
Abstract base class for creating callbacks around prompt methods. This class provides common functionality for both synchronous and asynchronous prompt method callbacks.
Author:
Christian Tzolov
  • Field Details

    • method

      protected final Method method
    • bean

      protected final Object bean
    • prompt

      protected final io.modelcontextprotocol.spec.McpSchema.Prompt prompt
  • Constructor Details

    • AbstractMcpPromptMethodCallback

      protected AbstractMcpPromptMethodCallback(Method method, Object bean, io.modelcontextprotocol.spec.McpSchema.Prompt prompt)
      Constructor for AbstractMcpPromptMethodCallback.
      Parameters:
      method - The method to create a callback for
      bean - The bean instance that contains the method
      prompt - The prompt
  • Method Details

    • validateMethod

      protected void validateMethod(Method method)
      Validates that the method signature is compatible with the prompt callback.
      Parameters:
      method - The method to validate
      Throws:
      IllegalArgumentException - if the method signature is not compatible
    • validateReturnType

      protected abstract void validateReturnType(Method method)
      Validates that the method return type is compatible with the prompt callback.
      Parameters:
      method - The method to validate
      Throws:
      IllegalArgumentException - if the return type is not compatible
    • isSupportedExchangeOrContextType

      protected abstract boolean isSupportedExchangeOrContextType(Class<?> paramType)
      Checks if a parameter type is compatible with the exchange type.
      Parameters:
      paramType - The parameter type to check
      Returns:
      true if the parameter type is compatible with the exchange type, false otherwise
    • validateParamType

      protected void validateParamType(Class<?> paramType)
    • validateParameters

      protected void validateParameters(Method method)
      Validates method parameters.
      Parameters:
      method - The method to validate
      Throws:
      IllegalArgumentException - if the parameters are not compatible
    • assignExchangeType

      protected abstract Object assignExchangeType(Class<?> paramType, Object exchange)
    • buildArgs

      protected Object[] buildArgs(Method method, Object exchange, io.modelcontextprotocol.spec.McpSchema.GetPromptRequest request)
      Builds the arguments array for invoking the method.

      This method constructs an array of arguments based on the method's parameter types and the available values (exchange, request, arguments).

      Parameters:
      method - The method to build arguments for
      exchange - The server exchange
      request - The prompt request
      Returns:
      An array of arguments for the method invocation
    • convertArgumentValue

      protected Object convertArgumentValue(Object value, Class<?> targetType)
      Converts an argument value to the expected parameter type.
      Parameters:
      value - The value to convert
      targetType - The target type
      Returns:
      The converted value
    • convertToGetPromptResult

      protected io.modelcontextprotocol.spec.McpSchema.GetPromptResult convertToGetPromptResult(Object result)
      Converts a method result to a GetPromptResult.
      Parameters:
      result - The result to convert
      Returns:
      The converted GetPromptResult