findAndReplace
Replace all visible text matches in a Google Docs document or tab and return the replacement count; an empty replacement deletes matches. Hyperlink targets cannot be changed.
Instructions
Replaces all occurrences of a text string throughout the document (or a specific tab). Returns the number of replacements made. Use an empty replaceText to delete all matches. This only changes VISIBLE text — it cannot change a hyperlink target. Renaming a mismatched link (e.g. readDocument flagged a LINK MISMATCH) with findAndReplace reports success but leaves the wrong URL/mailto in place; use modifyText with style.linkUrl on that range instead.
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>",
"findText": "<findText>",
"replaceText": "<replaceText>"
},
"name": "findAndReplace"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | No | Scope replacement to a specific tab. If omitted, replaces across all tabs. | |
| findText | Yes | The text to search for in the document. | |
| matchCase | No | Whether the search should be case-sensitive. Defaults to false. | |
| 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. | |
| replaceText | Yes | The replacement text. Use an empty string to delete all occurrences. |