feat(mcp): deliver tool cancellation safely and report progress on slow tools

Closed
NW
4d ago
+4226-155

Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-tool-groups (the previous PR in the stack); review only its own commit. These PRs build out the shared datahub-core-mcp-tools package and datahub-ai-service; nothing is wired into quickstart, the frontend or Helm yet, so they change no running DataHub. The later PRs that expose MCP are all behind a GMS feature flag, MCP_SERVER_ENABLED, off by default.

Stack so far:

  1. #21332
  2. #21333
  3. #21334
  4. #21335
  5. #21336
  6. #21337
  7. #21338
  8. #21339
  9. #21340
  10. #21341 ← this PR
  11. #21342
  12. #21343
  13. #21344
  14. #21345
  15. #21346
  16. #21347
  17. #21348
  18. #21349
  19. #21350
  20. #21351
  21. #21352
  22. #21353
  23. #21435
  24. #21436
  25. #21437
  26. #21438
  27. #21439
  28. #21440
  29. #21441
  30. #21442
  31. #21443
  32. #21444
  33. #21445
  34. #21447
  35. #21501
  36. #21502
  37. #21503
  38. #21504
  39. #21505
  40. #21506
  41. #21507
  42. #21508
  43. #21509
  44. #21510
  45. #21511
  46. #21512

What this does

  • async_background delivers a pending cancellation only after its worker
    thread returns. The worker can't be interrupted, so it keeps the caller's
    client and execution slot until it exits, and a cancelled request never
    sends a late response that would break the MCP session.
  • with_progress_heartbeat moves into datahub-core-mcp-tools: register_tool(...,
    slow=True) reports progress every 15 s to clients that send a
    progressToken. Transport keepalive doesn't depend on it: the SDK's SSE
    responses send : ping comments every 15 s regardless.
  • datahub-ai-service's tool-call events record cancelled calls.

Tests cover cancellation ordering, a session that keeps working after a
cancelled background tool, heartbeat with and without a progress request,
SSE pings on a slow call with no progress token, and a client that drops
a call mid-flight (recorded as cancelled; its client closed exactly once).

Testing

  • Tests cover cancellation ordering, a session that keeps working after a cancelled background tool, the heartbeat with and without a progress request, SSE pings on a slow call with no progress token, and a client that drops a call mid-flight (recorded as cancelled, its client closed exactly once).

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). Docs come later in the stack, with the user-facing pieces.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Breaking Changes. Not applicable: nothing user-facing changes yet.

šŸ¤– Generated with Claude Code