Skip to main content
New in version 2.14.0 Use this when you need to run long operations asynchronously while doing other work. The MCP task protocol lets you request operations to run in the background. The call returns a Task object immediately, letting you track progress, cancel operations, or await results.

Requesting Background Execution

Pass task=True to run an operation as a background task:
This works with tools, resources, and prompts:

Task API

All task types share a common interface.

Getting Results

Call await task.result() or simply await task to block until the task completes:

Checking Status

Check the current status without blocking:

Waiting with Control

Use task.wait() for more control over waiting:

Cancellation

Cancel a running task:

Status Updates

Register callbacks to receive real-time status updates as the server reports progress:

Handler Template

Graceful Degradation

You can always pass task=True regardless of whether the server supports background tasks. Per the MCP specification, servers without task support execute the operation immediately and return the result inline.
This lets you write task-aware client code without worrying about server capabilities.

Example

See Server Background Tasks for how to enable background task support on the server side.