write_doc_content
Replaces an existing Google Doc's full content with HTML or Markdown, including headings, lists, tables, links, code blocks, and images. Creates a backup before clearing the doc when possible.
Instructions
Replace the full content of an existing Google Doc.
Content is interpreted as HTML by default. Pass content_format='markdown' to supply Markdown instead. Headings, paragraphs, lists, links, tables, fenced code blocks, task list items, and images are all supported. Each table is inserted where it appears in the content. In HTML, a line break inside a tag's text is a space, as a browser shows it: use or (or Markdown) for line structure. Plain text with no tags at all keeps each line as its own paragraph. Use this to populate a doc created manually in Drive (bypassing service account storage quota limits).
Images are embedded inline the same way create_doc's own content_format='markdown' path handles them — see that tool's docstring for the src conventions, the revoke_sharing tradeoff, the auto_downscale size-limit behavior, and the alt-text fallback. A local-path image is uploaded to folder_id, else the server's default folder, else the doc's own folder. If the content has a local-path image this server can read and none of those is known (or the doc's folder can't be looked up), the call returns an error and leaves the doc unchanged. A local-path image it can't read (a missing file, or one LOCAL_FILE_ACCESS refuses) doesn't stop the call: it's written as its alt text, like any image that can't be embedded. A relative path that doesn't exist as written is also tried percent-decoded ("my%20pic.png").
Args: doc_id: The Google Doc file ID. content: Content to write into the document body. content_format: 'html' (default) or 'markdown' autolink_urls: When content_format='markdown', whether a bare http(s):// URL, www. address or email address becomes a real hyperlink (default True). Set False to leave them as plain text; to suppress just one, wrap it in backticks instead. revoke_sharing: Whether a local-path/drive: image's temporary anyone:reader share is revoked again after it's embedded (default True). An image file that was already link-shared before the call keeps its link and is reported with already_shared: true. auto_downscale: Resize an oversized local-path/drive: image instead of failing it (default False) — see create_doc's own docstring. allow_no_backup: Replace the content even when Drive refuses the backup copy (below) because the doc's sharing settings don't allow this account to copy it, or the account is at its item-creation limit (default False: the call refuses and leaves the doc unchanged). It has no effect when the account can't edit the doc. folder_id: Optional Google Drive folder ID to upload local-path images into. Defaults to the server's default folder, else the doc's own folder.
Returns: Confirmation with the document ID and web link. Includes "images" (per-image outcomes) when content contained any images. Includes "dropped_links" when a link was written as plain text instead (see create_doc). Includes "warning" if the backup copy (below) couldn't be removed, or if the content was replaced without one. Before clearing a doc that has content, a full copy of it is made in Drive, next to the doc, and deleted again once the new content is in. If the copy fails, nothing is changed and an error is returned, except when Drive refuses it for storage quota, because the account can't add a file to the doc's folder, or because the folder or Shared Drive is at its item limit: the replace then goes ahead without a backup. When sharing settings don't allow copying or the account is at its item-creation limit, it goes ahead without a backup only with allow_no_backup=True. If writing the new content fails, returns {"error", "docId", "backupId", "images", "dropped_links"} instead, with any temporary image share already revoked: the doc may be empty or partly written, and backupId is the kept copy of its previous content. When the replace went ahead without a backup there's no backupId, and the error says the previous content couldn't be backed up: it can't be recovered. The content is converted before any of this, so if it can't be converted, the doc is left unchanged and {"error", "docId"} is returned.
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": {
"doc_id": "<doc_id>",
"content": "<content>"
},
"name": "write_doc_content"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes | ||
| content | Yes | ||
| folder_id | No | ||
| autolink_urls | No | ||
| auto_downscale | No | ||
| content_format | No | html | |
| revoke_sharing | No | ||
| allow_no_backup | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||