Skip to content

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

Merged
nwadams merged 17 commits into
na--mcp-tool-groupsfrom
na--mcp-execution-helpers
Nov 23, 2026
Merged

nwadams merged 17 commits into
na--mcp-tool-groupsfrom
na--mcp-execution-helpers

Conversation

@nwadams

@nwadams nwadams commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

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. feat(mcp): add DataHub's built-in MCP server, off by default #21332
  2. feat(mcp): read GMS version and deployment from /config #21333
  3. feat(ai): scaffold the datahub-ai-service with /health #21334
  4. feat(ai): serve MCP at /mcp with caller-scoped DataHub clients #21335
  5. build(ai): add PyPI release scripts for datahub-core-mcp-tools and datahub-ai-service #21336
  6. feat(mcp): filter tools by the connected GMS version #21337
  7. feat(mcp): compile GraphQL for the exact GMS version with #[since] markers #21338
  8. test(mcp): validate packaged GraphQL against pinned GMS schemas #21339
  9. feat(mcp): tool groups and tool-aware server instructions #21340
  10. feat(mcp): deliver tool cancellation safely and report progress on slow tools #21341 ← this PR
  11. feat(mcp): shared limits, truncation, list coercion and ToolError mapping #21342
  12. feat(mcp): ReadBackend and ResultPolicy retrieval seams #21343
  13. feat(ai): bound GMS requests and never replay one GMS may have run #21344
  14. feat(gms): report whether authentication is enabled in /config #21345
  15. feat(ai): follow GMS's auth mode on /mcp #21346
  16. feat(ai): refuse DNS-rebinding requests to /mcp while GMS auth is off #21347
  17. feat(ai): datahub-ai-service docker image and locked dependencies #21348
  18. feat(mcp): keep the MCP server off until MCP_SERVER_ENABLED is set #21349
  19. feat(frontend): proxy /mcp to the datahub-ai-service #21350
  20. ci(ai): build the datahub-ai-service image on every relevant PR #21351
  21. feat(docker): run datahub-ai-service in quickstart and datahub-dev #21352
  22. test(smoke): MCP through the frontend's /mcp route #21353
  23. feat(mcp): port the read tools to DataHub Core's MCP server #21435
  24. feat(mcp): port the get_entities tool #21436
  25. feat(mcp): port the list_schema_fields tool #21437
  26. feat(mcp): port the search_documents tool #21438
  27. feat(mcp): port the grep_documents tool #21439
  28. feat(mcp): port the grep_entities tool #21440
  29. feat(mcp): port the get_lineage tool #21441
  30. feat(mcp): port the get_lineage_paths_between tool #21442
  31. feat(mcp): port the get_dataset_queries tool #21443
  32. feat(mcp): port the get_dataset_usage_history tool #21444
  33. feat(mcp): port the get_aspect_history tool #21445
  34. feat(mcp): port the glossary term version read tools #21447
  35. feat(mcp): port the write tools to DataHub Core's MCP server #21501
  36. feat(mcp): add the create_tag tool #21502
  37. feat(mcp): port add_terms and remove_terms #21503
  38. feat(mcp): port create_glossary_term and add_related_terms #21504
  39. feat(mcp): port the create_glossary_term_version tool #21505
  40. feat(mcp): port set_domains and remove_domains #21506
  41. feat(mcp): add the create_domain tool #21507
  42. feat(mcp): port add_owners and remove_owners #21508
  43. feat(mcp): port the update_description tool #21509
  44. feat(mcp): port add_structured_properties and remove_structured_properties #21510
  45. feat(mcp): port the save_document tool #21511
  46. feat(mcp): port the update_document tool #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

@cursor

cursor Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
This PR lands datahub-ai-service as a shippable Python image (Dockerfile, lockfile checks, dedicated CI image job) and threads it through compose profiles, Gradle quickstart generation, image-bake resolution, and security scanning. The Play frontend adds /mcp routes and an AiServiceController that stream-proxies to the AI service with selective header forwarding (PAT only—no session cookies), separate in-flight limits, and rejection of CORS preflight.

