Skip to main content
Glama

Replace a text range

replace_range
Destructive

Replace a specified range in a Google Doc with new text in one atomic update, keeping the original start style. Use fresh indexes from read_document_text to ensure accurate placement.

Instructions

Replaces the content in [start_index, end_index) with new text — one atomic batchUpdate that deletes the range and inserts at its start, so nothing is lost if either step would fail. Get fresh indexes from read_document_text first: indexes are stale after ANY previous edit. The new text takes the style at start_index. Cannot cut across a table cell boundary or delete a paragraph's final newline together with only part of the next paragraph — the API rejects such ranges. An empty replacement is allowed and equals delete_range.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe replacement text; empty string just deletes the range.
tab_idNoTab to target (from list_tabs). Omit for the first/only tab.
end_indexYesEnd of the range to replace (exclusive).
segment_idNoHeader/footer/footnote segment id (from get_document). Omit for the document body.
document_idYesThe document id — the long id from the document URL (docs.google.com/document/d/<documentId>/edit) or from create_document output.
start_indexYesStart of the range to replace (inclusive).
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds substantial behavioral detail beyond annotations: the operation is a single atomic batchUpdate that protects against partial failure, new text inherits style at start_index, certain ranges are rejected by the API, and empty replacement behaves like delete_range. This is exactly the kind of context annotations cannot convey.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three dense, purposeful sentences. The core behavior is front-loaded, and each subsequent sentence adds behavioral constraints or prerequisites without any filler or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutating tool with no output schema and six parameters, the description covers prerequisites, failure semantics, style behavior, and invalid ranges. It does not explicitly describe the return value, but for an edit operation this is not a critical omission given the rich behavioral context provided.

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?

The schema already documents all six parameters with 100% coverage, so the baseline is 3. The description adds valuable parameter-level meaning: range boundaries are half-open, indexes must be freshly fetched, and constraints around table cells and paragraph newlines affect valid start/end values.

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?

The description states a specific action ('Replaces the content in [start_index, end_index) with new text'), identifies the exact resource, and clarifies edge behavior (empty replacement equals delete_range). This clearly differentiates it from siblings like insert_text or replace_all_text.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives strong contextual guidance: fetch fresh indexes from read_document_text first, notes that indexes are stale after any prior edit, and lists API constraints on valid ranges. It does not explicitly contrast with insert_text or replace_all_text, but it is clear when this tool applies.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/A1-x-Tech/mcp-google-docs'

If you have feedback or need assistance with the MCP directory API, please join our Discord server