insert_local_images
Upload local image files to Drive and replace plain-text markers in a Google Doc with those images in one call. Use this to insert multiple local images without manual upload, find, insert, and delete steps.
Instructions
Upload local image files to Drive and swap each into a Google Doc at a plain-text marker, in one call. Not available when the server runs with LOCAL_FILE_ACCESS=off.
Typical flow: write doc content with a unique plain-text placeholder per image (e.g. "IMGMARKERONE") via create_doc/write_doc_content/insert_doc_text, then call this tool once with the marker → local file mapping. Collapses the N manual upload/find/insert/delete round trips a multi-image doc would otherwise need into a single call.
For each image: uploads the local file to Drive, shares it as anyone-with-link/reader (required — the Docs backend fetches inline images as an anonymous HTTP request, so a private file fails with "There was a problem retrieving the image"; confirmed live 2026-07-18), locates its marker's current position, inserts the image immediately before the marker text, then deletes the marker text. Once the image is actually embedded, that temporary share is revoked again by default (revoke_sharing=True) — revoking any earlier would break the embed, since Docs fetches the image at insertion time, not upload time. The revoke also runs if the document edit fails or the call is cancelled; a cancelled call returns nothing, so the uploaded file IDs are logged as a warning instead.
All markers are located in a single pass over the document's current text before any edits are applied — markers are matched longest-first at each position, so one marker that's a substring of another (e.g. "IMG1" vs "IMG10") can't produce a false match or a false "occurs twice" collision. Uploads and shares run in parallel; the document edit is one batchUpdate applied highest-index-first so replacing one marker never invalidates another marker's already-computed position — same convention as insert_doc_text/delete_doc_range. Uploading and sharing happen before any document edit, so a failed upload never leaves the doc partially edited.
Args: doc_id: The Google Doc file ID. images: List of image dicts, each with: marker (str): exact literal text already present in the doc body, marking where this image goes. Matched as a whole token — not immediately preceded or followed by another letter, digit, or underscore — so a marker like "IMG1" can't falsely match inside unrelated text like "IMG10". Must occur exactly once in the document (searched case-sensitively) — an ambiguous or missing marker fails just that image, not the whole call. local_path: absolute path to the local image file. width, height (float, optional): image size in points. folder_id: Drive folder to upload images into. Defaults to the server's configured default folder. revoke_sharing: Whether each image's temporary anyone:reader share is revoked again after it's embedded (default True). Set False to leave images shared instead — matches this tool's original behavior. A file that was already link-shared before the call (e.g. inherited from its folder) keeps its link and is reported with already_shared: true. auto_downscale: Google Docs rejects any inline image over ~25 megapixels or ~50MB. Each image's local file is checked against both limits before it's ever uploaded. The default (False) fails just that image with a clear error naming the limit and its actual size — other images in the same call are unaffected. Set True to instead resize an oversized image and upload the resized copy (the local file on disk is never modified); that outcome's entry gets downscaled: true.
Returns:
Dictionary with docId and results — a list of per-image outcomes in the
same order as the images argument, each echoing marker and local_path
plus either fileId + index + shared (+ revoke_error if a revoke attempt
failed, + downscaled: true if auto_downscale resized it, +
already_shared: true if the file was link-shared before this call) on
success, or
error on failure (marker not found, marker not unique, local file
missing, oversized with auto_downscale off, upload failure, sharing
failure, or — rare, since uploads happen first — a failed document edit;
that last case keeps fileId and shared, with no index, since the upload
and share happened even though the image was never placed). A sharing
failure after the underlying Drive file was already created also carries
fileId (#649) — the upload itself succeeded even though the share didn't.
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>",
"images": "<images>"
},
"name": "insert_local_images"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes | ||
| images | Yes | ||
| folder_id | No | ||
| auto_downscale | No | ||
| revoke_sharing | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||