feat(mcp): port add_terms and remove_terms
Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-create-tag (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 ← this PR
38. #21504
39. #21505
40. #21506
41. #21507
42. #21508
43. #21509
44. #21510
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_terms attaches one or more existing glossary terms to assets, or to
dataset columns when column_paths pairs a column with an asset, in one
batch write; remove_terms takes them off. They answer like add_tags and
remove_tags (success, entities covered, the per-call scope note), are in
the Write metadata group, idempotent, and remove_terms is @destructive.
TOOLS_IS_MUTATION_ENABLED=false hides both.
From DataHub Cloud's tools/terms.py: both tools (registered as add_terms
and remove_terms, the names DataHub Cloud and the legacy server publish and
the server instructions already route to), their descriptions and
response shape, and @min_version(oss="1.4.0", cloud="0.3.16"). Not
ported: propose_glossary_terms. From the legacy OSS server (d05ef3d):
term_urns, entity_urns and column_paths accept a bare string or a
JSON-stringified array, with plain array schemas.
Adapted to this package: the tools are a glossary-term LabelKind over the
add/remove code add_tags and remove_tags already use, so they get the
same behavior: ToolErrors that point at search(filter="entity_type =
glossaryTerm") for a term name or a non-term URN, input checks that fail
the whole call before anything is written, term existence read through
ReadBackend.exists on add only (DataHub Cloud's entities(urns:) check passed
terms that do not exist; removing a reference to a deleted term stays
possible), GMS's reason on a refused write, and an unknown-outcome
message instead of a retry. The mutations live in glossary_terms.gql.
Testing
unit tests for an asset and a column in one call (termUrns,
resources), removal, a missing term, a term name and a tag URN refused as
terms, and through an MCP client stringified list arguments, the
registered names, annotations and group. glossary_terms.gql validates on
GMS 1.7.0, 1.8.0 and master. Live on a local OSS DataHub with auth on,
through the frontend's /mcp: a run-unique glossary term (created for the
test) added to the ORDERS dataset and its order_status column with
term_urns as a bare string, confirmed in GraphQL, then removed (confirmed
gone); a tag URN and a missing term are tool errors; a temporary
non-admin user's PAT gets "DataHub rejected batchRemoveTerms:
Unauthorized ...". The test term was deleted afterwards.
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