cancel_crawlhtml_job
Stop an active HTML crawl job in the Unstructured API MCP Server by providing its crawl ID to halt processing and manage resources.
Instructions
Cancel an in-progress Firecrawl HTML crawl job.
Args:
crawl_id: ID of the crawl job to cancel
Returns:
Dictionary containing the result of the cancellation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| crawl_id | Yes |
Implementation Reference
- The main handler function for the 'cancel_crawlhtml_job' MCP tool. It takes a crawl_id and delegates to the internal _cancel_job helper to perform the cancellation via the Firecrawl API.async def cancel_crawlhtml_job( crawl_id: str, ) -> Dict[str, Any]: """Cancel an in-progress Firecrawl HTML crawl job. Args: crawl_id: ID of the crawl job to cancel Returns: Dictionary containing the result of the cancellation """ return await _cancel_job(crawl_id, "crawlhtml")
- Internal helper function that performs the actual cancellation logic for Firecrawl jobs, handling API key setup, client initialization, cancellation call, and error handling. Used by cancel_crawlhtml_job.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)}"}
- uns_mcp/connectors/external/__init__.py:12-24 (registration)Imports the cancel_crawlhtml_job function from firecrawl.py and registers it as an MCP tool using mcp.tool() within the register_external_connectors function.from .firecrawl import ( cancel_crawlhtml_job, check_crawlhtml_status, check_llmtxt_status, invoke_firecrawl_crawlhtml, invoke_firecrawl_llmtxt, ) mcp.tool()(invoke_firecrawl_crawlhtml) mcp.tool()(check_crawlhtml_status) mcp.tool()(invoke_firecrawl_llmtxt) mcp.tool()(check_llmtxt_status) mcp.tool()(cancel_crawlhtml_job)