Skip to main content
Glama

Replace text in Google Doc

replace_text
Destructive

Replace every occurrence of a text string throughout an entire Google Doc with new text in one operation, or delete all matches by supplying an empty replacement.

Instructions

Replace ALL occurrences of searchText throughout the entire Google Doc with replacementText, in one operation. An empty replacementText DELETES every occurrence. Matching is plain text (no regular expressions) and case-insensitive unless matchCase is true, so a short search such as "an" may also match inside other words. If the search text is short or could match more than intended, preview the matches with find_text first, and use insert_text/delete_text for a single occurrence. Returns occurrencesChanged (0 means nothing matched and the document is unchanged). Indexes after each changed occurrence shift when the lengths differ. No index is needed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
matchCaseNoOnly replace matches with exactly the same upper/lower case (default false).
documentIdYesThe Google Docs document ID (the part between /d/ and /edit in the document URL). A full Google Docs URL is also accepted.
searchTextYesThe exact text to search for (not a regular expression).
replacementTextYesText that replaces every match. An empty string deletes every match.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.9/5.0
Behavior5/5

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

Annotations already flag destructiveHint=true, openWorldHint=true, and idempotentHint=false, and the description corroborates it by explaining that an empty replacementText DELETES every match. It adds further behavior annotations do not carry: case-insensitive default matching, plain-text (non-regex) semantics, substring false-positive risk, the occurrencesChanged return value, and index shifting after length-changing replacements.

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?

The behavior and the biggest pitfall (short search strings, empty replacement = deletion) are front-loaded. The remaining sentences each carry a distinct fact — matching semantics, alternative tools, return value, index shifting — with no filler.

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?

Given a destructive write tool with no output schema and fully documented params, the description covers the gaps that matter: what deletion means, matching rules, how to preview, what is returned, and the index-shift caveat. An agent has enough to invoke it safely.

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?

Schema coverage is 100%, so baseline is 3, but the description adds genuine meaning beyond the schema: an empty replacementText deletes matches, matchCase is false by default, searchText is literal plain text, and matching may hit substrings inside other words. This clarifies parameter interaction rather than restating field docs.

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?

States a specific verb (replace) plus resource (text in a Google Doc) with explicit scope: ALL occurrences, throughout the entire document, in one operation. This clearly separates it from the sibling single-occurrence tools insert_text/delete_text.

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

Usage Guidelines5/5

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

Gives an explicit when-to-use condition for itself (bulk replacement) and names the alternatives: preview with find_text when the search text is short or ambiguous, and use insert_text/delete_text for a single occurrence. Also warns when NOT to trust the naive approach.

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