barrel_mcp_tasks (barrel_mcp v2.0.2)
View SourceLong-running operation registry (MCP tasks).
Tools registered with long_running => true return immediately with a taskId instead of synchronously producing a result. The worker continues in the background; clients poll via tasks/get, enumerate via tasks/list, and abort via tasks/cancel. State transitions emit notifications/tasks/status on the session's SSE channel.
Tasks live in a protected ETS table keyed by {SessionId, TaskId}. A periodic sweep evicts terminal tasks (success / error / cancelled) older than ?TASK_TTL.
Summary
Functions
Mark a task as cancelled and notify the client. Sends {cancel, RequestId} to the worker pid (if recorded) so cooperative arity-2 handlers can abort.
Create a new running task. Returns the task id.
Record failure: store the error and emit notification.
Record success: store the result and emit notifications/tasks/status.
Record the worker pid (and optional originating request id) on a running task so a later tasks/cancel can stop it.
Functions
Mark a task as cancelled and notify the client. Sends {cancel, RequestId} to the worker pid (if recorded) so cooperative arity-2 handlers can abort.
-spec create(SessionId :: binary() | undefined, Method :: binary(), Opts :: map()) -> {ok, binary()}.
Create a new running task. Returns the task id.
Record failure: store the error and emit notification.
Record success: store the result and emit notifications/tasks/status.
-spec set_worker(binary() | undefined, binary(), #{worker := pid(), request_id => integer() | binary()}) -> ok | {error, not_found}.
Record the worker pid (and optional originating request id) on a running task so a later tasks/cancel can stop it.