docs/python-sdk/fastmcp-client-mixins-task_management.mdx
fastmcp.client.mixins.task_managementTask management methods for FastMCP Client.
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>get_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_taskReturns:
Raises:
RuntimeError: If client not connectedMcpError: If the request results in a TimeoutError | JSONRPCErrorget_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>get_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_taskReturns:
Raises:
RuntimeError: If client not connected, task not found, or task failedMcpError: If the request results in a TimeoutError | JSONRPCErrorlist_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>list_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 server returns an empty list (indicating client-side tracking), falls back to querying status for locally tracked task IDs.
Args:
cursor: Optional pagination cursorlimit: Maximum number of tasks to return (default 50)Returns:
Raises:
RuntimeError: If client not connectedMcpError: If the request results in a TimeoutError | JSONRPCErrorcancel_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>cancel_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 execution and transition to cancelled state.
Args:
task_id: The task ID to cancelReturns:
Raises:
RuntimeError: If task doesn't existMcpError: If the request results in a TimeoutError | JSONRPCError