Skip to main content
Glama

download_google_doc_images

Extract and save images from Google Docs to a local directory for offline access or content reuse.

Instructions

Download image objects from a Google Doc to a local folder.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
document_id_or_urlYes
output_dirNo
tab_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function decorated with @mcp.tool() that implements the download_google_doc_images tool. It accepts document_id_or_url, output_dir, and tab_id parameters, gets the Google Doc, and delegates to download_doc_images_payload helper function.
    @mcp.tool()
    def download_google_doc_images(
        document_id_or_url: str,
        output_dir: str | None = None,
        tab_id: str | None = None,
    ) -> dict[str, Any]:
        """Download image objects from a Google Doc to a local folder."""
        client = get_client()
        document = client.get_doc(document_id_or_url)
        return download_doc_images_payload(client, document, output_dir=output_dir, tab_id=tab_id)
  • Core helper function that performs the actual image download logic. It extracts inline and positioned image objects from the document, creates an output directory, determines file extensions based on URIs, downloads images, and returns a payload with download metadata.
    def download_doc_images_payload(
        client: GoogleWorkspaceClient,
        document: dict[str, Any],
        *,
        output_dir: str | None,
        tab_id: str | None,
    ) -> dict[str, Any]:
        simplified = simplify_document(document, tab_id=tab_id)
        image_objects = []
        for tab in simplified["tabs"]:
            for image in tab.get("inline_objects", []) + tab.get("positioned_objects", []):
                if image.get("content_uri"):
                    image_objects.append(
                        {
                            "tab_id": tab.get("tab_id"),
                            "tab_title": tab.get("title"),
                            **image,
                        }
                    )
    
        folder = ensure_output_dir(output_dir, "google-doc-images-")
        downloads = []
        for index, image in enumerate(image_objects, start=1):
            extension = ".bin"
            source_uri = image.get("source_uri") or ""
            content_uri = image.get("content_uri") or ""
            for candidate in (source_uri, content_uri):
                lower = candidate.lower()
                if ".png" in lower:
                    extension = ".png"
                    break
                if ".jpg" in lower or ".jpeg" in lower:
                    extension = ".jpg"
                    break
                if ".gif" in lower:
                    extension = ".gif"
                    break
                if ".webp" in lower:
                    extension = ".webp"
                    break
            filename = f"{index:03d}_{safe_filename(image.get('object_id', 'image'))}{extension}"
            file_path = folder / filename
            download_url(client.session, image["content_uri"], file_path, client.timeout)
            downloads.append(
                {
                    "object_id": image.get("object_id"),
                    "tab_id": image.get("tab_id"),
                    "tab_title": image.get("tab_title"),
                    "path": str(file_path),
                    "source_uri": image.get("source_uri"),
                    "alt_text": image.get("alt_text"),
                }
            )
        return {
            "output_dir": str(folder),
            "count": len(downloads),
            "images": downloads,
        }
  • Registration point where download_google_doc_images is imported from the tools module and made available as part of the package's public API.
    from .tools import (
        diagnose_google_auth,
        download_google_doc_images,
        export_google_file,
        get_sheet_row,
        inspect_sheet_images,
        read_google_doc,
        read_sheet_grid,
        read_sheet_values,
        resolve_google_file,
        search_sheet,
        sheet_to_json,
    )
  • Tool name is exported in the __all__ list, making it part of the module's public interface when imported.
    "download_doc_images_payload",
    "download_google_doc_images",
    "download_url",
  • Supporting helper functions: ensure_output_dir creates the output directory (using a temp directory if not specified), and download_url performs the actual HTTP download of image files.
    def ensure_output_dir(output_dir: str | None, default_prefix: str) -> Path:
        if output_dir:
            target = Path(output_dir)
        else:
            target = Path(tempfile.mkdtemp(prefix=default_prefix))
        target.mkdir(parents=True, exist_ok=True)
        return target
    
    
    def download_url(session: requests.Session, url: str, path: Path, timeout: int) -> None:
        response = session.get(url, timeout=timeout)
        response.raise_for_status()
        path.write_bytes(response.content)
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('download') but doesn't cover permissions needed, rate limits, file formats supported, error handling, or whether it overwrites existing files. For a tool that likely involves file system operations and API calls, this leaves significant gaps in understanding its behavior.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core action and resource. It wastes no words and is appropriately sized for the tool's complexity, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which likely covers return values), the description's job is reduced. However, with no annotations, 3 parameters (one undocumented due to 0% schema coverage), and operations involving downloads and file system changes, the description is incomplete. It should address more behavioral aspects like error cases or output specifics beyond what the output schema might provide.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'document_id_or_url' and 'output_dir' implicitly but doesn't explain what 'tab_id' does or provide details on parameter formats (e.g., URL patterns, directory paths). The description adds minimal value beyond the schema's property names, failing to fully address the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('download') and resource ('image objects from a Google Doc'), specifying the destination ('to a local folder'). It distinguishes from siblings like 'read_google_doc' or 'inspect_sheet_images' by focusing on downloading images rather than reading content or inspecting images in sheets. However, it doesn't explicitly differentiate from all siblings, such as 'export_google_file', which might handle similar operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'export_google_file' or 'inspect_sheet_images'. It lacks context on prerequisites (e.g., authentication), exclusions (e.g., not for text extraction), or specific scenarios (e.g., batch image extraction). Usage is implied by the action but not explicitly defined.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/NgoQuocViet2001/google-workspace-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server