feat(mcp): add the create_tag 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-tags (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 ← this PR
37. #21503
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
create_tag(name, description?, color?) makes a tag and returns
{urn, created}, so an agent asked to tag something with a tag that does
not exist yet can create it and pass the urn to add_tags. It is
idempotent by name: calling it again returns the same tag with
created=false instead of making a second one. add_tags' description now
points at it.
New in OSS; neither DataHub Cloud nor the legacy OSS server has it.
How it decides:
- The name is the tag's id (urn:li:tag:), so names containing
"(", ")" or "," are refused before anything is read or written. A color
that is not hex (#RGB or #RRGGBB, "#" optional) is refused too. - A tag with that id is returned as is (matched: "id").
- Otherwise a best-effort search for the name returns a tag whose display
name equals it in any case (matched: "name"), e.g. "pii_data" returns a
tag named "PII_Data". A failed search does not block the create; a
merely similar name ("PII data") does not count. - Otherwise createTag with the name as id. If GMS answers that the tag
already exists (made concurrently), that tag is returned with
created=false. - CreateTagInput has no color, so setTagColor follows the create. If it
fails, the call still succeeds with the created URN, created=true and a
color_error (partial success). - Description and color apply only to a new tag; for an existing one the
result notes they were not applied.
A write that gets no reply says its outcome is unknown and that calling
create_tag again is safe. Nothing is retried automatically.
Also: a ReadBackend.tags_named read (findTagsByName in tags.gql) for the
name lookup, and an @idempotent marker that sets MCP idempotentHint on
write tools (explicit true or false; read-only tools leave it out, as the
spec gives it no meaning there). create_tag, add_tags and remove_tags are
idempotent; create_tag is not destructive. createTag, setTagColor and
search(input: {type: TAG}) all exist on GMS 1.7.0;
@min_version(oss="1.4.0", cloud="0.3.16") as for the other tag tools.
Testing
unit tests for a new tag (id, description, normalized color as a
second write), an existing id (no writes, note), an existing display name
in another case, a similar name that does not count, a failed name
search, reserved characters and a blank name, a bad color, a color
failure as partial success, a concurrently created tag, a refused create,
and the annotations. Live on a local OSS DataHub with auth on, through
the frontend's /mcp: a run-unique tag created with a description and
color "1890ff" (GraphQL shows colorHex #1890FF); the same name again
returns it with created=false and notes the color was not applied; the
same name upper-cased returns it by display name; "pii_data" returns the
showcase tag "PII_Data"; "a,b" is refused; a temporary non-admin user's
PAT gets "DataHub rejected createTag: Unauthorized ..." and no tag is
made. The created tag was added to the ORDERS dataset and its
order_status column with add_tags and removed with remove_tags (checked
in GraphQL both times), then deleted.
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