fastmcp/examples/tasks
Jeremiah Lowin 74e01d5e08
Add SEP-2663 client half: transparent call_tool, ResultClaim, Task handle
A FastMCP client now transparently completes tasked tools/call: the tasks
ClientExtension advertises the capability and claims the CreateTaskResult, and
the resolver drives the tasks/get poll loop to completion, answering in-task
input through the client's elicitation handler and returning the tool's real
result. call_tool is transparent, call_tool_mcp exposes the raw result, and
call_tool_task yields a Task handle. The client half moves to fastmcp-tasks;
the [tasks] client extension auto-wires into Client (ProxyClient opts out).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-22 15:21:10 -04:00
..
.envrc Remove enable_tasks setting, enable task protocol by default 2025-12-09 09:34:42 -05:00
client.py Add SEP-2663 client half: transparent call_tool, ResultClaim, Task handle 2026-07-22 15:21:10 -04:00
docker-compose.yml [2.14] SEP-1686 tasks (#2378) 2025-12-04 20:10:35 -05:00
README.md Remove enable_tasks setting, enable task protocol by default 2025-12-09 09:34:42 -05:00
server.py Add SEP-2663 client half: transparent call_tool, ResultClaim, Task handle 2026-07-22 15:21:10 -04:00

FastMCP Tasks Example

Demonstrates background task execution with Docket, including progress tracking, distributed backends, and CLI worker management.

Setup

# From the fastmcp root directory
uv sync

# Start Redis
cd examples/tasks
docker compose up -d

# Load environment (or source .envrc manually)
direnv allow

# Run the server
fastmcp run server.py

For single-process mode without Redis, set FASTMCP_DOCKET_URL=memory:// (note: CLI workers won't work).

Running the Client

# Background execution with progress callbacks
python examples/tasks/client.py --duration 10

# Immediate execution (blocks)
python examples/tasks/client.py immediate --duration 5

Starting Additional Workers

With Redis, you can run additional workers to process tasks in parallel:

fastmcp tasks worker server.py

# Configure via environment:
export FASTMCP_DOCKET_CONCURRENCY=20
fastmcp tasks worker server.py

Backend options:

  • memory:// - Single-process only (default)
  • redis:// - Distributed, multi-process (Redis or Valkey)

Environment Variables

Variable Default Description
FASTMCP_DOCKET_URL memory:// Docket backend URL

Learn More