Skip to main content
Glama

Docs Replace Document Text

docs_replace_document_text
Idempotent

Replace every occurrence of specified text in a Google Docs document using its document ID; optionally match case and return the number of occurrences changed.

Instructions

Replace every occurrence of a piece of text in a Google Docs document. The document_id comes from drive_list_files, search_workspace or docs_create_document; to add text use docs_append_document_text, and for formatting or targeted edits use docs_batch_update_document (extended tool tier). Returns status 'ok', document_id, revision_id and occurrences_changed, which is 0 when nothing matched.

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": {
      "contains_text": "<contains_text>",
      "document_id": "<document_id>",
      "replace_text": "<replace_text>"
    },
    "name": "docs_replace_document_text"
  }
}

Input Schema

NameRequiredDescriptionDefault
match_caseNoMatch letter case exactly when true; by default matching ignores case.
document_idYesGoogle Docs document ID: the Drive file ID, also the long ID in the document's URL.
replace_textYesText that replaces each occurrence; an empty string deletes the matches.
contains_textYesExact text to find; every occurrence is replaced.

Output Schema

NameRequiredDescriptionDefault
statusNoMachine-readable operation status.
document_idNo
revision_idNo
occurrences_changedNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv2.2.0

TDQS

A4.7/5.0
Behavior4/5

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

Annotations already declare the mutation profile (readOnly=false, destructive=false, idempotent=true, openWorld=true), so the description's job is to add context beyond that. It does: replacement is global across all matches, and occurrences_changed is 0 when nothing matched, which tells the agent how to detect a no-op. It stops short of stating access/scope requirements or that the edit lands in document revision history.

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 sentences, front-loaded with the operation, then routing, then return values. Every clause carries information an agent needs; there is no restatement of the title or filler.

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 4-parameter mutation tool with an output schema and full annotations, the definition covers operation scope, sibling routing, ID sourcing, and no-match behavior. The only remaining gaps are edit-permission/scope requirements and whether existing document formatting around matches is preserved.

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 coverage is 100%, so baseline would be 3, but the description adds real meaning beyond the schema: it identifies document_id as originating from drive_list_files, search_workspace, or docs_create_document, turning an opaque file ID into an actionable lookup chain. Case sensitivity and deletion-via-empty-string are already handled by the schema, so nothing is missing.

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 precise verb and resource ('Replace every occurrence of a piece of text in a Google Docs document') and pins down the scope of the operation as global-within-document. It explicitly separates itself from docs_append_document_text (adding text) and docs_batch_update_document (formatting/targeted edits), so an agent can route correctly without opening schemas.

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?

Names the alternatives and the exact condition that selects each: append tool for adding text, batch_update for formatting or targeted edits. It also tells the agent where valid document_id values come from (drive_list_files, search_workspace, docs_create_document), which prevents a common upstream mistake.

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

Deploy Server

Other Tools