Skip to main content
Glama

replaceRangeWithMarkdown

Replace one section of a Google Doc with parsed Markdown, including headings, lists, tables, and links, while leaving content outside the chosen range untouched.

Instructions

Best for rewriting ONE section of a document with real structure. Replaces a caller-chosen range with content parsed from markdown, building true headings, nested bullet/numbered lists, tables, links, and the rich markdown HTML extensions — everything replaceDocumentWithMarkdown builds, scoped to a range. Address the range three ways: explicit {startIndex,endIndex} from readDocument with format='index'; {afterHeading} (or {headingId}) to replace everything under a heading, up to the next heading of the same or shallower level; or {textToFind}. Set startIndex == endIndex to INSERT markdown at an index without deleting anything. Use this instead of modifyText whenever the replacement is multi-line or contains lists — modifyText is text-only and flattens list nesting. Use replaceDocumentWithMarkdown when you are rewriting the whole body, and appendMarkdown to add to the end. Content outside the range is left untouched, including images, horizontal rules, and other sections; only content inside the range is checked for markdown fidelity, and by default a range holding an image or footnote is refused rather than silently flattened (onFidelityLoss). Pass dryRun to see the resolved range and what would be lost without writing. The write is guarded by the revision the read saw. If the document changed since you read it, an afterHeading/headingId or textToFind target is re-resolved against the current document and proceeds when the change did not touch the section; an explicit startIndex/endIndex is refused unless the change landed strictly after the range, since explicit indices have no anchor to re-resolve. Refusals name what changed and where.

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>",
      "target": "<target>"
    },
    "name": "replaceRangeWithMarkdown"
  }
}

Input Schema

NameRequiredDescriptionDefault
tabIdNoThe ID of the specific tab to edit. If not specified, edits the first tab.
dryRunNoResolve and validate the range, report what would change, and make no writes.
targetYesThe range to replace: explicit {startIndex,endIndex} (from readDocument format='index'), {afterHeading|headingId} for a whole section, or {textToFind} for content located by text.
filePathNoPath to a local markdown file to use as the replacement content. Takes precedence over markdown.
markdownNoInline markdown to put in the range. Prefer filePath for content longer than ~2000 characters.
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.
onFidelityLossNoWhat to do when the range contains content markdown cannot represent (images, footnotes, a generated table of contents). 'block' (default) refuses and names what would be lost; 'warn' proceeds and reports it. Content OUTSIDE the range is never inspected and never at risk.block
preserveHeadingNoHeading targets only. True (default) replaces the content BELOW the heading and keeps the heading itself; false moves the range start to the heading paragraph so the heading is replaced too.
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.

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?

With no annotations, the description carries the full burden and does so: it discloses the fidelity-loss policy ('by default a range holding an image or footnote is refused'), that content outside the range is never at risk, and the revision-guard behavior including the asymmetric re-resolution of anchored vs. explicit-index targets. It also explains dryRun and that refusals name what changed — none of which is inferable from the schema.

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 one-line purpose and sibling differentiators before the mechanics, and every paragraph maps to a distinct concern (targeting, alternatives, range safety, concurrency). It is long and dense for a single paragraph block; a few clauses such as the repeated restatement of what the range holds could be tightened without losing information.

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?

A 10-parameter mutation tool with no annotations and no output schema is the hardest case, and the description covers purpose, targeting, alternatives, safety/refusal behavior, and concurrency semantics. What it omits (return shape, path-vs-inline precedence) is already documented in the schema, so an agent has everything needed to call it correctly.

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 coverage is 100%, so baseline is 3, but the description adds real meaning: it explains the three alternative shapes of the `target` union and their semantics, and crucially that 'startIndex == endIndex' means insert-without-delete. It also ties `readHandle` to the revision the read saw. Minor gap: it does not discuss `filePath` vs `markdown` precedence or `preserveHeading`, though the schema covers both.

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+resource (replace a range with markdown-parsed content) and immediately bounds scope: 'rewriting ONE section of a document with real structure'. It explicitly contrasts itself with replaceDocumentWithMarkdown ('scoped to a range') and modifyText ('text-only and flattens list nesting'), so an agent can pick it without opening a sibling schema.

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 explicit routing rules in both directions: 'Use this instead of modifyText whenever the replacement is multi-line or contains lists', 'Use replaceDocumentWithMarkdown when you are rewriting the whole body, and appendMarkdown to add to the end'. It also names the three targeting modes and when each applies (index from readDocument, heading section, textToFind).

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