addToolWithProgress method
void
addToolWithProgress()
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 {
// Placeholder - will be replaced below
return CallToolResult(content: []);
},
);
// Wrap the handler to support progress
_toolHandlers[name] = (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);
});
};
}