Task-augmented tool execution. A client sends tools/call with a task field;
the server records the call under a task id and the client polls tasks/get /
tasks/result. This is the interceptive half of the extension API — the
Tasks extension (io.modelcontextprotocol/tasks) wraps tools/call rather
than only adding tools.
# stdio (default — the client spawns the server as a subprocess)
uv run python -m stories.tasks.client
# HTTP — the client self-hosts the server on a free port, runs, then tears it down
uv run python -m stories.tasks.client --httpserver.pyMCPServer("tasks-example", extensions=[Tasks()])— opt in at construction. The extension advertisesio.modelcontextprotocol/tasksand servestasks/get,tasks/result,tasks/cancel, andtasks/list. Therender_reporttool is the kind of slower, multi-step work a caller would rather run as a task than block on.mcp.server.tasks.Tasks.intercept_tool_call— the interceptive seam: a plain call passes through; a call with ataskfield is recorded and returned with the task id in_meta["io.modelcontextprotocol/related-task"].client.pymain— start the call as a task, read itstasks/getstatus, then fetch the payload withtasks/result. Thetaskfield andtasks/*methods are outside the spec verbsClientexposes, so the thin_start_task/_get_task/_task_resulthelpers wrapclient.session.
This is a reference implementation for the extension API, not a production task
runtime. A plain tools/call (no task field) is unchanged — only a call the
client explicitly augments with a task field becomes a task. Three deliberate
simplifications:
- The tool runs to completion inline, so a task is observed as
completedimmediately (no detached/background execution, no TTL eviction). - The augmented call returns a normal
CallToolResultwith the task id in_metarather than the spec'sCreateTaskResult— thetools/callresult schema admits onlyCallToolResult | InputRequiredResult(seeTODO(L56)inmcp.server.runner), so returningCreateTaskResultwould require extending the methods-layer validation maps. The lifecycle runs through the dedicatedtasks/*methods instead. - Any tool may be task-augmented on request; per-tool gating on the declared
ToolExecution.task_support(forbidden/optional/required) is not enforced.
Tasks — extensions · SEP-2133 — extensions capability
apps/ (the additive half of the extension API),
custom_methods/ (a non-spec method without an extension),
middleware/ (the low-level tools/call wrapping the interceptor builds on).