callToolWithCancellation method
Call a tool with cancellation support
Implementation
Future<CallToolResult> callToolWithCancellation(
String name,
Map<String, dynamic> arguments,
String operationId,
) async {
// Register the operation
final operation = PendingOperation(
id: operationId,
sessionId: 'system', // Use a system session for direct calls
type: 'tool:$name',
);
_pendingOperations[operationId] = operation;
try {
// Check if cancelled before starting
if (operation.isCancelled) {
throw McpError('Operation cancelled');
}
return await callTool(name, arguments);
} finally {
_pendingOperations.remove(operationId);
}
}