modifyText
Edit targeted Google Docs text by range or search: insert, replace, delete, or apply text and paragraph formatting to one location without rewriting the document.
Instructions
Best for small, targeted, single-location changes within a line or paragraph. Can insert text at a position, replace a range or found text, delete text (replace with empty string ""), apply text styling (bold, italic, etc.), apply paragraph styling (alignment, headings, spacing, list bullets via paragraphStyle.bulletPreset, etc.), or any combination. Use readDocument with format='index' to determine indices — it returns a compact structural map (headings, list items, tables with per-cell indices) instead of the full raw document. Supports \n for line breaks and \t for tabs in replacement text. When using textToFind, if multiple matches exist the tool returns all instances with context so you can specify matchInstance. textToFind tolerates markdown list markers copied from readDocument(format='markdown'), because Google Docs stores bullets outside text runs. For MULTIPLE edits in the same document, use batchModifyText instead: it applies them in one atomic batchUpdate against a single snapshot, so you do not have to recompute indices between edits and a collaborator cannot land halfway through. This tool is TEXT-ONLY: a multi-line replacement is inserted as one blob with a single paragraph style, so markdown syntax (e.g. a literal "- " or "1. " prefix) stays literal and is never parsed into a real list. paragraphStyle.bulletPreset is the one structural exception: it applies a REAL top-level bullet/number (createParagraphBullets) to every paragraph the target range covers — useful for a single inserted line that must match a bulleted/numbered section elsewhere in the document — but it is still one flat preset over the whole range, with no per-line nesting control; for that, or for richer multi-line structure, use replaceRangeWithMarkdown. For multi-line, list, or section-level content at a range, use replaceRangeWithMarkdown; to rewrite a whole document, use replaceDocumentWithMarkdown. To add content to the end of a doc, use appendMarkdown or appendText. Newly inserted text carries the document's default text color explicitly, when the document defines one. Google Docs also gives inserted text the CHARACTER formatting of the run around it, so replacing an italic placeholder with a long section makes that whole section italic: pass clearStyle:true to insert as plain body text instead. When you do not, the result names any non-default formatting the new text inherited. If the document changed after you read it, a textToFind target is re-resolved against the current document and proceeds when the change did not touch it; an explicit startIndex/endIndex or insertionIndex is refused unless the change landed strictly after the range, because explicit indices have no anchor to re-resolve and an edit before them moves the content they addressed. Prefer textToFind when a document has other editors.
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": "modifyText"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | No | New text to insert or replace with. | |
| style | No | Text formatting to apply (bold, italic, font size, etc.). | |
| tabId | No | The ID of the specific tab to operate on. If not specified, operates on the first tab. | |
| target | Yes | Target by range indices, text search, or insertion index. Nested object, one of: {"startIndex":N,"endIndex":M}, {"textToFind":"..."}, or {"insertionIndex":N}. | |
| clearStyle | No | If true, inserted text lands as plain body text instead of inheriting the character formatting of the run it replaced. Google Docs gives inserted text the formatting of the surrounding run, so replacing a one-line italic placeholder with a long section silently makes the whole section italic. Set this whenever the replacement is new content rather than an in-place edit of an existing phrase. Any `style` you also pass is applied after the clear, so it still wins. Ignored when the call inserts no text. When you do not set it, the result reports any non-default formatting the new text inherited. | |
| documentId | Yes | The document ID — the long string between /d/ and /edit in a Google Docs URL. | |
| 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. | |
| paragraphStyle | No | Paragraph formatting to apply (alignment, indentation, headings, spacing, list bullets, etc.). |