Skip to main content
Glama

replaceDocumentWithMarkdown

Replaces a Google Docs document body with Markdown content, including headings, lists, tables, and supported formatting. Use it to rewrite entire documents from edited Markdown.

Instructions

Best for rewriting entire sections or full documents. Replaces the entire document body with content parsed from markdown. Supports headings, bold, italic, strikethrough, links, tables, bullet/numbered lists, and rich markdown HTML extensions for underline, color, highlight, font, alignment, and blockquotes. Does not support markdown images or raw HTML outside those listed extensions; unsupported content is omitted and reported as warnings in the result. Use insertImage for images. Use readDocument with format='markdown' first to get the current content, edit it, then call this tool to apply changes. PREFERRED WORKFLOW for large edits: readDocument saves the content to a local working-copy file and returns its path — edit that file, then pass it here as filePath instead of inline markdown, to avoid truncation and get a reviewable diff before pushing. DESTRUCTIVE METADATA WARNING: this rebuilds the whole body, which Google Docs treats as new content, so unresolved comments anchored in the replaced text lose their anchors and every headingId is regenerated, breaking in-document links that pointed at headings. Both are enumerated before the delete and reported (onCollateral='block' refuses instead of warning), and the response carries the post-write heading map so links can be repointed. Pass dryRun to see the proposed-vs-current unified diff and the full collateral list without writing anything. For several small scattered edits, use batchModifyText — it edits in place in one atomic batch and costs no comment anchors or heading ids. To rewrite ONE section instead of the whole body — keeping images, rules, and every other section untouched — use replaceRangeWithMarkdown, which builds the same structure inside a caller-chosen range. For small single-location edits (one line or paragraph), use modifyText instead. To add content without rewriting, use appendMarkdown. Inserted text carries the document's default text color explicitly, when the document defines one.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "documentId": "<documentId>"
    },
    "name": "replaceDocumentWithMarkdown"
  }
}

Input Schema

NameRequiredDescriptionDefault
tabIdNoThe ID of the specific tab to replace content in. If not specified, replaces content in the first tab.
dryRunNoPreview only: returns the proposed-vs-current unified diff, the deletion summary, and the full comment/heading-link collateral list, and performs NO delete, no cleanup, no insert, and no workspace write.
filePathNoPath to a local markdown file to use as content. Takes precedence over the markdown parameter. Use this for large documents to avoid truncation.
markdownNoInline markdown content. Prefer filePath instead for content longer than ~2000 characters — use the working-copy path returned by readDocument, edit that file, then pass it here.
documentIdYesThe document ID — the long string between /d/ and /edit in a Google Docs URL.
readHandleNoCapability returned by a previous readDocument call for this document (and tab). Required over HTTP on the 2026-07-28 runtime: it authorizes the write and pins it to the revision that read saw. Omit it on stdio to use that connection's most recent read.
onCollateralNoWhat to do when the replace would orphan unresolved comment anchors or break in-document heading links. 'warn' (default) proceeds and reports them; 'block' refuses and lists them. Under 'block', a collateral check that could not run (for example comments could not be listed) is also a refusal, since a check that did not run cannot clear anything.warn
preserveTitleNoIf true, preserves the first heading/title and replaces content after it.
expectedRevisionIdNoOptional compare-and-write assertion: the write is refused unless the read handle was issued for this revision. It is an assertion only, never authorization.
firstHeadingAsTitleNoIf true (default), the first H1 heading (# ...) in the markdown is styled as a Google Docs TITLE instead of Heading 1. Useful when the markdown represents a full document whose first line is the document title. Set to false if the first H1 should remain a Heading 1.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv4.0.0-rc.1

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description carries the full burden and does so: it discloses that the whole body is rebuilt and treated as new content, that unresolved comments lose anchors, that every headingId is regenerated and breaks in-document links, and that the response carries a post-write heading map for repointing. It further documents dryRun's preview behavior, onCollateral='block' semantics (including refusal when the collateral check itself could not run), and readHandle authorization over HTTP with revision pinning.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the use case, then capabilities, then the destructive-metadata warning, then alternatives — a reader can stop early and still act correctly. It is long, but nearly every sentence is functional; only minor redundancy appears where dryRun and onCollateral are restated relative to the schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 10-parameter destructive mutation with no annotations and no output schema, the description covers unsupported-content behavior (images/raw HTML omitted and reported as warnings), what the result contains (warnings, collateral list, heading map), and the safe invocation path (dryRun, readHandle, expectedRevisionId). Nothing an agent needs to call it correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3; the description adds real meaning on top by specifying the precedence and preferred use of filePath over markdown for long content, and by framing readHandle as both authorization and revision pinning rather than a plain string. It does not, however, explain tabId fallback or firstHeadingAsTitle beyond what the schema already states.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('replaces the entire document body with content parsed from markdown') and immediately scopes it as 'best for rewriting entire sections or full documents'. It also explicitly distinguishes itself from replaceRangeWithMarkdown (one section, keeps images/rules), appendMarkdown (add without rewriting), and modifyText (single-location edits), so an agent can disambiguate without opening sibling schemas.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives an explicit ordering of operations: readDocument with format='markdown' first, edit, then apply; and a named preferred workflow using the working-copy path as filePath for large content. It also routes to alternatives by condition — batchModifyText for scattered small edits, replaceRangeWithMarkdown for one section, modifyText for one line/paragraph, appendMarkdown to add, insertImage for images.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools