failTask
Mark specified tasks as failed within MCPlanManager (MCP server), providing error details and optional retry configuration for efficient task management.
Instructions
将指定ID的任务标记为 'failed' (失败)。
Args: task_id (int): 需要标记为失败的任务的ID (从0开始)。 error_message (str): 描述任务失败原因的字符串。 should_retry (bool, optional): 是否应该重试该任务的标志。默认为 True。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| error_message | Yes | ||
| should_retry | No | ||
| task_id | Yes |
Implementation Reference
- src/mcplanmanager/app.py:107-117 (handler)MCP tool handler for failTask: decorated with @mcp.tool(), defines input schema via type hints, delegates execution to PlanManager.failTask@mcp.tool() def failTask(task_id: int, error_message: str, should_retry: bool = True) -> ToolResponse[TaskOutput]: """ 将指定ID的任务标记为 'failed' (失败)。 Args: task_id (int): 需要标记为失败的任务的ID (从0开始)。 error_message (str): 描述任务失败原因的字符串。 should_retry (bool, optional): 是否应该重试该任务的标志。默认为 True。 """ return plan_manager.failTask(task_id, error_message, should_retry)
- Core implementation logic in PlanManager.failTask: finds the task, sets status to 'failed', records error message, clears current task ID if necessary, updates timestamp, and returns response.def failTask(self, task_id: int, error_message: str, should_retry: bool = True) -> Dict: """标记任务失败""" task = self._find_task_by_id(task_id) if not task: return {"success": False, "message": f"Task {task_id} not found", "data": None} task["status"] = "failed" task["result"] = error_message # 如果这是当前任务,清除当前任务ID if self.plan_data["state"]["current_task_id"] == task_id: self.plan_data["state"]["current_task_id"] = None self._update_timestamp() return { "success": True, "data": task, "message": f"Task failed: {error_message}" }