Skip to main content
Glama

export_google_file

Export Google Workspace files to PDF, XLSX, HTML, Markdown, or plain text formats for offline use or sharing.

Instructions

Export a Google Workspace file to PDF, XLSX, HTML zip, Markdown, or plain text.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_id_or_urlYes
mime_typeYes
output_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for 'export_google_file' tool. Decorated with @mcp.tool() for automatic registration. Accepts file_id_or_url, mime_type, and optional output_path parameters. Exports Google Workspace files to PDF, XLSX, HTML zip, Markdown, or plain text formats by calling client.export_drive_file() and saving the content to disk.
    @mcp.tool()
    def export_google_file(
        file_id_or_url: str,
        mime_type: str,
        output_path: str | None = None,
    ) -> dict[str, Any]:
        """Export a Google Workspace file to PDF, XLSX, HTML zip, Markdown, or plain text."""
        client = get_client()
        metadata, content = client.export_drive_file(file_id_or_url, mime_type)
        if output_path:
            destination = Path(output_path)
            destination.parent.mkdir(parents=True, exist_ok=True)
        else:
            folder = client.export_root
            folder.mkdir(parents=True, exist_ok=True)
            extension = {
                "application/pdf": ".pdf",
                "application/zip": ".zip",
                "text/markdown": ".md",
                "text/plain": ".txt",
                XLSX_MIME: ".xlsx",
            }.get(mime_type, ".bin")
            destination = folder / f"{safe_filename(metadata.get('name', metadata.get('id', 'export')))}{extension}"
        destination.write_bytes(content)
        return {
            "file_id": metadata.get("id"),
            "name": metadata.get("name"),
            "mime_type": mime_type,
            "output_path": str(destination),
            "bytes": len(content),
        }
  • Helper method export_drive_file() that performs the actual Google Drive API call. Extracts the file ID, retrieves metadata, and makes a GET request to the Drive export endpoint with the specified MIME type. Returns a tuple of (metadata, content_bytes).
    def export_drive_file(self, file_id_or_url: str, mime_type: str) -> tuple[dict[str, Any], bytes]:
        file_id = extract_file_id(file_id_or_url)
        metadata = self.get_drive_file(file_id)
        content = self._request(
            "GET",
            f"https://www.googleapis.com/drive/v3/files/{file_id}/export",
            scopes=[DRIVE_SCOPE],
            params={"mimeType": mime_type},
            expect_json=False,
        )
        return metadata, content
  • Helper function extract_file_id() that parses Google file IDs from various URL formats (docs, sheets, drive URLs) or validates standalone IDs. Used by export_drive_file to extract the file identifier from user-provided URLs.
    def extract_file_id(value: str, kind: str | None = None) -> str:
        value = value.strip()
        if kind == "doc":
            match = DOC_URL_RE.search(value)
            if match:
                return match.group(1)
        elif kind == "sheet":
            match = SHEET_URL_RE.search(value)
            if match:
                return match.group(1)
        else:
            for pattern in (DOC_URL_RE, SHEET_URL_RE, DRIVE_FILE_RE):
                match = pattern.search(value)
                if match:
                    return match.group(1)
            match = DRIVE_OPEN_RE.search(value)
            if match:
                return match.group(1)
    
        if ID_RE.match(value):
            return value
        raise ValueError(f"Could not extract a Google file ID from: {value}")
  • Helper function safe_filename() that sanitizes filenames by replacing non-alphanumeric characters (except ._-) with underscores. Used to create safe output filenames when exporting Google files.
    def safe_filename(name: str) -> str:
        return re.sub(r"[^A-Za-z0-9._-]+", "_", name).strip("._") or "file"
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 implies a mutation (exporting changes format) but doesn't clarify if it modifies the original file, requires specific permissions, has rate limits, or what the output entails (e.g., file creation, download link). The description lacks details on error handling, performance, or side effects, leaving significant gaps for a tool with potential write operations.

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 purpose without unnecessary words. It lists export formats clearly and avoids redundancy. Every part earns its place by specifying the action, resource, and target formats concisely.

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 3 parameters with 0% schema coverage, no annotations, and an output schema present, the description is moderately complete. It covers the basic purpose and formats but lacks details on usage, behavior, and parameter meanings. The output schema likely handles return values, reducing the need for output explanation, but the description doesn't fully address the tool's complexity and mutation aspects.

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

Parameters3/5

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

Schema description coverage is 0%, so the schema provides no parameter details. The description adds minimal semantics by implying 'mime_type' relates to export formats (PDF, XLSX, etc.) and 'file_id_or_url' identifies the source, but doesn't explain parameter roles, formats, or constraints (e.g., valid MIME types, URL patterns). It partially compensates for the coverage gap but leaves parameters largely undocumented.

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 ('Export') and resource ('Google Workspace file'), specifying the target formats (PDF, XLSX, HTML zip, Markdown, plain text). It distinguishes from siblings like 'read_google_doc' or 'download_google_doc_images' by focusing on format conversion rather than reading or downloading images. However, it doesn't explicitly differentiate from all siblings (e.g., 'sheet_to_json' also exports data).

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., file accessibility, authentication), compare to siblings like 'read_google_doc' for viewing or 'sheet_to_json' for JSON export, or specify use cases (e.g., for archival, sharing in non-Google formats). The description only states what it does, not when it's appropriate.

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