Skip to main content
New in version 2.14.0 The MCP task protocol lets you request operations to run asynchronously. This returns a Task object immediately, letting you track progress, cancel operations, or await results. See Server Background Tasks for how to enable this on the server side.

Requesting Background Execution

Pass task=True to run an operation as a background task. The call returns immediately with a Task object while the work executes on the server.
This works with tools, resources, and prompts:

Working with Task Objects

All task types share a common interface for retrieving results, checking status, and receiving updates. To get the result, call await task.result() or simply await task. This blocks until the task completes and returns the result. You can also check status without blocking using await task.status(), which returns the current state ("working", "completed", "failed", or "cancelled") along with any progress message from the server.
For more control over waiting, use task.wait() with an optional timeout or target state:
To cancel a running task, call await task.cancel().

Real-Time Status Updates

Register callbacks to receive status updates as the server reports progress. Both sync and async callbacks are supported.

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. The Task API provides a consistent interface either way.
This means you can write task-aware client code without worrying about server capabilities.

Complete Example