callToolWithCancellation method

Future<CallToolResult> callToolWithCancellation(
  1. String name,
  2. Map<String, dynamic> arguments,
  3. String operationId
)

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);
  }
}