ExAgent.MCP.Client.Tasks (ExAgent v3.0.0)

View Source

Host operations for the negotiated MCP Tasks extension.

Stability — Candidate.

Open an ExAgent.MCP.Client with tasks: true and protocol "2026-07-28". The peer must advertise the extension. A started task belongs to that remote endpoint and principal.

Summary

Functions

Signal cancellation of an existing task by ID.

Read an existing task by ID through the negotiated Tasks extension.

Dispatch a tool and return its ordinary result or {:task, task}.

Functions

cancel_task(client, id)

@spec cancel_task(ExAgent.MCP.Client.t(), String.t()) :: :ok | {:error, term()}

Signal cancellation of an existing task by ID.

:ok acknowledges the request. The remote task may still be working or may complete. Use get_task/2 to observe its state. A peer rejection of the ID returns {:error, :mcp_task_unknown} as in get_task/2.

get_task(client, id)

@spec get_task(ExAgent.MCP.Client.t(), String.t()) :: {:ok, map()} | {:error, term()}

Read an existing task by ID through the negotiated Tasks extension.

The returned map has "status" and includes "result" for a completed task or the JSON-RPC error code for a failed one. It is for the trusted host. A lookup error leaves the original tool outcome unconfirmed. Honor the server's "pollIntervalMs" between reads.

{:error, :mcp_task_unknown} means the peer rejected the task ID with JSON-RPC -32602. This covers invalid, unknown and expired task IDs. Use independent evidence to reconcile the original effect.

start_tool(client, name, arguments)

@spec start_tool(ExAgent.MCP.Client.t(), String.t(), map()) ::
  {:task, map()}
  | {:ok, String.t()}
  | {:content, [map()]}
  | {:tool_error, String.t()}
  | {:error, term()}

Dispatch a tool and return its ordinary result or {:task, task}.

When both peers opt into Tasks, the server may return a task with a server-generated "taskId" and a suggested "pollIntervalMs". Keep the handle in trusted host storage to follow it with get_task/2 or signal cancellation with cancel_task/2.