cancelTask method

Future<Task?> cancelTask(
  1. String taskId, {
  2. Map<String, dynamic>? meta,
  3. RequestOptions? options,
})

Cancel a task (tasks/cancel). 2025-11-25 answers with the cancelled task; the 2026-07-28 extension only acknowledges (null).

Implementation

Future<Task?> cancelTask(String taskId, {Map<String, dynamic>? meta, RequestOptions? options}) async {
  if (!isConnected) throw McpError('Client is not connected to a transport');
  final response = Map<String, dynamic>.from(
      await _sendRequest('tasks/cancel', _withMeta({'taskId': taskId}, meta), options) as Map);
  return response['taskId'] is String ? Task.fromJson(response) : null;
}