feat(mcp): port add_structured_properties and remove_structured_properties
Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-update-description (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–34. #21435, the read tools (PRs 24–34 merged into it).
35. #21501
36. #21502
37. #21503
38. #21504
39. #21505
40. #21506
41. #21507
42. #21508
43. #21509
44. #21510 ← this PR
45. #21511
46. #21512
47–55. #21587, MCP settings: model, API and UI.
56–60. #21588, telemetry, metrics, usage events and the stdio server.
61–64. #21589, docs, release notes and smoke tests.
65–68. #21590, settings enforcement and the tool catalog.
69–70. #21591, the home page module.
What this does
add_structured_properties(property_values, entity_urns) sets typed
structured property values on assets (the given values replace that
property's values; other properties are left as they are);
remove_structured_properties(property_urns, entity_urns) takes
properties off assets. GMS has no batch form, so each asset is one
write; every argument is checked before the first. Both are in the Write
metadata group, destructive and idempotent.
TOOLS_IS_MUTATION_ENABLED=false hides both.
From DataHub Cloud's tools/structured_properties.py: the tools, their
descriptions and response messages, value conversion by the property's
value type (number, string, URN, ISO 8601 date, rich text), the
destructive marker on remove and @min_version(oss="1.4.0",
cloud="0.3.16"). From the legacy OSS server: values published as a
single {"type": "string"} schema while still accepting numbers at
runtime, since Gemini accepts only one type and several OpenAI-compatible
endpoints reject multi-type unions (41ff2dd, 01054c4); the examples pass
numbers as numeric strings; entity_urns and property_urns as StrLists
(d05ef3d). The schema test added with add_owners now also flags a type
list with more than one non-null type (01054c4).
propose_structured_properties is not ported.
Fixed while porting:
- A property that does not exist is refused. GMS answers it with
exists=false and a placeholder string definition, which DataHub Cloud's
check (entity is null) let through; live, such a write returned
success and stored nothing. - A partial failure says which assets were updated and which were not,
with GMS's reason for each (DataHub Cloud listed only the failures, so a
caller could not tell what had changed), and that a retry is safe. - A single-valued property given several values, and an empty value
list, are refused before writing. - add_structured_properties is marked destructive (it replaces values).
- remove_structured_properties does not require the property to exist,
as removing tags does not: removing a reference to a deleted property
is how it gets cleaned up.
Adapted to this package: ToolErrors instead of ValueErrors and
RuntimeErrors; writes through execute_write (one attempt each; no reply
is reported per asset as "may or may not have been applied"); asset URNs
get the checks add_tags gives them; the definition read goes through a
new ReadBackend.structured_property (the test fakes implement it). The
mutations and getStructuredPropertyDefinition are in
structured_properties.gql, valid on GMS 1.7.0, 1.8.0 and master.
Testing
unit tests for four typed properties on two assets (the inputs
sent), invalid values writing nothing (no properties, a non-property
key, a missing property as GMS answers it, no values, a non-number, two
values for a single-valued property, a non-URN, a non-ISO date), a bad
asset URN, a partial failure (one applied, one refused, one without a
reply), remove with duplicates and no definition reads, an empty result,
the read through a bound ReadBackend, and through an MCP client the
published value schema, an integer value, a bare entity URN and the
annotations. Live on a local OSS DataHub with auth on, through the
frontend's /mcp: a run-unique multi-valued property made for the test
and the showcase dataQualityScore set on the Postgres and S3 orders
datasets (read back), an integer score accepted; a non-number, two
values for a single-valued property, a non-URN, a missing property and
a value outside GMS's allowed values are errors; a missing dataset among
two got "applied to 1 of 2" with GMS's reason; remove took the test
property off both, and again; a temporary non-admin user's PAT got
"Not authorized to update properties" from both tools. Both datasets'
properties were checked equal to the originals and the test property
was deleted (soft, then hard, as this GMS requires).
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