Skip to main content
Glama

modifyText

Edit targeted Google Docs text by range or search: insert, replace, delete, or apply text and paragraph formatting to one location without rewriting the document.

Instructions

Best for small, targeted, single-location changes within a line or paragraph. Can insert text at a position, replace a range or found text, delete text (replace with empty string ""), apply text styling (bold, italic, etc.), apply paragraph styling (alignment, headings, spacing, list bullets via paragraphStyle.bulletPreset, etc.), or any combination. Use readDocument with format='index' to determine indices — it returns a compact structural map (headings, list items, tables with per-cell indices) instead of the full raw document. Supports \n for line breaks and \t for tabs in replacement text. When using textToFind, if multiple matches exist the tool returns all instances with context so you can specify matchInstance. textToFind tolerates markdown list markers copied from readDocument(format='markdown'), because Google Docs stores bullets outside text runs. For MULTIPLE edits in the same document, use batchModifyText instead: it applies them in one atomic batchUpdate against a single snapshot, so you do not have to recompute indices between edits and a collaborator cannot land halfway through. This tool is TEXT-ONLY: a multi-line replacement is inserted as one blob with a single paragraph style, so markdown syntax (e.g. a literal "- " or "1. " prefix) stays literal and is never parsed into a real list. paragraphStyle.bulletPreset is the one structural exception: it applies a REAL top-level bullet/number (createParagraphBullets) to every paragraph the target range covers — useful for a single inserted line that must match a bulleted/numbered section elsewhere in the document — but it is still one flat preset over the whole range, with no per-line nesting control; for that, or for richer multi-line structure, use replaceRangeWithMarkdown. For multi-line, list, or section-level content at a range, use replaceRangeWithMarkdown; to rewrite a whole document, use replaceDocumentWithMarkdown. To add content to the end of a doc, use appendMarkdown or appendText. Newly inserted text carries the document's default text color explicitly, when the document defines one. Google Docs also gives inserted text the CHARACTER formatting of the run around it, so replacing an italic placeholder with a long section makes that whole section italic: pass clearStyle:true to insert as plain body text instead. When you do not, the result names any non-default formatting the new text inherited. If the document changed after you read it, a textToFind target is re-resolved against the current document and proceeds when the change did not touch it; an explicit startIndex/endIndex or insertionIndex is refused unless the change landed strictly after the range, because explicit indices have no anchor to re-resolve and an edit before them moves the content they addressed. Prefer textToFind when a document has other editors.

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": {
      "documentId": "<documentId>",
      "target": "<target>"
    },
    "name": "modifyText"
  }
}

Input Schema

NameRequiredDescriptionDefault
textNoNew text to insert or replace with.
styleNoText formatting to apply (bold, italic, font size, etc.).
tabIdNoThe ID of the specific tab to operate on. If not specified, operates on the first tab.
targetYesTarget by range indices, text search, or insertion index. Nested object, one of: {"startIndex":N,"endIndex":M}, {"textToFind":"..."}, or {"insertionIndex":N}.
clearStyleNoIf true, inserted text lands as plain body text instead of inheriting the character formatting of the run it replaced. Google Docs gives inserted text the formatting of the surrounding run, so replacing a one-line italic placeholder with a long section silently makes the whole section italic. Set this whenever the replacement is new content rather than an in-place edit of an existing phrase. Any `style` you also pass is applied after the clear, so it still wins. Ignored when the call inserts no text. When you do not set it, the result reports any non-default formatting the new text inherited.
documentIdYesThe document ID — the long string between /d/ and /edit in a Google Docs URL.
readHandleNoCapability returned by a previous readDocument call for this document (and tab). Required over HTTP on the 2026-07-28 runtime: it authorizes the write and pins it to the revision that read saw. Omit it on stdio to use that connection's most recent read.
paragraphStyleNoParagraph formatting to apply (alignment, indentation, headings, spacing, list bullets, etc.).

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv4.0.0-rc.1

TDQS

A4.8/5.0
Behavior5/5

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

With no annotations supplied, the description carries the full burden and does so: it discloses the TEXT-ONLY limitation (markdown prefixes stay literal), the single exception via paragraphStyle.bulletPreset and its flat no-nesting constraint, character-formatting inheritance on insert plus the clearStyle remedy, and that inserted text carries the document default color explicitly. It also explains write authorization and revision pinning via readHandle, and the failure semantics when the document changed after reading (textToFind re-resolves; explicit indices are refused unless the change landed strictly after the range).

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?

It is front-loaded with the core scope and the routing rule in the first two sentences, and essentially every sentence adds a distinct constraint or alternative. However, it runs long (roughly 500 words) with several densely packed caveat clauses, and a few points (default text color, inherited-formatting reporting) are restated near the end, so it is thorough but not maximally tight.

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 an 8-parameter mutation tool with no annotations and no output schema, the definition covers targeting modes, index invalidation, style inheritance, list handling, and how the result reports inherited formatting. An agent has everything needed to choose the right target mode, set clearStyle correctly, and decide between this tool and its siblings.

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 the baseline is 3, but the description adds genuinely new meaning: textToFind tolerates markdown list markers because Docs stores bullets outside text runs, multiple matches return all instances with context so matchInstance can be supplied, \n and \t are honored in replacement text, and bulletPreset is scoped to the paragraphs the target range covers. Some redundancy remains with the schema (e.g., clearStyle and readHandle are already well documented inline), which keeps it just under 5.

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 first sentence states a specific verb set and scope: 'small, targeted, single-location changes within a line or paragraph,' then enumerates the exact operations (insert at position, replace range/found text, delete via empty string, text styling, paragraph styling). It explicitly distinguishes itself from batchModifyText, replaceRangeWithMarkdown, replaceDocumentWithMarkdown, appendMarkdown, and appendText, so an agent can route without opening another schema.

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?

It gives explicit when-to-use (single-location edits) and when-not-to-use with named alternatives and the reason: batchModifyText for multiple edits because it is atomic and avoids index recomputation, replaceRangeWithMarkdown for multi-line/list/section content, replaceDocumentWithMarkdown for full rewrites, appendMarkdown/appendText for end-of-doc additions. It also advises preferring textToFind when the document has other editors.

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