batchModifyText
Apply up to 200 small text edits—replace, insert, delete, or style—to a Google Doc in one atomic batch with conflict checks and optional dry-run preview.
Instructions
Best for MANY small, scattered text edits in one document — the multi-location form of modifyText. Applies up to 200 operations (replace a range or found text, insert at an index, delete, apply text or paragraph styling) in ONE atomic batchUpdate. Every target is resolved against one document snapshot and applied highest-index-first, so the indices you read stay valid for all of them and you do not have to recompute offsets between edits. All-or-nothing: if one operation is invalid, none are applied, and the whole batch is guarded by a single revision check, so a concurrent edit is reported as a conflict rather than written against shifted indices. If the document changed after you read it, every operation is classified against that change: textToFind operations are re-resolved against the current document and proceed when the change did not touch them, while explicit index operations are refused unless the change landed strictly after their range. Any operation that is refused refuses the whole batch, naming what changed and where. Operations whose resolved ranges overlap are rejected up front, naming both. Pass dryRun to get the proposed-vs-current unified diff, an explicit deletion summary, and a per-operation breakdown without writing; a real call returns the same diff for what it applied. This tool is TEXT-ONLY, like modifyText: a multi-line replacement is inserted as one blob with a single paragraph style, so markdown syntax stays literal and list nesting is flattened. For structured content (lists, headings, tables) at a range use replaceRangeWithMarkdown; to rewrite a whole document use replaceDocumentWithMarkdown — but prefer this tool over that one for local edits, because a full-body rewrite orphans comment anchors and regenerates every headingId. Use readDocument with format='index' for indices, or listHeadings for the outline. Newly 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>",
"operations": "<operations>"
},
"name": "batchModifyText"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | No | The ID of the specific tab to operate on. Applies to every operation in the batch. If not specified, operates on the first tab. | |
| dryRun | No | Resolve and validate every operation, return the unified diff and the per-operation summary, and make no writes at all. | |
| documentId | Yes | The document ID — the long string between /d/ and /edit in a Google Docs URL. | |
| operations | Yes | The edits to apply, 1-200. Order does not matter: targets are resolved against one snapshot and applied highest-index-first, so the indices you read stay valid for every operation. | |
| readHandle | No | Capability 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. | |
| expectedRevisionId | No | Optional compare-and-write assertion: the write is refused unless the read handle was issued for this revision. It is an assertion only, never authorization. |