feat(mcp): port the create_glossary_term_version tool

Closed
NW
2d ago
+5674-70

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-glossary-term (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 ← this PR
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

create_glossary_term_version creates a new version of a glossary term
concept: a new GlossaryTerm linked into a VersionSet, after an existing
term (whose set is looked up; an unversioned term becomes v1 of a new
set), into a given version set, or as the first version of a new one. It
returns the version set and the new term's URN. With a previous term, the
new version inherits its parent and metadata and, where DataHub defines a
DRAFT stage for glossary terms, starts there, so the previous version
stays the latest visible one until the new one is published. It is in the
Write metadata group, not destructive and not idempotent, and is
registered with the version read tools only when
ENTITY_VERSIONING_ENABLED is true (and TOOLS_IS_MUTATION_ENABLED is not
false).

From DataHub Cloud's tools/glossary_versioning.py: the tool, its
description and response shape, and always sending an id (a UUID when
none is given) so the new term's URN is known. The description no longer
points at Cloud-only lifecycle tools for publishing. The legacy OSS
server has no such tool.

Version gates: @min_version(oss="1.10.0", cloud="0.3.16"), the same as the
version read tools: createGlossaryTermVersion came with glossary term
versioning (#20631), after releases/v1.9.0 was cut (DataHub Cloud marked the
tool Cloud-only). The mutation is in glossary_versioning.gql with
#[since oss=1.10.0 cloud=0.3.16] on its root field. The compiler cannot
drop a whole operation, so the mutation also selects __typename: on older
GMS the marker drops the real field, and with it $input and its input
type, leaving a valid no-op operation, so the document still validates
on GMS 1.7.0 and 1.8.0 for the read tools that share it.

Adapted to this package: ToolErrors instead of ValueErrors and
RuntimeErrors; arguments checked before writing (both a version set and
a previous term, a non-term previous URN, a non-version-set URN, a blank
version, an id containing "(", ")" or ","); the previous term or version
set must exist (ReadBackend, require_existing; a version set by its own
key aspect) and a parent node must be an existing glossary node. GMS's
refusals reach the caller as they are; a write that gets no reply names
the term URN to check instead of inviting a retry. The id, parent-node
and term-URN checks are shared with create_glossary_term and
add_related_terms (glossary.py; both its Core and its Cloud variant),
and compare_glossary_term_versions now uses the same term-URN check (its
message gains a glossary term example and a search hint).

Testing

unit tests for a version in a given set (input, no generic
exists call), a version after a term (the sent id is the returned URN),
invalid arguments writing nothing, a missing previous term, a refused
write, an unknown outcome naming the term, the version gate on all three
versioning tools, and registration with the flag on, off and unset (the
writes switch off hides it too). Live on a local OSS DataHub with auth
on, through an in-memory MCP client with the flag set and GMS version
detection left out (this dev GMS reports v1.9.0rc1, below the gate, so
the service's version filter would hide the tool), on test terms under a
run-unique glossary node: v2 after an unversioned term made that term v1
of a new set and linked the new term as v2 (isLatest false, comment and
parent inherited, checked in GraphQL; get_glossary_term_versions lists
only the published v1 until v2 is published); a new concept got its own
set; both options and a missing previous term are tool errors; a
temporary non-admin user's PAT gets "DataHub rejected
createGlossaryTermVersion: Unauthorized ...". The test terms, version
sets and node were 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