Skip to main content
Glama
Unstructured-IO

Unstructured API MCP Server

Official

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
NameRequiredDescriptionDefault
job_idYes

Implementation Reference

  • 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)}"
  • Import of CancelJobRequest schema used internally by the cancel_job handler for the client API request.
    CancelJobRequest,
  • 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)}"}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Unstructured-IO/UNS-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server