Anubis. Server. Session. Tasks
(anubis_mcp v1.14.0)
Copy Markdown
Tasks runtime for a session (MCP spec 2025-11-25).
Owns the lifecycle of task-augmented tools/call executions: capability
checks, task creation and worker spawn, status transitions, cancellation,
TTL expiry, result storage through the configured Anubis.Server.TaskStore
adapter, and replies to tasks/result waiters.
State fields (tasks, task_refs, task_store) live in the Session's
state map; this module transforms them and performs the side effects
(worker spawn, monitors, timers, store calls, waiter replies) at the
edges. Anubis.Server.Session delegates to this module and supplies a
frame_fn to prepare frames lazily.
Summary
Functions
Returns true if the request is a tools/call carrying task augmentation
params.
Builds the task store configuration from the :task_store session option.
Handles a task-augmented tools/call: validates support, tool existence,
and tool task policy, then spawns the worker task and replies with the
CreateTaskResult.
Dispatches a tasks/* request (tasks/get, tasks/result, tasks/cancel,
tasks/list), replying inline or registering a result waiter for
non-terminal tasks.
Sends a notifications/tasks/status notification for the given task to the
client transport.
Handles TTL expiry of a live task: terminates the worker, releases waiters with an expiry error, and deletes the task from the store.
Finalizes the task runtime for a completed worker, deriving the terminal status from the handler result.
Finalizes the task runtime as failed when its worker crashes.
Returns the task ID owning the given worker monitor ref, if any.
Terminates all live task workers, demonitors them, and releases their waiters with the given error. Used during session termination.
Types
@type frame_fn() :: (state() -> Anubis.Server.Frame.t())
@type state() :: map()
@type task_waiter() :: {from :: GenServer.from(), request_id :: String.t() | integer()}
Functions
Returns true if the request is a tools/call carrying task augmentation
params.
Builds the task store configuration from the :task_store session option.
@spec create_for_tools_call(map(), map(), GenServer.from(), state(), frame_fn()) :: {:reply, {:ok, binary()}, state()}
Handles a task-augmented tools/call: validates support, tool existence,
and tool task policy, then spawns the worker task and replies with the
CreateTaskResult.
@spec dispatch_request(map(), map(), GenServer.from(), state(), frame_fn()) :: {:reply, {:ok, binary()}, state()} | {:noreply, state()}
Dispatches a tasks/* request (tasks/get, tasks/result, tasks/cancel,
tasks/list), replying inline or registering a result waiter for
non-terminal tasks.
Sends a notifications/tasks/status notification for the given task to the
client transport.
Handles TTL expiry of a live task: terminates the worker, releases waiters with an expiry error, and deletes the task from the store.
Finalizes the task runtime for a completed worker, deriving the terminal status from the handler result.
Finalizes the task runtime as failed when its worker crashes.
Returns the task ID owning the given worker monitor ref, if any.
@spec terminate_all(state(), Anubis.MCP.Error.t()) :: :ok
Terminates all live task workers, demonitors them, and releases their waiters with the given error. Used during session termination.