addToolWithProgress method

void addToolWithProgress(
  1. String name,
  2. String description,
  3. Map<String, dynamic> inputSchema,
  4. Future<CallToolResult> handler(
    1. Map<String, dynamic> arguments, {
    2. dynamic onProgress(
      1. double,
      2. String
      )?,
    }),
)

Add a tool with progress support

Implementation

void addToolWithProgress(
  String name,
  String description,
  Map<String, dynamic> inputSchema,
  Future<CallToolResult> Function(
    Map<String, dynamic> arguments, {
    Function(double, String)? onProgress,
  })
  handler,
) {
  addTool(
    name: name,
    description: description,
    inputSchema: inputSchema,
    handler: (arguments) async {
      // The operation the dispatcher registered for this call. Minting a
      // new id here would address a call that does not exist, and the
      // progress would go nowhere.
      final operationId = Zone.current[#mcpOperationId] as String?;
      return await handler(
        arguments,
        onProgress: (progress, message) {
          if (operationId == null) return;
          notifyProgress(operationId, progress, message);
        },
      );
    },
  );
}