Skip to main content
Glama
Google Workspace MCP Server

Google Workspace MCP Server

by mutallipp

Batch Update Doc

batch_update_doc
Destructive

Apply multiple Google Docs edits—text, formatting, tables, and breaks—in one atomic batch to avoid partial updates and index-shift errors.

Instructions

Executes multiple low-level document operations in a single atomic batch update.

For normal header/footer text, prefer update_doc_headers_footers. Only use create_header_footer here for advanced section-break layouts.

RECOMMENDED WORKFLOW FOR BUILDING DOCUMENTS:

To avoid index calculation errors, build documents in phases:

PHASE 1 - INSERT ALL CONTENT (use end_of_segment=true, no index math): Append text, section breaks, and page breaks sequentially. Each operation appends to the end of the body. No index needed. Example batch: [ {"type": "insert_text", "end_of_segment": true, "text": "Report Title\n"}, {"type": "insert_text", "end_of_segment": true, "text": "\nExecutive Summary\n"}, {"type": "insert_text", "end_of_segment": true, "text": "Revenue grew 15%.\n"}, {"type": "insert_section_break", "end_of_segment": true, "section_type": "NEXT_PAGE"}, {"type": "insert_text", "end_of_segment": true, "text": "Detailed Analysis\n"} ]

PHASE 2 - CREATE HEADERS/FOOTERS (if needed): For normal header/footer text, use update_doc_headers_footers (it auto-creates if missing and writes the content for you). Only include create_header_footer operations in a batch when you are intentionally managing advanced section-break-specific layouts.

PHASE 3 - INSPECT STRUCTURE: Call inspect_doc_structure with detailed=true to get exact start_index and end_index for every paragraph and element.

PHASE 4 - APPLY FORMATTING (separate batch using indices from Phase 3): Use the real indices from inspect_doc_structure output: [ {"type": "update_paragraph_style", "start_index": 1, "end_index": 15, "heading_level": 1, "alignment": "CENTER"}, {"type": "format_text", "start_index": 1, "end_index": 15, "bold": true, "font_size": 24}, {"type": "create_bullet_list", "start_index": 50, "end_index": 120, "list_type": "ORDERED"} ]

ALTERNATIVE - FIND_REPLACE PATTERN (no indices needed at all): Insert text with unique placeholders, then use find_replace: [ {"type": "insert_text", "end_of_segment": true, "text": "{{TITLE}}\n{{BODY}}\n"}, {"type": "find_replace", "find_text": "{{TITLE}}", "replace_text": "Quarterly Report"}, {"type": "find_replace", "find_text": "{{BODY}}", "replace_text": "The results show..."} ]

ALTERNATIVE - SEMANTIC ANCHORS (target existing structure without indices): Insertion operations accept after_heading, before_heading, or anchor_text with anchor_position instead of index. Each is resolved against the document at execution time, so it cannot go stale the way a pre-computed index can, and an anchor matching zero or several places is refused rather than guessed. Submit anchored insertions in their own batch; they execute from highest index to lowest to keep targets stable. [ {"type": "insert_text", "after_heading": "Results", "text": "Revenue grew 15%.\n"}, {"type": "insert_text", "anchor_text": "Conclusion", "anchor_position": "before", "text": "See appendix.\n"} ]

WARNING - AVOID THIS ANTI-PATTERN: Do NOT pre-compute sequential indices for multiple insert_text operations. Each insertion shifts all subsequent indices and manual calculation is error-prone. Use end_of_segment=true instead, which always appends to the current end. BAD: [{"type":"insert_text","index":1,"text":"Hello\n"}, {"type":"insert_text","index":8,"text":"World\n"}] <- index 8 may be wrong GOOD: [{"type":"insert_text","end_of_segment":true,"text":"Hello\n"}, {"type":"insert_text","end_of_segment":true,"text":"World\n"}]

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": {
      "user_google_email": "<user_google_email>",
      "document_id": "<document_id>",
      "operations": "<operations>"
    },
    "name": "batch_update_doc"
  }
}

Input Schema

NameRequiredDescriptionDefault
operationsYesList of operation dicts. Each operation MUST have a 'type' field. All operations accept an optional 'tab_id' to target a specific tab.
write_modeNo"EDIT" (default) applies the batch directly; "SUGGEST" records every operation as a suggested edit that collaborators can accept or reject. The Docs API rejects some operations in SUGGEST mode, such as named range and tab changes.EDIT
document_idYesID of the document to update
user_google_emailYesUser's Google email address

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv2.8.0

TDQS

A4.5/5.0
Behavior4/5

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

Annotations already declare destructiveHint=true, readOnlyHint=false, openWorldHint=true and non-idempotent, so the safety profile is covered. The description adds genuine behavior beyond that: the batch is atomic, anchors are resolved at execution time and 'an anchor matching zero or several places is refused rather than guessed', and anchored insertions run highest-index-to-lowest for stability. It does not mention the write_mode=SUGGEST path or rollback-on-failure details, which are left to the schema.

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

Conciseness3/5

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

Front-loaded and well-sectioned, but redundant: the header/footer routing advice appears twice (opening paragraph and Phase 2), and the BAD/GOOD anti-pattern restates the Phase 1 guidance. It is long for a tool whose schema already enumerates the operations, though most sentences still carry useful routing or safety information.

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 tool with a large oneOf operation union, an output schema present (so return values need not be explained), and destructive semantics, the description covers the full decision path: which operations to batch, in what order, with which targeting mechanism. Nothing an agent needs to call it correctly appears missing.

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 meaningfully adds operational semantics: end_of_segment=true removes the need for index math, anchors substitute for indices, and pre-computing sequential indices shifts subsequent positions. The worked JSON examples show how the operation objects combine in practice, which the schema alone does not convey.

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 names a specific verb and resource ('Executes multiple low-level document operations in a single atomic batch update') and immediately distinguishes it from update_doc_headers_footers. An agent can identify this as the general-purpose multi-op batch writer without opening the 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?

Explicit when-to-use guidance: the preferred workflow for building documents (four phases), two named alternatives (find_replace pattern, semantic anchors), and an explicit routing rule for header/footer work to update_doc_headers_footers with the narrow exception for section-break layouts. It also states an anti-pattern to avoid.

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