Connect the Google Docs MCP server to your AI agent Open source, MIT, on npm. Setup instructions for Claude, Cursor and Codex are in the repository; adoption questions — Telegram. GitHub repository Telegram

Google Docs: Replace a text range — MCP tool

Google Docs MCP tool: Replaces one exact index range with new text in a single atomic batchUpdate.

Technical name: replace_range

What task it solves

I want to rewrite a specific passage of a document.

Replaces one exact index range with new text in a single atomic batchUpdate.

When to use it

Use it when position matters — rewriting one sentence, one heading or one occurrence among many. For textual find-and-replace across the document use replace_all_text; for a full rewrite use import_markdown.

What to provide

  • document_idrequired.
  • start_index / end_indexrequired. The range [start, end) from read_document_text, fetched AFTER the latest edit.
  • textrequired. The replacement; empty string just deletes the range.
  • tab_id, segment_id — optional addressing.

What it returns

The batchUpdate reply with the new revisionId.

What changes in Google Docs

The old range content is deleted and the new text inserted at its start in one atomic call. The new text takes the style at start_index. All later indexes shift.

Example request

Replace the second paragraph of the summary with this shorter version.

Errors and limitations

The range must not cut across a table cell boundary. Stale indexes hit the wrong text — always re-read first. The deleted content is unrecoverable; the call is never retried automatically after an ambiguous failure.

Access also depends on token permissions, quotas, and upstream API limits.

Related MCP tools

Technical details