readDocument
Reads Google Docs content as markdown, plain text, structural index, or raw JSON, and saves a local working copy for reviewable edits before replacing document content.
Instructions
Reads the content of a Google Document. Returns markdown by default (formatted content suitable for editing and re-uploading with replaceDocumentWithMarkdown) and saves it to a local working-copy file (path included in the response). PREFERRED EDITING WORKFLOW for large edits: (1) readDocument to get the local file path, (2) edit that file locally, (3) call replaceDocumentWithMarkdown with filePath pointing to it. This avoids inline content truncation and gives you a reviewable working copy before pushing changes. If the document contains content markdown cannot represent (images, footnotes), a warning is appended listing what replaceDocumentWithMarkdown would permanently remove — prefer modifyText or appendMarkdown for those documents. Use format='text' for plain text, or format='index' to get a compact structural map (headings, list items and nesting, tables with per-cell indices) with the exact startIndex/endIndex every index-addressed tool needs. format='index' is the cheap way to find indices: it fetches a narrow field mask instead of the whole document, so it stays affordable even for tabbed documents. format='json' returns the raw, unpruned API structure and is only for callers that genuinely need suggestions or style provenance. Set diffFromLastRead=true (markdown only) to get a unified diff from your previous read in this session instead of the full content.
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>"
},
"name": "readDocument"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | No | The ID of the specific tab to read. If not specified, reads the first tab (or legacy document.body for documents without tabs). | |
| format | No | Output format: 'markdown' (formatted content), 'text' (plain text), 'index' (compact structural map with character indices — use this to find indices for modifyText/deleteRange/insertTable), 'json' (raw API structure, large and unpruned). | markdown |
| fromIndex | No | format='index' only. Resume point: elements ending at or before this document index are dropped. Pass the nextFromIndex from a truncated index response to get the next page. The Docs API has no start-index cursor, so each page costs another (narrow) fetch. | |
| maxLength | No | Maximum character limit for the returned content. Applies to text, markdown, and json output (not to index, which uses maxResponseChars and truncates at element boundaries). Must be a positive integer; omit it for the full document. | |
| documentId | Yes | The document ID — the long string between /d/ and /edit in a Google Docs URL. | |
| plainMarkdown | No | For Google Docs markdown output only. If true, suppresses rich HTML-style formatting extensions and returns cleaner portable markdown. The local working-copy file and diff/conflict tracking always keep the rich version — for lossless editing, edit the working-copy file, not this plain text. Ignored (with a note) when diffFromLastRead is true. | |
| writeLocalFile | No | For Google Docs markdown output only (format='markdown'). If false, this read does not touch the on-disk local mirror file at all — no overwrite, no backup, response text is unaffected. Use this to run a diffFromLastRead staleness check (or any read you do not intend to edit locally) without risking the mirror. When true (the default) and the SDK v2 runtime's per-handle capability system is not in play, this read overwrites the shared mirror at the path from a previous read of this document/tab; if that file's on-disk content is newer than this process's own last write to it (a local edit readDocument told you to make, still unpushed), it is backed up to '<path>.bak' first and the result says so — the overwrite still proceeds, so recover from the .bak file, not from a re-read. | |
| diffFromLastRead | No | If true and this document has already been read in this session (with format=markdown), returns a unified diff from the previous read to the current document instead of the full content. Ignored on first read or when format is not markdown. | |
| maxResponseChars | No | format='index' only. Character budget for the serialized index. Truncation lands on element boundaries so the JSON is always valid. 0 disables the budget. Defaults to 100000. | |
| stripInheritedStyles | No | format='json' only. If true, drops inherited textStyle/documentStyle/namedStyles and every suggested* map from the raw document. Every startIndex/endIndex is preserved. Off by default: format='json' means a faithful raw document. |