Class SyncMcpProgressMethodCallback
java.lang.Object
org.springframework.ai.mcp.annotation.method.progress.AbstractMcpProgressMethodCallback
org.springframework.ai.mcp.annotation.method.progress.SyncMcpProgressMethodCallback
- All Implemented Interfaces:
Consumer<io.modelcontextprotocol.spec.McpSchema.ProgressNotification>
public final class SyncMcpProgressMethodCallback
extends AbstractMcpProgressMethodCallback
implements Consumer<io.modelcontextprotocol.spec.McpSchema.ProgressNotification>
Synchronous implementation of a progress method callback.
This class creates a Consumer that invokes a method annotated with @McpProgress
synchronously when a progress notification is received.
The method may take the ProgressNotification of the legacy protocol or the
ProgressParams of the 2026-07-28 ("modern") revision. Either way the callback
accepts the legacy notification; the progress of a modern client is converted to it
with ModernClientHandlerSupport.toLegacyProgress(io.modelcontextprotocol.modern.McpSchema.ProgressParams), which loses nothing.
The method may take a ToolContext as an additional parameter. It receives the
tool context of the tool call that reports the progress when the caller knows it, as
the tool callbacks of a modern connection do, and null otherwise.
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating SyncMcpProgressMethodCallback instances.Nested classes/interfaces inherited from class org.springframework.ai.mcp.annotation.method.progress.AbstractMcpProgressMethodCallback
AbstractMcpProgressMethodCallback.AbstractBuilder<T extends AbstractMcpProgressMethodCallback.AbstractBuilder<T,R>, R>, AbstractMcpProgressMethodCallback.McpProgressMethodException -
Field Summary
Fields inherited from class org.springframework.ai.mcp.annotation.method.progress.AbstractMcpProgressMethodCallback
bean, method -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(io.modelcontextprotocol.spec.McpSchema.ProgressNotification notification) Accept the progress notification and process it.voidacceptModern(io.modelcontextprotocol.modern.McpSchema.ProgressParams progress, @Nullable ToolContext toolContext) Accept the progress of a modern client, for a tool call with the given tool context.builder()Create a new builder.protected booleanisNotificationType(Class<?> paramType) Accepts theProgressParamsof the modern schema in addition to theProgressNotificationof the legacy protocol.protected voidvalidateParameters(Method method) Accepts aToolContextparameter next to the progress parameters.protected voidvalidateReturnType(Method method) Validates that the method return type is compatible with the progress callback.Methods inherited from class org.springframework.ai.mcp.annotation.method.progress.AbstractMcpProgressMethodCallback
buildArgs, validateMethod
-
Method Details
-
validateReturnType
Description copied from class:AbstractMcpProgressMethodCallbackValidates that the method return type is compatible with the progress callback. This method should be implemented by subclasses to handle specific return type validation.- Specified by:
validateReturnTypein classAbstractMcpProgressMethodCallback- Parameters:
method- The method to validate
-
isNotificationType
Accepts theProgressParamsof the modern schema in addition to theProgressNotificationof the legacy protocol.- Overrides:
isNotificationTypein classAbstractMcpProgressMethodCallback- Parameters:
paramType- The parameter type to check- Returns:
- true if the callback supports the parameter type
-
validateParameters
Accepts aToolContextparameter next to the progress parameters.- Overrides:
validateParametersin classAbstractMcpProgressMethodCallback- Parameters:
method- The method to validate
-
accept
public void accept(io.modelcontextprotocol.spec.McpSchema.ProgressNotification notification) Accept the progress notification and process it.This method builds the arguments for the method call and invokes the method.
- Specified by:
acceptin interfaceConsumer<io.modelcontextprotocol.spec.McpSchema.ProgressNotification>- Parameters:
notification- The progress notification, must not be null- Throws:
AbstractMcpProgressMethodCallback.McpProgressMethodException- if there is an error invoking the progress methodIllegalArgumentException- if the notification is null
-
acceptModern
public void acceptModern(io.modelcontextprotocol.modern.McpSchema.ProgressParams progress, @Nullable ToolContext toolContext) Accept the progress of a modern client, for a tool call with the given tool context. The method receives the tool context if it declares aToolContextparameter.- Parameters:
progress- The modern progress, must not be nulltoolContext- The tool context of the tool call that reports the progress, ornullif there is none- Throws:
AbstractMcpProgressMethodCallback.McpProgressMethodException- if there is an error invoking the progress methodIllegalArgumentException- if the progress is null- Since:
- 2.1.0
-
builder
Create a new builder.- Returns:
- A new builder instance
-