feat(mcp): add the create_domain 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-domains (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 ← this PR
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_domain(name, description?, parent_domain?) makes a domain, at the
top level or under an existing domain, and returns {urn, created}. It is
idempotent by name: calling it again with a name that already exists
under the same parent returns that domain with created=false (and a note
when a description was given, since it only applies to a new domain),
while the same name under a different parent is a different domain. It
is in the Write metadata group, not destructive and idempotent.
set_domains' description and its missing-domain message now point at it,
for the create-then-assign flow. TOOLS_IS_MUTATION_ENABLED=false hides
it. New in this package: neither DataHub Cloud nor the legacy OSS server has
it. @min_version(oss="1.4.0", cloud="0.3.16") like the other domain
tools; createDomain and listDomains (with parentDomain) are on GMS 1.7.0.
How it finds an existing domain:
- GMS refuses a second domain with the same name among a parent's direct
children ("... already exists in this domain"). On that refusal the
tool looks the domain up among the parent's children (listDomains with
the parent, or the top-level domains; exact name, as GMS compares) and
returns it. This covers domains made elsewhere, e.g. in the UI. - GMS's name check runs on the search index, which lags writes: live, two
quick creates of the same name with random ids both passed it and made
two domains. So the tool derives the id from the parent and name (a
UUID5) instead of letting GMS pick a random one, and first reads that
URN's domainProperties directly (ReadBackend.aspects, not search): a
repeated call finds its domain at once. A domain at that id that was
since renamed or moved does not block a new one, which gets a random
id. A known id also lets a create that gets no reply name the URN a
retry will return. - The parent must be an existing domain (ReadBackend), checked before
writing: GMS's own refusal of a missing parent does not say which URN.
No locks: two concurrent first calls can still race, as in the UI.
ReadBackend gains domains_named(name, parent_domain, count) for the
lookup (findDomainsByName in domains.gql); the test fakes implement it.
Testing
unit tests for a domain under a parent (input, parent check), a
repeated call answered by the direct read with no second write, a domain
moved away from its id not blocking a new one, a duplicate under the same
parent (GMS's refusal, then the lookup under that parent, ignoring a
similar name), a top-level duplicate looked up at the top level, the same
name under another parent created, a conflict whose domain is not found,
invalid arguments creating nothing (blank name, missing parent, non-domain
parent), an unknown outcome naming the URN, other refusals passed on, and
the annotations and set_domains' pointer through an MCP client. Live on a
local OSS DataHub with auth on, through the frontend's /mcp, with
run-unique names: a top-level domain created and the same call again
returned it with created=false and the description note; "Campaigns"
under it created, again returned it; "Campaigns" under a second domain
was a new domain; a domain made directly through GraphQL with a random
id (as the UI does) was found through GMS's name check and returned with
created=false; a missing parent and a bare name are tool errors; a
temporary non-admin user's PAT got "DataHub rejected createDomain:
Unauthorized ..."; the child read back with its parent; set_domains
accepted the new domain; after deleting a domain, creating it again
works. Every test domain was deleted and the dataset's domain removed
again.
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