stop_web_task
Stop running web automation tasks to cancel unnecessary operations and free browser resources. Use when you need to halt long-running web activities that are no longer required.
Instructions
Stop a running web browsing task.
Immediately halts task execution and cleans up browser resources. Use this
when you need to cancel a long-running task that's no longer needed.
Args:
task_id: Task ID from start_web_task()
Returns:
Dictionary containing:
- ok: Boolean indicating success
- message: Confirmation message
- task_id: The stopped task ID
- error: Error message (if task not found or already completed)
Examples:
- stop_web_task("abc-123-def")
Note: Cannot stop tasks that are already completed or failed.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task_id | Yes |
Implementation Reference
- server.py:271-308 (handler)The MCP tool handler for 'stop_web_task'. Logs the request, calls task_manager.cancel_task(task_id), and returns a success or error response dictionary.async def stop_web_task(task_id: str) -> dict[str, Any]: """ Stop a running web browsing task. Immediately halts task execution and cleans up browser resources. Use this when you need to cancel a long-running task that's no longer needed. Args: task_id: Task ID from start_web_task() Returns: Dictionary containing: - ok: Boolean indicating success - message: Confirmation message - task_id: The stopped task ID - error: Error message (if task not found or already completed) Examples: - stop_web_task("abc-123-def") Note: Cannot stop tasks that are already completed or failed. """ logger.info(f"Stopping web task: {task_id}") success = task_manager.cancel_task(task_id) if success: return { "ok": True, "message": f"Task {task_id} cancelled successfully", "task_id": task_id } else: return { "ok": False, "error": f"Could not cancel task {task_id} (not found or already completed)", "task_id": task_id }
- task_manager.py:212-233 (helper)The core logic for stopping a web task. Sets the task status to 'CANCELLED', records completion time, and cleans up the associated browser agent if present.def cancel_task(self, task_id: str) -> bool: """Cancel a running task. Args: task_id: Task identifier Returns: True if task was cancelled, False otherwise """ with self._lock: task = self.tasks.get(task_id) if not task or task.status not in [TaskStatus.PENDING, TaskStatus.RUNNING]: return False task.status = TaskStatus.CANCELLED task.completed_at = datetime.now(timezone.utc).isoformat() # Clean up browser if running if task.agent: task.agent.cleanup_browser() return True