import threading, uuid _jobs = {} @mcp.tool() def start_batch_job(input_dir: str, output_dir: str = "", mode: str = "auto") -> dict: """Start a background job that de-identifies all DICOM/image files in a directory. Returns immediately with a job_id. Use get_job_status to check progress, do not wait synchronously. """ job_id = uuid.uuid4().hex[:8] _jobs[job_id] = {"job_id": job_id, "state": "queued", "processed": 0, "total": None, "decisions": {}, "errors": []} threading.Thread( target=_batch_worker, args=(job_id, input_dir, output_dir), daemon=True, ).start() return {"status": "started", "job_id": job_id, "next_step": f"Call get_job_status with job_id '{job_id}'."}