Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111---title: task_managementsidebarTitle: task_management---
# `fastmcp.client.mixins.task_management`
Task management methods for FastMCP Client.
## Classes
### `ClientTaskManagementMixin` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/client/mixins/task_management.py#L30" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Mixin providing task management methods for Client.
**Methods:**
#### `get_task_status` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/client/mixins/task_management.py#L33" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_task_status(self: Client, task_id: str) -> GetTaskResult```
Query the status of a background task.
Sends a 'tasks/get' MCP protocol request over the existing transport.
**Args:**- `task_id`: The task ID returned from call_tool_as_task
**Returns:**- Status information including taskId, status, pollInterval, etc.
**Raises:**- `RuntimeError`: If client not connected- `McpError`: If the request results in a TimeoutError | JSONRPCError
#### `get_task_result` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/client/mixins/task_management.py#L56" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_task_result(self: Client, task_id: str) -> Any```
Retrieve the raw result of a completed background task.
Sends a 'tasks/result' MCP protocol request over the existing transport.Returns the raw result - callers should parse it appropriately.
**Args:**- `task_id`: The task ID returned from call_tool_as_task
**Returns:**- The raw result (could be tool, prompt, or resource result)
**Raises:**- `RuntimeError`: If client not connected, task not found, or task failed- `McpError`: If the request results in a TimeoutError | JSONRPCError
#### `list_tasks` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/client/mixins/task_management.py#L85" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_tasks(self: Client, cursor: str | None = None, limit: int = 50) -> dict[str, Any]```
List background tasks.
Sends a 'tasks/list' MCP protocol request to the server. If the serverreturns an empty list (indicating client-side tracking), falls back toquerying status for locally tracked task IDs.
**Args:**- `cursor`: Optional pagination cursor- `limit`: Maximum number of tasks to return (default 50)
**Returns:**- Response with structure:- tasks: List of task status dicts with taskId, status, etc.- nextCursor: Optional cursor for next page
**Raises:**- `RuntimeError`: If client not connected- `McpError`: If the request results in a TimeoutError | JSONRPCError
#### `cancel_task` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/client/mixins/task_management.py#L135" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoncancel_task(self: Client, task_id: str) -> mcp.types.CancelTaskResult```
Cancel a task, transitioning it to cancelled state.
Sends a 'tasks/cancel' MCP protocol request. Task will halt executionand transition to cancelled state.
**Args:**- `task_id`: The task ID to cancel
**Returns:**- The task status showing cancelled state
**Raises:**- `RuntimeError`: If task doesn't exist- `McpError`: If the request results in a TimeoutError | JSONRPCError