Class SyncMcpCompleteMethodCallback
java.lang.Object
org.springaicommunity.mcp.method.complete.AbstractMcpCompleteMethodCallback
org.springaicommunity.mcp.method.complete.SyncMcpCompleteMethodCallback
- All Implemented Interfaces:
BiFunction<io.modelcontextprotocol.server.McpSyncServerExchange,io.modelcontextprotocol.spec.McpSchema.CompleteRequest, io.modelcontextprotocol.spec.McpSchema.CompleteResult>
public final class SyncMcpCompleteMethodCallback
extends AbstractMcpCompleteMethodCallback
implements BiFunction<io.modelcontextprotocol.server.McpSyncServerExchange,io.modelcontextprotocol.spec.McpSchema.CompleteRequest,io.modelcontextprotocol.spec.McpSchema.CompleteResult>
Class for creating BiFunction callbacks around complete methods.
This class provides a way to convert methods annotated with
McpComplete into
callback functions that can be used to handle completion requests. It supports various
method signatures and return types, and handles both prompt and URI template
completions.- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating SyncMcpCompleteMethodCallback instances.Nested classes/interfaces inherited from class org.springaicommunity.mcp.method.complete.AbstractMcpCompleteMethodCallback
AbstractMcpCompleteMethodCallback.AbstractBuilder<T extends AbstractMcpCompleteMethodCallback.AbstractBuilder<T,R>, R>, AbstractMcpCompleteMethodCallback.McpCompleteMethodException -
Field Summary
Fields inherited from class org.springaicommunity.mcp.method.complete.AbstractMcpCompleteMethodCallback
bean, completeReference, method, prompt, uri, uriTemplateManager, uriVariables -
Method Summary
Modifier and TypeMethodDescriptionio.modelcontextprotocol.spec.McpSchema.CompleteResultapply(io.modelcontextprotocol.server.McpSyncServerExchange exchange, io.modelcontextprotocol.spec.McpSchema.CompleteRequest request) Apply the callback to the given exchange and request.builder()Create a new builder.protected booleanisExchangeType(Class<?> paramType) Checks if a parameter type is compatible with the exchange type.protected voidvalidateReturnType(Method method) Validates that the method return type is compatible with the complete callback.Methods inherited from class org.springaicommunity.mcp.method.complete.AbstractMcpCompleteMethodCallback
buildArgs, validateMethod, validateParametersMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.BiFunction
andThen
-
Method Details
-
apply
public io.modelcontextprotocol.spec.McpSchema.CompleteResult apply(io.modelcontextprotocol.server.McpSyncServerExchange exchange, io.modelcontextprotocol.spec.McpSchema.CompleteRequest 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 CompleteResult.
- Specified by:
applyin interfaceBiFunction<io.modelcontextprotocol.server.McpSyncServerExchange,io.modelcontextprotocol.spec.McpSchema.CompleteRequest, io.modelcontextprotocol.spec.McpSchema.CompleteResult> - Parameters:
exchange- The server exchange, may be null if the method doesn't require itrequest- The complete request, must not be null- Returns:
- The complete result
- Throws:
AbstractMcpCompleteMethodCallback.McpCompleteMethodException- if there is an error invoking the complete methodIllegalArgumentException- if the request is null
-
builder
Create a new builder.- Returns:
- A new builder instance
-
validateReturnType
Validates that the method return type is compatible with the complete callback.- Specified by:
validateReturnTypein classAbstractMcpCompleteMethodCallback- Parameters:
method- The method to validate- Throws:
IllegalArgumentException- if the return type is not compatible
-
isExchangeType
Checks if a parameter type is compatible with the exchange type.- Specified by:
isExchangeTypein classAbstractMcpCompleteMethodCallback- Parameters:
paramType- The parameter type to check- Returns:
- true if the parameter type is compatible with the exchange type, false otherwise
-