Class AsyncMcpToolMethodCallback

java.lang.Object
org.springaicommunity.mcp.method.tool.AbstractMcpToolMethodCallback<T,RC>
org.springaicommunity.mcp.method.tool.AbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.server.McpAsyncServerExchange,McpAsyncRequestContext>
org.springaicommunity.mcp.method.tool.AsyncMcpToolMethodCallback
All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.server.McpAsyncServerExchange,io.modelcontextprotocol.spec.McpSchema.CallToolRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>>

public final class AsyncMcpToolMethodCallback extends AbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.server.McpAsyncServerExchange,McpAsyncRequestContext> implements BiFunction<io.modelcontextprotocol.server.McpAsyncServerExchange,io.modelcontextprotocol.spec.McpSchema.CallToolRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>>
Class for creating Function callbacks around tool methods. This class provides a way to convert methods annotated with McpTool into callback functions that can be used to handle tool requests.
Author:
Christian Tzolov
  • Constructor Details

    • AsyncMcpToolMethodCallback

      public AsyncMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject)
    • AsyncMcpToolMethodCallback

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

    • isExchangeOrContextType

      protected boolean isExchangeOrContextType(Class<?> paramType)
      Description copied from class: AbstractAsyncMcpToolMethodCallback
      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 AbstractAsyncMcpToolMethodCallback<io.modelcontextprotocol.server.McpAsyncServerExchange,McpAsyncRequestContext>
      Parameters:
      paramType - The parameter type to check
      Returns:
      true if the parameter type is an exchange or context type, false otherwise
    • createRequestContext

      protected McpAsyncRequestContext createRequestContext(io.modelcontextprotocol.server.McpAsyncServerExchange exchange, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request)
      Specified by:
      createRequestContext in class AbstractMcpToolMethodCallback<io.modelcontextprotocol.server.McpAsyncServerExchange,McpAsyncRequestContext>
    • apply

      public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> apply(io.modelcontextprotocol.server.McpAsyncServerExchange exchange, io.modelcontextprotocol.spec.McpSchema.CallToolRequest request)
      Apply the callback to the given request.

      This method builds the arguments for the method call, invokes the method, and returns the result.

      Specified by:
      apply in interface BiFunction<io.modelcontextprotocol.server.McpAsyncServerExchange,io.modelcontextprotocol.spec.McpSchema.CallToolRequest,reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>>
      Parameters:
      exchange - The server exchange context
      request - The tool call request, must not be null
      Returns:
      The result of the method invocation