GMS and the UI gain MCP_SERVER_ENABLED (mcpServerEnabled in GraphQL/app config). GMS /config also exposes authentication.enabled and mcpServer.enabled so the AI service can follow auth mode, gate MCP when the flag is off, and apply host/origin guards when auth is disabled. datahub-ai-service is extended accordingly (GMS auth probe, HostGuard, safe HTTP retries and tool deadlines, richer /health).

In datahub-core-mcp-tools, background tools call checkpoint_if_cancelled after the worker returns so cancellations don’t emit late MCP responses; register_tool(..., slow=True) uses progress heartbeats; list-registration disables subscription listen and adds StrList coercion for client stringified arrays. Telemetry records cancelled tool calls.

Reviewed by Cursor Bugbot for commit 66f9777. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@lakshay-nasa

Copy link
Copy Markdown
Contributor

tiny nit: the heartbeat's cancel path swallows a tool failure silently (pass). might be worth a debug log so self-hosters can see it

@nwadams
nwadams force-pushed the na--mcp-execution-helpers branch from 4f50cf0 to 87d71cc Compare November 19, 2026 00:10
…ow tools

- 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).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ping

Add the data helpers the tool ports build on.

- Size limits for tool output, overridable with the same environment
  variables as mcp-server-datahub (DESCRIPTION_LENGTH_LIMIT,
  QUERY_LENGTH_LIMIT, DOCUMENT_CONTENT_CHAR_LIMIT,
  FIELD_DESCRIPTION_LENGTH_LIMIT, ...). A non-numeric or non-positive value
  fails at startup with the variable's name.
- truncate_with_ellipsis, including limits shorter than the suffix and a
  "[+N chars]" marker.
- arg_validation: StrList and friends accept a list that a client sent as
  a JSON string or a bare value, while the published schema stays a single
  array type ("" and "null" count as omitted). coerce_keyword_list also
  splits comma-joined keywords.
- execute_graphql raises ToolError with a message the model can act on
  (rejected token, GMS unreachable, GraphQL errors); format_exception=False
  keeps the SDK's raw GraphError for callers that act on error types.
  datahub-ai-service's token check reuses its HTTP status helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nwadams and others added 4 commits November 23, 2026 14:53
CI's package check compares find_packages with find_namespace_packages, and the
gql directory had no __init__.py. Make it a package and declare its .gql files
as its own package data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Installing metadata-ingestion and the two packages from source resolves their
build requirements from the configured index. In CI that index needs the netrc
secret, which only the lock install step mounted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FastMCP 4.2.5 serves subscriptions/listen, and on the 2026-07-28 protocol the
SDK advertises listChanged whenever that handler is registered, overriding the
notification options. Drop the handler: the server never sends change
notifications, and an in-process bus can't reach clients on another replica.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
master now adds its own placeholder right after __SYSTEM_CLIENT_SECRET__.
Keeping ours one line further down lets both changes merge without a
conflict. The replacements are independent, so their order doesn't matter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nwadams nwadams closed this Nov 23, 2026
@nwadams
nwadams merged commit 66f9777 into na--mcp-tool-groups Nov 23, 2026
1 check was pending
@nwadams
nwadams deleted the na--mcp-execution-helpers branch November 23, 2026 20:09
@github-actions

Copy link
Copy Markdown
Contributor

Smart test selection

pytest smoke tests

Mode: shadow. The selection below is computed but not applied; this PR still runs the default matrix (p0).

  • Selection: smart: tests for the tagged features, plus always-run modules, this PR's changed tests, and the plumbing sample if the PR changes the pytest harness
  • Size: 177 of 822 tests in 2 batches, predicted longest batch ~7 min
  • Tags: change-type: build, ci, docs, pytest-plumbing, test-infra, tooling; feature-dev: authentication, feature-flags, system-metadata; feature-user: home-page, settings; technical-layer: cli, graphql, react-frontend, spring-config
  • Confidence: MEDIUM (71 changed files)
  • Classifier reasoning: Adds an MCP proxy in datahub-frontend and a new datahub-ai-service with GMS auth-mode detection, gated by a new mcpServerEnabled feature flag exposed through GraphQL and the React app config, plus Docker, CI, and docs changes; system-metadata is a weak fit and was included only because the GMS /con…

