Class AbstractAsyncMcpToolMethodCallback<T,RC extends McpRequestContextTypes<?>>

java.lang.Object
org.springaicommunity.mcp.method.tool.AbstractMcpToolMethodCallback<T,RC>
org.springaicommunity.mcp.method.tool.AbstractAsyncMcpToolMethodCallback<T,RC>
Type Parameters:
T - The type of the context parameter (e.g., McpAsyncServerExchange or McpTransportContext)
Direct Known Subclasses:
AbstractSyncMcpToolMethodCallback, AsyncMcpToolMethodCallback, AsyncStatelessMcpToolMethodCallback

public abstract class AbstractAsyncMcpToolMethodCallback<T,RC extends McpRequestContextTypes<?>> extends AbstractMcpToolMethodCallback<T,RC>
Abstract base class for creating Function callbacks around async tool methods. This class provides common functionality for converting methods annotated with McpTool into callback functions that can be used to handle tool requests asynchronously.
Author:
Christian Tzolov
  • Field Details

    • toolCallExceptionClass

      protected final Class<? extends Throwable> toolCallExceptionClass
  • Constructor Details

    • AbstractAsyncMcpToolMethodCallback

      protected AbstractAsyncMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, Class<? extends Throwable> toolCallExceptionClass)
  • Method Details

    • convertToCallToolResult

      protected reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> convertToCallToolResult(Object result)
      Convert reactive types to Mono
      Parameters:
      result - The result from the method invocation
      Returns:
      A Mono representing the processed result
    • mapValueToCallToolResult

      protected io.modelcontextprotocol.spec.McpSchema.CallToolResult mapValueToCallToolResult(Object value)
      Map individual values to CallToolResult This method delegates to the parent class's convertValueToCallToolResult method to avoid code duplication.
      Parameters:
      value - The value to map
      Returns:
      A CallToolResult representing the mapped value
    • createAsyncErrorResult

      protected reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> createAsyncErrorResult(Exception e)
      Creates an error result for exceptions that occur during method invocation.
      Parameters:
      e - The exception that occurred
      Returns:
      A Mono representing the error
    • validateRequest

      protected reactor.core.publisher.Mono<Void> validateRequest(io.modelcontextprotocol.spec.McpSchema.CallToolRequest request)
      Validates that the request is not null.
      Parameters:
      request - The request to validate
      Returns:
      A Mono error if the request is null, otherwise Mono.empty()
    • isExchangeOrContextType

      protected abstract boolean isExchangeOrContextType(Class<?> paramType)
      Determines if the given parameter type is an exchange or context type that should be injected. Subclasses must implement this method to specify which types are considered exchange or context types.
      Specified by:
      isExchangeOrContextType in class AbstractMcpToolMethodCallback<T,RC extends McpRequestContextTypes<?>>
      Parameters:
      paramType - The parameter type to check
      Returns:
      true if the parameter type is an exchange or context type, false otherwise