ExMCP.Tasks (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Durable lifecycle helpers for the MCP Tasks extension.

create/3 inserts a task into the configured store before returning its CreateTaskResult. Server callbacks can use get/2, update/3, and cancel/2 for the modern task methods, while workers use the transition and input-response helpers.

The current request principal, tenant, and endpoint are included in the store owner automatically. A worker outside a server callback should retain owner/1 from the creating request and pass it back with owner: owner.

Successful creates and wire-visible transitions asynchronously publish the full modern state to authorized subscriptions/listen task filters. Pass a non-default registry as subscription_registry: registry; use notify: false only when the host owns publication.

Summary

Functions

Records a cooperative cancellation request and acknowledges it.

Returns whether cooperative cancellation was requested.

Atomically completes a working task.

Synchronously creates and stores a task before returning its wire handle.

Atomically fails a working task with a JSON-RPC error object.

Returns the authorized full wire state for one task.

Atomically marks a cooperatively stopped task as cancelled.

Builds the non-secret authorization owner for the current request.

Atomically changes a non-terminal task's status message.

Atomically moves a working task to input-required.

Atomically drains input responses accepted for a task worker.

Idempotently submits responses for currently outstanding task inputs.

Types

task_error()

@type task_error() ::
  {:error, ExMCP.Tasks.Store.store_error() | :task_store_unavailable}

Functions

cancel(task_id, opts \\ [])

@spec cancel(
  String.t(),
  keyword()
) :: :ok | task_error()

Records a cooperative cancellation request and acknowledges it.

cancellation_requested?(task_id, opts \\ [])

@spec cancellation_requested?(
  String.t(),
  keyword()
) :: {:ok, boolean()} | task_error()

Returns whether cooperative cancellation was requested.

complete(task_id, result, opts \\ [])

@spec complete(String.t(), map(), keyword()) ::
  {:ok, ExMCP.Tasks.Task.t()} | task_error()

Atomically completes a working task.

create(tool_name, arguments \\ %{}, opts \\ [])

@spec create(String.t(), map(), keyword()) :: {:ok, map()} | task_error()

Synchronously creates and stores a task before returning its wire handle.

fail(task_id, error, opts \\ [])

@spec fail(String.t(), map(), keyword()) :: {:ok, ExMCP.Tasks.Task.t()} | task_error()

Atomically fails a working task with a JSON-RPC error object.

get(task_id, opts \\ [])

@spec get(
  String.t(),
  keyword()
) :: {:ok, map()} | task_error()

Returns the authorized full wire state for one task.

mark_cancelled(task_id, opts \\ [])

@spec mark_cancelled(
  String.t(),
  keyword()
) :: {:ok, ExMCP.Tasks.Task.t()} | task_error()

Atomically marks a cooperatively stopped task as cancelled.

owner(opts \\ [])

@spec owner(keyword()) :: ExMCP.Tasks.Store.owner()

Builds the non-secret authorization owner for the current request.

put_status_message(task_id, message, opts \\ [])

@spec put_status_message(String.t(), String.t() | nil, keyword()) ::
  {:ok, ExMCP.Tasks.Task.t()} | task_error()

Atomically changes a non-terminal task's status message.

require_input(task_id, input_requests, opts \\ [])

@spec require_input(String.t(), map(), keyword()) ::
  {:ok, ExMCP.Tasks.Task.t()} | task_error()

Atomically moves a working task to input-required.

take_input_responses(task_id, opts \\ [])

@spec take_input_responses(
  String.t(),
  keyword()
) :: {:ok, map()} | task_error()

Atomically drains input responses accepted for a task worker.

update(task_id, input_responses, opts \\ [])

@spec update(String.t(), map(), keyword()) :: :ok | task_error()

Idempotently submits responses for currently outstanding task inputs.