Medium confidence: a wrong tag means tests are skipped, so check the tags above against what this PR touches.

Selected scopes (26 files or classes, 177 tests)
  • tests/e2e/authorization/test_self_entity_auth.py
  • tests/e2e/cli/user_groups_cmd/test_user_cmd.py
  • tests/e2e/delete/delete_test.py
  • tests/e2e/dev_tooling/test_dev_tooling.py
  • tests/e2e/domains/domain_entities_batching_test.py
  • tests/e2e/entity_versioning/test_versioning_ingest.py
  • tests/e2e/frontend/test_static_asset_encodings.py
  • tests/e2e/glossary/glossary_children_count_test.py
  • tests/e2e/lineage/test_lineage_sdk.py
  • tests/e2e/mcp/mcp_test.py
  • tests/e2e/openapi/v1/test_tracking.py
  • tests/e2e/openapi/v3/test_scroll_entities.py
  • tests/e2e/patch/test_domain_patches.py
  • tests/e2e/platform_resources/test_platform_resource.py
  • tests/e2e/read_only/test_services_up.py
  • tests/e2e/restli/test_restli_batch_ingestion.py
  • tests/e2e/schema_fields/test_schemafields.py
  • tests/e2e/search/test_search_projection.py::TestSearchProjection
  • tests/e2e/service_accounts/test_service_accounts.py
  • tests/e2e/status/test_lifecycle_state.py::TestLifecycleStageAPIs
  • tests/e2e/telemetry/telemetry_test.py
  • tests/e2e/test_authentication_e2e.py
  • tests/e2e/test_e2e.py
  • tests/e2e/tokens/revokable_access_token_test.py
  • tests/e2e/tokens/session_access_token_test.py
  • tests/e2e/trace/test_api_trace.py

Add the run-all-tests:pytest label to run the full pytest suite on this PR.

commit 66f9777 · workflow run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 66f9777. Configure here.

