feat(frontend): proxy /mcp to the datahub-ai-service
Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-server-flag (the previous PR in the stack); review only its own commit. This PR changes GMS, the frontend, Docker or CI, not only the new Python packages. Everything user-facing is behind a GMS feature flag, MCP_SERVER_ENABLED, off by default (added in #21349).
Stack so far:
- #21332
- #21333
- #21334
- #21335
- #21336
- #21337
- #21338
- #21339
- #21340
- #21341
- #21342
- #21343
- #21344
- #21345
- #21346
- #21347
- #21348
- #21349
- #21350 ā this PR
- #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
Serve MCP at /mcp, the same URL shape as DataHub Cloud, by proxying
GET/POST/DELETE /mcp and /mcp/* from the frontend to datahub-ai-service
(DATAHUB_AI_SERVICE_URL; /mcp is 404 while it is unset).
- No frontend authentication: datahub-ai-service follows GMS's auth mode and checks
the caller's Authorization header, which is forwarded unchanged. The
session cookie and X-DataHub-Actor are never forwarded, so a logged-in
browser tab can't call /mcp with its cookie. OPTIONS answers 405 with no
CORS headers, so cross-site browser calls fail their preflight. A token
in the URL (?token=) is refused with 400. - Only the headers MCP needs are forwarded: Authorization, Content-Type,
Accept, Origin, User-Agent, Last-Event-ID and every Mcp-* header (the
stateless protocol routes on Mcp-Method / Mcp-Name / Mcp-Param-*).
X-Forwarded-Host is overwritten with the Host the client used, and
X-Forwarded-Proto set, for datahub-ai-service's DNS-rebinding check. - Responses stream through a non-blocking publisher with an idle timeout
(frontend.aiProxy.streamIdleTimeoutSeconds, 600), so slow calls hold no
blocking-I/O thread; gzip is bypassed so SSE isn't buffered. Response
headers wait up to frontend.aiProxy.timeoutSeconds (600). - /mcp has its own admission limit (frontend.aiProxy.maxInFlight, 128), not
tied to readiness, held until the response finishes streaming and
released exactly once, including when the client goes away. - datahub-ai-service unreachable: 503 with a JSON-RPC error body.
Tests run against a local HTTP server: header forwarding and stripping,
404/400/405/503, a first SSE event delivered while the next is held back,
the permit held for the whole stream, and released on client disconnect.
Live through a local OSS frontend: legacy and modern clients, Claude Code
with no token (GMS auth off), and 403 for a rebinding request.
Testing
8 controller tests vs a local HTTP server (streaming, permit release on disconnect). Live through the OSS frontend: legacy + modern clients, Claude Code with no token, rebinding 403.
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). The MCP docs come later in the stack.
- For any breaking change/potential downtime/deprecation/big changes an entry has been made in Breaking Changes. The release notes come later in the stack.
š¤ Generated with Claude Code