Skip to content

feat(ai): serve MCP at /mcp with caller-scoped DataHub clients - #21335

Merged
nwadams merged 23 commits into
na--ai-service-scaffoldfrom
na--ai-service-mcp
Nov 23, 2026
Merged

nwadams merged 23 commits into
na--ai-service-scaffoldfrom
na--ai-service-mcp

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--ai-service-scaffold (the previous PR in the stack); review only its own commit. Nothing in these first five PRs 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 ← this PR
  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
  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

datahub-ai-service now serves the datahub-core-mcp-tools tools (today: get_me) over
stateless streamable HTTP at /mcp.

  • Every request carries the caller's DataHub token. An ASGI middleware in
    front of the MCP app checks it with GraphQL me and caches successful
    verdicts (keyed by a hash of the token) for
    DATAHUB_MCP_TOKEN_CACHE_TTL_SECONDS. Missing or rejected tokens get 401;
    when GMS is unreachable or erroring the request gets 503, never access.
  • Each MCP message runs with a DataHub client built from its caller's token
    and closed afterwards; no client is cached or shared between callers.
  • SSE responses by default; DATAHUB_AI_MCP_RESPONSE_MODE=json returns plain
    JSON bodies for proxies that can't stream.
  • listChanged is not advertised, since a stateless host can't send it.
  • Tool-call observer seam for telemetry; an observer failure never fails
    the call.

Tests run a real HTTP server against a fake GMS: missing/garbage tokens,
GMS outage, SSE and JSON modes, legacy and modern protocol clients, token
caching, and two concurrent callers held in flight at once.

Testing

  • Tests run a real HTTP server against a fake GMS: missing and garbage tokens (401), GMS down (503), SSE and JSON response modes, legacy and modern protocol clients, token caching, and two concurrent callers keeping their own identity.
  • Checked against a running DataHub Core instance with Claude Code connected using a personal access token.

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

datahub-ai-service now serves the datahub-core-mcp-tools tools (today: get_me) over
stateless streamable HTTP at /mcp.

- Every request carries the caller's DataHub token. An ASGI middleware in
  front of the MCP app checks it with GraphQL `me` and caches successful
  verdicts (keyed by a hash of the token) for
  DATAHUB_MCP_TOKEN_CACHE_TTL_SECONDS. Missing or rejected tokens get 401;
  when GMS is unreachable or erroring the request gets 503, never access.
- Each MCP message runs with a DataHub client built from its caller's token
  and closed afterwards; no client is cached or shared between callers.
- SSE responses by default; DATAHUB_AI_MCP_RESPONSE_MODE=json returns plain
  JSON bodies for proxies that can't stream.
- listChanged is not advertised, since a stateless host can't send it.
- Tool-call observer seam for telemetry; an observer failure never fails
  the call.

Tests run a real HTTP server against a fake GMS: missing/garbage tokens,
GMS outage, SSE and JSON modes, legacy and modern protocol clients, token
caching, and two concurrent callers held in flight at once.

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

Generate scripts/release.sh for both packages with
python-build/generate_release_scripts.py, so they publish to PyPI with
DataHub's version like datahub-agent-context.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add VersionFilterMiddleware to datahub-core-mcp-tools and install it in
datahub-ai-service. Tools/list hides tools whose @min_version the connected GMS
doesn't meet, and tools/call refuses them, so a client with a stale list
can't call them either.

- The requirement travels with the registered tool function, so there is
  no module-level registry and two servers filter independently.
- Deployment type (serverEnv) is always honored; the version is compared
  only for real releases, so unreleased builds keep their tools.
- GMS info comes from a host-supplied callable; datahub-ai-service uses a
  GmsServerInfoCache (60 s) on its configured GMS URL. If /config can't be
  read, tools are left unfiltered and their own calls report the failure.

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

cursor Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
datahub-ai-service now exposes stateless streamable HTTP MCP at /mcp, registering tools from datahub-core-mcp-tools via FastMCP (default SSE; optional JSON for non-streaming proxies).

Each request must send Authorization: Bearer <personal access token>. New ASGI McpAuthMiddleware validates tokens against GMS with GraphQL me, caches successful verdicts briefly, returns 401 for missing/invalid tokens and 503 when GMS cannot verify (fail closed). CallerClientMiddleware builds a per-message DataHub client from that token so callers never share credentials or clients. ToolCallTelemetryMiddleware adds an observer hook that cannot break tool calls.

create_app wires MCP (optional disable via DATAHUB_AI_MCP_ENABLED), auth, and lifespan; README documents client setup and new env vars. Tests spin a real uvicorn server with a fake GMS covering auth errors, GMS outage, SSE/JSON modes, concurrent identities, token caching, and telemetry.

Reviewed by Cursor Bugbot for commit ad78be2. 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

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 2769477. Configure here.

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>

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