New in version: 2.14
Background tasks allow tools, resources, and prompts to execute asynchronously, returning immediately while work continues in the background. Clients can track progress, cancel operations, and retrieve results when ready.
This implements the MCP task protocol from the MCP specification, powered by Docket for task queue management.
Requirements
For single-process deployments, everything works out of the box using an in-memory backend. For multi-process deployments (multiple workers, distributed systems), you’ll need Redis or Valkey. See the Docket documentation for backend configuration details.Enabling Background Tasks
Addtask=True to any tool, resource, or prompt decorator:
Background tasks require async functions. Sync functions will log a warning and execute immediately instead.
Configuration
Background tasks require explicit opt-in:| Environment Variable | Default | Description |
|---|---|---|
FASTMCP_ENABLE_TASKS | false | Enable the MCP task protocol |
FASTMCP_DOCKET_URL | memory:// | Backend URL (memory:// or redis://host:port/db) |
Progress Reporting
TheProgress dependency lets you report progress back to clients:
await progress.set_total(n)- Set the total number of stepsawait progress.increment(amount=1)- Increment progressawait progress.set_message(text)- Update the status message
Additional Dependencies
FastMCP provides several Docket-style dependencies you can inject into your functions:CurrentDocket(), you gain access to the full Docket API. This lets you schedule additional background tasks from within your tool, chain tasks together, or use any of Docket’s advanced features like task priorities and retries. See the Docket documentation for the complete API.

