Skip to main content
Glama

replace_text

Replace a text string in a Google Docs tab by verifying exact matches, setting expected match count, and previewing with dry-run to prevent accidental changes.

Instructions

Replace occurrences of a text string in a Google Doc tab.

Use this tool when you need to make an exact-text substitution in a document tab. Call list_tabs first to get the tab_id, then read_document to confirm the text you want to replace is present as-is.

The tool locates every occurrence of find using a normalization ladder (exact → curly/straight quote equivalence → NBSP/whitespace collapse → soft-hyphen strip) and refuses the write if the match count does not equal expected_matches. This prevents accidental multi-replacement and duplicate-sentence collapse.

Set dry_run=True to preview the operation without writing; the response carries applied: false and the matched span information but makes no API call.

On success the response carries before/after excerpts (±200 chars), the normalization rung used, pre/post revision IDs, and audit_logged.

Errors are returned as typed envelopes with error_code, message, diagnostics, and retryable so the caller can act on them precisely: ZERO_MATCH – find string not found; near-miss span included MATCH_COUNT_MISMATCH – wrong number of matches; all locations listed REVISION_CONFLICT – document changed mid-call; re-read and retry STRUCTURAL_BOUNDARY – match crosses a paragraph boundary INVALID_INPUT – empty find, or find equals replace TAB_NOT_FOUND – tab_id not in document; available tabs listed SUGGESTIONS_PRESENT – tab has pending suggested edits; accept/reject them in the Docs UI first, then retry (a pending suggestion makes the write's computed indices unsafe — see verified writes, below)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
findYes
doc_idYes
tab_idYes
dry_runNo
replaceYes
expected_matchesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.2.0

TDQS

A4.7/5.0
Behavior5/5

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

No annotations are provided, so the description carries the full burden, and it delivers: normalization ladder behavior, refusal on match-count mismatch, dry_run semantics, response details, and seven typed error envelopes. This gives the agent a strong model of side effects and failure modes.

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

Conciseness4/5

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

Purpose and usage guidance are front-loaded, and the detailed error-code list earns its place for a mutation tool. A small deduction is warranted for the dangling reference 'see verified writes, below' and the overall length, though every other sentence adds actionable value.

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

Completeness5/5

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

For a 6-parameter mutation tool with no annotations and no schema-level descriptions, this description is remarkably complete. It covers prerequisites, matching behavior, preview mode, response contents, and a comprehensive error taxonomy, so an agent has what it needs to call the tool correctly and handle failures.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description compensates thoroughly. It explains how find is matched via normalization, how expected_matches guards against accidental replacement, what dry_run does, and how tab_id should be obtained via list_tabs. The self-explanatory doc_id and replace parameters require no further elaboration.

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 opening sentence states a specific verb and resource: 'Replace occurrences of a text string in a Google Doc tab.' It further clarifies this is an exact-text substitution, which distinguishes it from markdown-oriented sibling tools like replace_range_markdown and replace_tab_markdown.

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 explicitly says when to use the tool ('when you need to make an exact-text substitution') and prescribes a clear prerequisite workflow: call list_tabs first, then read_document to confirm the text. It does not explicitly name alternative tools or state when not to use it, so it falls just short of the highest bar.

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