feat(mcp): port the get_entities tool

Closed
NW
4d ago
+0-0

Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-search (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 ← this PR
25. #21437
26. #21438
27. #21439
28. #21440
29. #21441
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_entities reads one or more entities by URN: a dataset, dashboard, glossary
term, document, data contract, assertion, query or any other type. fields is
a strict allowlist (published as an enum) and everything withheld is listed in
omittedFields, sized where that matters; named fields that came back empty
are listed in notReturnedFields. schema_columns picks columns by name from
the whole schema before the token budget, with full text. A dataset's
descriptions, tags and terms include its siblings' (the dbt model behind a
warehouse table), merged as the UI shows them. In a batch, results keep the
caller's order and a missing or malformed URN becomes {urn, error} in place; a
single missing URN, or a batch with no URN at all, raises a ToolError. It is in
the read group, read-only and trust-labeled, and reads through ReadBackend
(new entity and related_documents methods). A host can pass
schema_field_matcher to register_tools to rank columns its own way.

From DataHub Cloud: the tool, its projection and field allowlist, sibling
merge (sibling_merge.py), column matching (schema_matching.py), and the entity
cleaning helpers (new entity_cleaning.py: description sanitizing and caps,
documentation origins, schema-field cleaning with edited* merges, the per-entity
schema token budget, document and SQL caps). entity_details.gql,
query_entity.gql and related_documents.gql come from DataHub Cloud. Left out as
Cloud-only or not this tool's: certification (GMS has no Certifiable
interface), URL injection, the GetEntityLineage operation (get_lineage's), and
the Context-doc kill switch. Without json_repair, a malformed JSON-string URN
list is taken as one value and rejected by URN validation.

From legacy OSS mcp-server-datahub:

  • assertions are read with their own document (assertion_entity.gql) and
    select error.properties, where OSS servers put an errored run's message;
  • assertion key/value lists (customProperties, nativeParameters, run
    nativeResults and error properties) are capped, with Total when cut
    (MAX_ASSERTION_KEY_VALUE_ENTRIES / _CHARS);
  • a data contract returns at most MAX_CONTRACT_DATA_QUALITY_ASSERTIONS members,
    failing and erroring first, with dataQualityTotal;
  • Dataset.properties.externalUrl and DataJob.inputOutput are selected (the
    latter is a new nameable field).

Version gates: every unmarked field validates on GMS 1.7.0, 1.8.0 and master,
including the Document arm and DataContract.structuredProperties (both older
than 1.7.0). customAssertion's fields/scope/aggregation/operator/parameters/
nativeType/nativeParameters and AssertionInfo.customProperties are
#[since oss=1.8.0 cloud=0.3.16]. Cloud-only: entity documentation on
Dataset/Dashboard/Chart/DataFlow/DataJob (cloud=0.3.4), statsSummary
percentiles, ranks, row count and size (0.3.2), GlossaryTerm.versionProperties
(0.3.9), DataContract.result (0.3.4), assertionStatus and error.displayMessage
(0.3.17), result.metric (0.3.16.3), failureSeverityConfig (0.3.17.7), each the
first Cloud release whose schema has it.

Tests: 73 new (projection, cleaning, sibling merge, the tool against a fake
ReadBackend, per-kind query routing, host matcher isolation, and what each
document selects on OSS 1.7.0/1.8.0 and Cloud). Live against a local OSS
DataHub with the showcase-ecommerce data: a Snowflake table (sibling dbt
description merged, externalUrl), a Tableau dashboard, a glossary term, a
document (title, related assets, parent lifted), a batch with a missing URN and
a bare name, fields and schema_columns, related documents, and a data job.

Testing

73 tests (incl. which fields each document selects on 1.7.0 / 1.8.0 / Cloud); live: dataset with sibling merge, dashboard, term, document, mixed batch, fields / schema_columns args.

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