feat(ai): serve MCP at /mcp with caller-scoped DataHub clients
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:
- #21332
- #21333
- #21334
- #21335 ā this PR
- #21336
- #21337
- #21338
- #21339
- #21340
- #21341
- #21342
- #21343
- #21344
- #21345
- #21346
- #21347
- #21348
- #21349
- #21350
- #21351
- #21352
- #21353
- #21435
- #21436
- #21437
- #21438
- #21439
- #21440
- #21441
- #21442
- #21443
- #21444
- #21445
- #21447
- #21501
- #21502
- #21503
- #21504
- #21505
- #21506
- #21507
- #21508
- #21509
- #21510
- #21511
- #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 GraphQLmeand 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