Repository navigation
feat(mcp): port the update_document tool - #21512
Conversation
PR SummaryOverview Commands: anchored Includes a large Reviewed by Cursor Bugbot for commit 7383f0c. Bugbot is set up for automated code reviews on this repo. Configure here. |
c308cf3 to
b29d76a
Compare
57f2fa0 to
90677cf
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b29d76a. Configure here.
update_document(urn, command, ...) changes part of an existing document
without sending it whole: update_content applies anchored {old_str,
new_str, replace_all_matches?} edits to the body; replace_content
replaces the body (allow_deleting_content=true is required when there
is one); append_content adds to the end; update_properties changes
title, topics, related documents, related assets or status
(PUBLISHED / UNPUBLISHED) without the body; move puts the document,
with what is nested under it, under another document. Every command but
move edits the stored document in place, keeping its parent, owners and
visibility. It is in the Write metadata group, destructive and not
idempotent, and is registered with save_document behind the same gates
(TOOLS_IS_MUTATION_ENABLED, SAVE_DOCUMENT_TOOL_ENABLED, both on by
default).
From DataHub Cloud's tools/update_document.py: the commands and their
argument checks (an argument of another command names the command that
owns it; a missing or empty required one shows its shape), the anchored
edit rules, the replace guard, moves through GMS's moveDocument (which
refuses a missing parent and a loop under the document's own
descendant; an upsert of documentInfo would not), the
SAVE_DOCUMENT_RESTRICT_UPDATES guardrail (off by default) also applied
to a move's target, the configuration-document guard, the host edit
policy with its pre-approval validator, lastModified stamped with the
caller, certification left out of the upsert, and
@min_version(oss="1.4.0", cloud="0.3.16"). The legacy OSS server's
version lacks move and the in-place guarantees; its separate
MCP_UPDATE_DOCUMENT_ENABLED gate is not ported (DataHub Cloud dropped it: the
two tools ship together).
So a failed update never re-parents a document or creates one: a
missing document is refused (use save_document to create); a failed
read stops the call before any write; a refused or failed move writes
nothing else; a content or property write is one upsert of the stored
document in its own folder, never retried, with GMS's reason on a
refusal and "may or may not have been applied" when there is no reply
(for an append, a warning that appending again would add the text
twice). SDK usage errors become tool errors.
Adapted to this package: shared helpers from save_document.py (write
handling, the caller, guards); existence read through ReadBackend;
moveDocument in document_writes.gql (valid on GMS 1.7.0, 1.8.0 and
master); ToolErrors throughout.
Tested: unit tests for anchored edits (one and replace-all) changing only
the body, edits that do not anchor (missing, ambiguous, no old_str)
writing nothing, the replace guard, append, update_properties leaving the
body (tags, status, settings actor), move through moveDocument with no
other write, a refused move changing nothing, arguments that do not fit
the command, a missing document not created, a failed read, a refused
update written once in its own folder, an append without a reply, the
shared-folder guardrail, a locked field refused before approval and by
the tool, and registration with save_document behind one gate. Live on a
local OSS DataHub with auth on, through the frontend's /mcp, on
run-unique test documents: an anchored edit, ambiguous and missing
anchors refused, replace refused then confirmed, append, title, topic and
status changed, all with the parent and owner unchanged; a foreign
argument and a missing document are errors; a temporary non-admin user's
PAT got "unauthorized to modify entity" for an append and "DataHub
rejected moveDocument: Unauthorized" for a move, and the document was
unchanged; a move to another folder worked, a move under the document's
own child got "would create a circular parent reference" and a move
under a missing document "does not exist", both leaving the parent as
it was. All test documents and the shared folder (absent before) were
hard-deleted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90677cf to
4a211d7
Compare
b29d76a to
7383f0c
Compare

Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on
na--mcp-save-document(the previous PR in the stack); review only its own commit. It changes only the shareddatahub-core-mcp-toolspackage anddatahub-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
masteras #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
45. #21511
46. #21512 ← this PR
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
update_document(urn, command, ...) changes part of an existing document
without sending it whole: update_content applies anchored {old_str,
new_str, replace_all_matches?} edits to the body; replace_content
replaces the body (allow_deleting_content=true is required when there
is one); append_content adds to the end; update_properties changes
title, topics, related documents, related assets or status
(PUBLISHED / UNPUBLISHED) without the body; move puts the document,
with what is nested under it, under another document. Every command but
move edits the stored document in place, keeping its parent, owners and
visibility. It is in the Write metadata group, destructive and not
idempotent, and is registered with save_document behind the same gates
(TOOLS_IS_MUTATION_ENABLED, SAVE_DOCUMENT_TOOL_ENABLED, both on by
default).
From DataHub Cloud's tools/update_document.py: the commands and their
argument checks (an argument of another command names the command that
owns it; a missing or empty required one shows its shape), the anchored
edit rules, the replace guard, moves through GMS's moveDocument (which
refuses a missing parent and a loop under the document's own
descendant; an upsert of documentInfo would not), the
SAVE_DOCUMENT_RESTRICT_UPDATES guardrail (off by default) also applied
to a move's target, the configuration-document guard, the host edit
policy with its pre-approval validator, lastModified stamped with the
caller, certification left out of the upsert, and
@min_version(oss="1.4.0", cloud="0.3.16"). The legacy OSS server's
version lacks move and the in-place guarantees; its separate
MCP_UPDATE_DOCUMENT_ENABLED gate is not ported (DataHub Cloud dropped it: the
two tools ship together).
So a failed update never re-parents a document or creates one: a
missing document is refused (use save_document to create); a failed
read stops the call before any write; a refused or failed move writes
nothing else; a content or property write is one upsert of the stored
document in its own folder, never retried, with GMS's reason on a
refusal and "may or may not have been applied" when there is no reply
(for an append, a warning that appending again would add the text
twice). SDK usage errors become tool errors.
Adapted to this package: shared helpers from save_document.py (write
handling, the caller, guards); existence read through ReadBackend;
moveDocument in document_writes.gql (valid on GMS 1.7.0, 1.8.0 and
master); ToolErrors throughout.
Testing
unit tests for anchored edits (one and replace-all) changing only
the body, edits that do not anchor (missing, ambiguous, no old_str)
writing nothing, the replace guard, append, update_properties leaving the
body (tags, status, settings actor), move through moveDocument with no
other write, a refused move changing nothing, arguments that do not fit
the command, a missing document not created, a failed read, a refused
update written once in its own folder, an append without a reply, the
shared-folder guardrail, a locked field refused before approval and by
the tool, and registration with save_document behind one gate. Live on a
local OSS DataHub with auth on, through the frontend's /mcp, on
run-unique test documents: an anchored edit, ambiguous and missing
anchors refused, replace refused then confirmed, append, title, topic and
status changed, all with the parent and owner unchanged; a foreign
argument and a missing document are errors; a temporary non-admin user's
PAT got "unauthorized to modify entity" for an append and "DataHub
rejected moveDocument: Unauthorized" for a move, and the document was
unchanged; a move to another folder worked, a move under the document's
own child got "would create a circular parent reference" and a move
under a missing document "does not exist", both leaving the parent as
it was. All test documents and the shared folder (absent before) were
hard-deleted.
Checklist
🤖 Generated with Claude Code