cancel_job
Delete a specific job by its ID to stop processing and manage resources in the Unstructured API workflow system.
Instructions
Delete a specific job.
Args:
job_id: ID of the job to cancel
Returns:
String containing the response from the job cancellation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes |
Implementation Reference
- uns_mcp/server.py:540-559 (handler)The main MCP tool handler for 'cancel_job'. It cancels a job using the UnstructuredClient's jobs.cancel_job_async method with a CancelJobRequest.@mcp.tool() async def cancel_job(ctx: Context, job_id: str) -> str: """Delete a specific job. Args: job_id: ID of the job to cancel Returns: String containing the response from the job cancellation """ client = ctx.request_context.lifespan_context.client try: response = await client.jobs.cancel_job_async( request=CancelJobRequest(job_id=job_id), ) return f"Job canceled successfully: {response.raw_response}" except Exception as e: return f"Error canceling job: {str(e)}"
- uns_mcp/server.py:22-22 (schema)Import of CancelJobRequest schema used internally by the cancel_job handler for the client API request.CancelJobRequest,
- uns_mcp/server.py:540-540 (registration)The @mcp.tool() decorator registers this function as an MCP tool named 'cancel_job'.@mcp.tool()
- Helper function _cancel_job in Firecrawl connector for canceling specific Firecrawl jobs (crawlhtml/llmfulltxt), referenced in tests but not an MCP tool.async def _cancel_job( job_id: str, job_type: Firecrawl_JobType, ) -> Dict[str, Any]: """Generic function to cancel a Firecrawl job. Args: job_id: ID of the job to cancel job_type: Type of job ('crawlhtml' or 'llmtxt') Returns: Dictionary containing the result of the cancellation """ # Get configuration with API key config = _prepare_firecrawl_config() # Check if config contains an error if "error" in config: return {"error": config["error"]} # Special case for LLM text generation jobs - not supported if job_type == "llmfulltxt": return { "id": job_id, "status": "error", "message": ( "Cancelling LLM text generation jobs is not supported." " The job must complete." ), "details": {"status": "error", "reason": "unsupported_operation"}, } else: try: # Initialize the Firecrawl client firecrawl = FirecrawlApp(api_key=config["api_key"]) # Cancel the job result = firecrawl.cancel_crawl(job_id) # Check if the cancellation was successful (result has 'status': 'cancelled') is_successful = result.get("status") == "cancelled" # Return a user-friendly response return { "id": job_id, "status": "cancelled" if is_successful else "error", "message": f"Firecrawl {job_type} job cancelled successfully" if is_successful else "Failed to cancel job", "details": result, } except Exception as e: return {"error": f"Error cancelling {job_type} job: {str(e)}"}