Skip to content

feat(mcp): port the update_document tool - #21512

Merged
nwadams merged 1 commit into
na--mcp-save-documentfrom
na--mcp-update-document
Nov 25, 2026
Merged

nwadams merged 1 commit into
na--mcp-save-documentfrom
na--mcp-update-document

Conversation

@nwadams

@nwadams nwadams commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

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 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
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

  • 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

@nwadams
nwadams requested a review from lakshay-nasa November 22, 2026 23:36
@cursor

cursor Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
Adds a new update_document MCP write tool so agents can edit existing DataHub documents without round-tripping the full body, registered together with save_document behind the same mutation / SAVE_DOCUMENT_TOOL_ENABLED gates.

Commands: anchored update_content, guarded replace_content, append_content, metadata-only update_properties, and move (via new GraphQL moveDocument / updateDocumentContents in document_writes.gql). Content changes go through GMS’s content mutation (not a full upsert); property edits upsert in place with shared guards (edit policy, configuration docs, optional shared-folder restriction, validation / error messaging).

Includes a large test_update_document.py suite and updates tool-list expectations in ai-service and MCP registration tests.

Reviewed by Cursor Bugbot for commit 7383f0c. Bugbot is set up for automated code reviews on this repo. Configure here.

This was referenced Nov 22, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

Fix All in Cursor

❌ 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>
@nwadams
nwadams merged commit 7383f0c into na--mcp-save-document Nov 25, 2026
52 of 68 checks passed
@nwadams
nwadams deleted the na--mcp-update-document branch November 25, 2026 14:52

This branch was successfully deployed

1 active deployment
Preview — 7383f0c7 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants