Interface Progress


public interface Progress
Provides access to progress reporting capabilities for MCP requests.

If an MCP client specifies a progress token in a request, the server can send progress notification messages back to the client during request processing.

Tool, Prompt, Resource, and ResourceTemplate methods can accept this interface as a parameter. Framework implementations will automatically inject it before invoking the method.

Example usage:

 @Tool(description = "Process large dataset")
 public String processData(
         @ToolArg(name = "data") String data,
         Progress progress) {
     if (progress.token().isPresent()) {
         ProgressTracker tracker = progress.trackerBuilder()
             .setTotal(100)
             .setDefaultStep(10)
             .build();
         // Use tracker.advanceAndForget() as work progresses
     }
     // ... process data
 }
 
See Also:
  • Method Details

    • token

      Gets the progress token if present in the request.

      If the client didn't include a progress token, this returns Optional.empty().

      Returns:
      the progress token if present
    • notificationBuilder

      ProgressNotification.Builder notificationBuilder()
      Creates a builder for a progress notification.

      ProgressNotification can be used to send individual notification messages.

      Returns:
      a new notification builder
      Throws:
      IllegalStateException - if the progress token is not present
    • trackerBuilder

      ProgressTracker.Builder trackerBuilder()
      Creates a builder for a progress tracker.

      ProgressTracker is a stateful, thread-safe construct that can be used to update progress status and send notification messages automatically.

      Returns:
      a new tracker builder
      Throws:
      IllegalStateException - if the progress token is not present