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 Summary
FieldsModifier and TypeFieldDescriptionFields inherited from class org.springaicommunity.mcp.method.tool.AbstractMcpToolMethodCallback
returnMode, toolMethod, toolObject -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractAsyncMcpToolMethodCallback(ReturnMode returnMode, Method toolMethod, Object toolObject, Class<? extends Throwable> toolCallExceptionClass) -
Method Summary
Modifier and TypeMethodDescriptionprotected reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>convertToCallToolResult(Object result) Convert reactive types to Monoprotected reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>Creates an error result for exceptions that occur during method invocation.protected abstract booleanisExchangeOrContextType(Class<?> paramType) Determines if the given parameter type is an exchange or context type that should be injected.protected io.modelcontextprotocol.spec.McpSchema.CallToolResultmapValueToCallToolResult(Object value) Map individual values to CallToolResult This method delegates to the parent class's convertValueToCallToolResult method to avoid code duplication.protected reactor.core.publisher.Mono<Void>validateRequest(io.modelcontextprotocol.spec.McpSchema.CallToolRequest request) Validates that the request is not null.Methods inherited from class org.springaicommunity.mcp.method.tool.AbstractMcpToolMethodCallback
buildMethodArguments, buildTypedArgument, callMethod, convertValueToCallToolResult, createErrorMessage, createRequestContext, findCauseUsingPlainJava
-
Field Details
-
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
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:
isExchangeOrContextTypein classAbstractMcpToolMethodCallback<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
-