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
  • Method Details

    • validateReturnType

      protected void validateReturnType(Method method)
      Description copied from class: AbstractMcpProgressMethodCallback
      Validates 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:
      validateReturnType in class AbstractMcpProgressMethodCallback
      Parameters:
      method - The method to validate
    • isNotificationType

      protected boolean isNotificationType(Class<?> paramType)
      Accepts the ProgressParams of the modern schema in addition to the ProgressNotification of the legacy protocol.
      Overrides:
      isNotificationType in class AbstractMcpProgressMethodCallback
      Parameters:
      paramType - The parameter type to check
      Returns:
      true if the callback supports the parameter type
    • validateParameters

      protected void validateParameters(Method method)
      Accepts a ToolContext parameter next to the progress parameters.
      Overrides:
      validateParameters in class AbstractMcpProgressMethodCallback
      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:
      accept in interface Consumer<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 method
      IllegalArgumentException - 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 a ToolContext parameter.
      Parameters:
      progress - The modern progress, must not be null
      toolContext - The tool context of the tool call that reports the progress, or null if there is none
      Throws:
      AbstractMcpProgressMethodCallback.McpProgressMethodException - if there is an error invoking the progress method
      IllegalArgumentException - if the progress is null
      Since:
      2.1.0
    • builder

      public static SyncMcpProgressMethodCallback.Builder builder()
      Create a new builder.
      Returns:
      A new builder instance