feat(mcp): port the get_lineage tool
Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-grep-entities (the previous PR in the stack); review only its own commit. It changes only the shared datahub-core-mcp-tools package and datahub-ai-service. It is one tool port, so it stays one PR even where it runs past the stack's usual 1,000-line size. Everything user-facing is behind a GMS feature flag, MCP_SERVER_ENABLED, off by default (added in #21349).
Stack so far:
1ā22. Merged to master as #21332.
23. #21435
24. #21436
25. #21437
26. #21438
27. #21439
28. #21440
29. #21441 ā this PR
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
get_lineage returns one direction (upstream or downstream) of any entity's
lineage, up to 1, 2 or unlimited (3+) hops, narrowed by a /q query or the
search filter language. Paging is server-side: offset is sent to
searchAcrossLineage as start, and each page reports total, returned,
hasMore and nextOffset (where the next page starts after what the token
budget let through, so following it skips nothing). Facets come with the
first page only. Each node is the get_entities projection: identity and
description by default, fields as the same allowlist, the rest listed in
omittedFields. With column, the input is the column's schemaField and each
downstream/upstream dataset carries the matching lineageColumns. It is in
the read group, read-only, trust-labeled, and registered with the progress
heartbeat.
From DataHub Cloud: the tool and description, server-side paging with the
derived total when GMS omits it, the per-response token budget
(select_results_within_budget, new in graphql_helpers), the existence check
(a schemaField is checked through its dataset), the rejection of a column
query filtered to charts/dashboards, fields, lineageColumns extraction,
facet trimming, the urn/filter/size/offset/fields aliases plus direction
and depth (direction="upstream"/"downstream" is coerced; "both" is a tool
error saying to call twice), and reader-policy labels. The GetEntityLineage
operation goes back into entity_details.gql, next to the entityPreview
fragment its nodes are read with (every .gql is validated on its own, so a
separate file would need a copy of that fragment).
From legacy OSS mcp-server-datahub: SearchFlagsOverride (6f7d9bf): a host
can merge searchFlags such as {"skipCache": true} over the lineage defaults
through the request's ToolContext (search_flags.request_search_flags).
Adapted to this package: reads go through ReadBackend (new
search_lineage; exists for the guard), a missing entity, a bad filter,
max_hops < 1 and a column on a non-dataset raise ToolError instead of
ItemNotFoundError/ValueError, and Cloud's URL injection is left out.
Version gates: none. Every selection of GetEntityLineage validates on GMS 1.7.0, 1.8.0
and master.
Testing
DataHub Cloud's get_lineage tests (guard, paging, missing total, budget
cut, facets, column-filter rejection, metric/semantic model names) against
a test ReadBackend, column extraction, the direction alias and coercion
through FastMCP, search-flag defaults and override, and the GraphQL backend's
operation. Live on a local OSS DataHub (showcase-ecommerce): the Snowflake
orders table's 37 downstream nodes paged 10 at a time by nextOffset (37
distinct: 22 datasets, 12 charts, 3 dashboards), its 4 upstreams (Postgres,
S3, two Spark jobs), fields=["ownership"], column-level lineage of
customer_id both ways (lineageColumns on the dbt, Postgres and S3 orders
tables), a dashboard filter, an offset past the end, and a bogus URN,
direction="both" and a column with a dashboard filter as tool errors.
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