DATAHUB_GMS_BASE_PATH: ${DATAHUB_GMS_BASE_PATH:-/}
LOG_AGGREGATOR_ENDPOINT: ${LOG_AGGREGATOR_ENDPOINT:-}
# /mcp is proxied to datahub-ai-service (docker-compose.ai.yml).
DATAHUB_AI_SERVICE_URL: ${DATAHUB_AI_SERVICE_URL:-http://datahub-ai-service:9005}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quickstart proxies MCP to a missing service

Medium Severity

The frontend always sets DATAHUB_AI_SERVICE_URL to http://datahub-ai-service:9005, including in the default quickstart profile, while datahub-ai-service is intentionally omitted from that profile until an image is published. With the URL set, /mcp is a live proxy and returns 503 JSON-RPC when the hostname cannot be resolved, instead of the documented 404 when the URL is unset. Default quickstart therefore exposes a broken /mcp endpoint and will log unreachable-upstream warnings for any client that hits it.

Additional Locations (2)
Fix in Cursor Fix in Web

Triggered by project rule: DataHub Bugbot rules

Reviewed by Cursor Bugbot for commit 66f9777. Configure here.

return
# Anyone who reaches /mcp now acts as the system user: refuse requests
# a rebound web page could send.
rejection = self._host_guard.rejection(scope)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HostGuard DNS blocks the event loop

Medium Severity

HostGuard.rejection runs on the asyncio event loop and may call blocking socket.getaddrinfo while holding a lock, whenever GMS auth is off and DATAHUB_AI_TRUSTED_PROXIES contains hostnames (compose sets datahub-frontend-react). Auth detection is correctly offloaded with asyncio.to_thread, but the host check is not. A slow or hung Docker DNS lookup stalls every concurrent request on that loop, including /health, so the container can fail its healthcheck.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 66f9777. Configure here.

if ("POST".equals(method)) {
ByteString body = request.body().asBytes();
builder.POST(
HttpRequest.BodyPublishers.ofByteArray(body == null ? new byte[0] : body.toArray()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy drops POST body without byte fallback

High Severity

proxyMcp forwards a POST using only request.body().asBytes(), and substitutes an empty array when that returns null. The existing GMS proxy tries asBytes() and then asText() before sending no body. Play's default parser often stores application/json as JSON rather than raw bytes, so asBytes() can be null for normal MCP POSTs. Unit tests use bodyRaw(), which always populates bytes, so they would not catch an empty JSON-RPC body being sent upstream.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 66f9777. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

Initial JS bundle size ➡️

Base (1b825c3) This PR Diff
index.html (/login) 301 KB 301 KB +0 KB (+0.0%)
Logged-in shell 1015 KB 1015 KB +0 KB (+0.0%)
/search 1.19 MB 1.19 MB +0 KB (+0.0%)
/ (home) 1.19 MB 1.19 MB +0 KB (+0.0%)

index.html is the login page; logged-in pages add the shell. Gzip of the JS loaded before first paint. Codecov reports total bundle including lazy chunks — these intentionally differ.

@github-actions

Copy link
Copy Markdown
Contributor

Boot web vitals (no backend)

Unauthenticated /login against the two dist/ trees from this job. No GMS — this is eager JS, not search/dataset payload. Lantern, desktop, 1x CPU. Does not forecast fleet p75; do not gate on LCP.

Web-vitals A/B — base (1b825c3) (A) vs pr (66f9777) (B)

Lighthouse 12.8.2, throttling simulate (cpu 1x, rtt 40 ms, 10240 kbps). Form factor: desktop. Cache: cold (fresh incognito context per run). target n=3/build, 1 warm-up discarded, alternating A,B.

Boot-only (no GMS). Unauthenticated login route — eager JS/CSS/font transfer and parse, not search/dataset payload. Do not treat as a fleet p75.

boot

Measured runs in the table: A 3/3, B 3/3.

metric A p50 B p50 Δ p50 Δ% A p95 B p95
fcp 910 ms 909 ms -1 ms -0.2% 913 ms 912 ms
lcp 1353 ms 1349 ms -3 ms -0.3% 1356 ms 1354 ms
cls 0.0000 0.0000 0.0000 — 0.0000 0.0000
tbt 13 ms 10 ms -2 ms -16.0% 13 ms 12 ms
tti 1355 ms 1351 ms -3 ms -0.3% 1358 ms 1356 ms
ttfb 1 ms 0 ms 0 ms -46.4% 1 ms 1 ms
transferredBytes 1072.6 KB 1072.6 KB 0.0 KB +0.0% 1072.6 KB 1072.6 KB
mainThread 309 ms 302 ms -7 ms -2.1% 349 ms 314 ms
bootup 141 ms 136 ms -5 ms -3.3% 145 ms 143 ms

Resource transfer by type (p50):

type A bytes B bytes Δ bytes A requests B requests
document 1.2 KB 1.2 KB -0.0 KB 1 1
script 574.6 KB 574.6 KB 0.0 KB 7 7
stylesheet 69.3 KB 69.3 KB 0.0 KB 2 2
image 48.7 KB 48.7 KB 0.0 KB 1 1
media 257.3 KB 257.3 KB 0.0 KB 1 1
font 106.6 KB 106.6 KB 0.0 KB 3 3
other 0.0 KB 0.0 KB 0.0 KB 0 0

LCP element A: div > div.sc-pRPz > div.sc-hrcaRA > p.sc-pNWdM — Welcome to DataHub
LCP element B: div > div.sc-pRPz > div.sc-hrcaRA > p.sc-pNWdM — Welcome to DataHub

These numbers rank changes and gate regressions against the measured origin(s). They do not sum across PRs and do not forecast any fleet-wide production number.

This branch was successfully deployed

2 active deployments
datahub-project-web-react (Preview) — 66f97775 Deployed Nov 23, 2026 by github-actions[bot]
Preview — 66f97775 Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants