Skip to main content
Glama
taylorwilsdon

Google Workspace MCP Server - Control Gmail, Calendar, Docs, Sheets, Slides, Chat, Forms & Drive

get_drive_file_content

Retrieve and convert content from any Google Drive file by ID, including native Google Docs, Office files, and other formats, into plain text with metadata. Supports shared drives and handles decoding for readable output.

Instructions

Retrieves the content of a specific Google Drive file by ID, supporting files in shared drives.

• Native Google Docs, Sheets, Slides → exported as text / CSV.
• Office files (.docx, .xlsx, .pptx) → unzipped & parsed with std-lib to
  extract readable text.
• Any other file → downloaded; tries UTF-8 decode, else notes binary.

Args:
    user_google_email: The user’s Google email address.
    file_id: Drive file ID.

Returns:
    str: The file content as plain text with metadata header.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_idYes
serviceYes
user_google_emailYes

Implementation Reference

  • The core handler function implementing the 'get_drive_file_content' MCP tool. It downloads Google Drive file content (handling exports for Google formats, Office XML parsing, and binary fallback), formats with metadata, and returns as text. Registered via @server.tool() decorator.
    @server.tool()
    @handle_http_errors("get_drive_file_content", is_read_only=True, service_type="drive")
    @require_google_service("drive", "drive_read")
    async def get_drive_file_content(
        service,
        user_google_email: str,
        file_id: str,
    ) -> str:
        """
        Retrieves the content of a specific Google Drive file by ID, supporting files in shared drives.
    
        • Native Google Docs, Sheets, Slides → exported as text / CSV.
        • Office files (.docx, .xlsx, .pptx) → unzipped & parsed with std-lib to
          extract readable text.
        • Any other file → downloaded; tries UTF-8 decode, else notes binary.
    
        Args:
            user_google_email: The user’s Google email address.
            file_id: Drive file ID.
    
        Returns:
            str: The file content as plain text with metadata header.
        """
        logger.info(f"[get_drive_file_content] Invoked. File ID: '{file_id}'")
    
        resolved_file_id, file_metadata = await resolve_drive_item(
            service,
            file_id,
            extra_fields="name, webViewLink",
        )
        file_id = resolved_file_id
        mime_type = file_metadata.get("mimeType", "")
        file_name = file_metadata.get("name", "Unknown File")
        export_mime_type = {
            "application/vnd.google-apps.document": "text/plain",
            "application/vnd.google-apps.spreadsheet": "text/csv",
            "application/vnd.google-apps.presentation": "text/plain",
        }.get(mime_type)
    
        request_obj = (
            service.files().export_media(fileId=file_id, mimeType=export_mime_type)
            if export_mime_type
            else service.files().get_media(fileId=file_id)
        )
        fh = io.BytesIO()
        downloader = MediaIoBaseDownload(fh, request_obj)
        loop = asyncio.get_event_loop()
        done = False
        while not done:
            status, done = await loop.run_in_executor(None, downloader.next_chunk)
    
        file_content_bytes = fh.getvalue()
    
        # Attempt Office XML extraction only for actual Office XML files
        office_mime_types = {
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "application/vnd.openxmlformats-officedocument.presentationml.presentation",
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        }
    
        if mime_type in office_mime_types:
            office_text = extract_office_xml_text(file_content_bytes, mime_type)
            if office_text:
                body_text = office_text
            else:
                # Fallback: try UTF-8; otherwise flag binary
                try:
                    body_text = file_content_bytes.decode("utf-8")
                except UnicodeDecodeError:
                    body_text = (
                        f"[Binary or unsupported text encoding for mimeType '{mime_type}' - "
                        f"{len(file_content_bytes)} bytes]"
                    )
        else:
            # For non-Office files (including Google native files), try UTF-8 decode directly
            try:
                body_text = file_content_bytes.decode("utf-8")
            except UnicodeDecodeError:
                body_text = (
                    f"[Binary or unsupported text encoding for mimeType '{mime_type}' - "
                    f"{len(file_content_bytes)} bytes]"
                )
    
        # Assemble response
        header = (
            f'File: "{file_name}" (ID: {file_id}, Type: {mime_type})\n'
            f'Link: {file_metadata.get("webViewLink", "#")}\n\n--- CONTENT ---\n'
        )
        return header + body_text
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by detailing behavioral traits: it explains how different file types are processed (native Google files exported as text/CSV, Office files parsed, others downloaded with UTF-8 decode attempt), and mentions the return format includes a metadata header. It doesn't cover authentication needs or rate limits, but provides substantial behavioral context.

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 efficiently structured with a clear opening sentence, bullet points for file type handling, and separate sections for Args and Returns. Every sentence adds value with no wasted words, making it easy to parse.

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

Completeness4/5

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

For a tool with 3 parameters, no annotations, and no output schema, the description provides substantial context about behavior, file type handling, and return format. It doesn't explain the 'service' parameter or provide detailed error handling, but covers the core functionality comprehensively given the complexity.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates well by explaining the purpose of file_id and user_google_email parameters. It doesn't mention the 'service' parameter, but provides meaningful context for 2 of the 3 parameters, which is substantial value given the complete lack of schema documentation.

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

Purpose5/5

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

The description clearly states the verb 'retrieves' and resource 'content of a specific Google Drive file by ID', specifying it supports files in shared drives. It distinguishes from siblings like get_doc_content by mentioning broader file type support beyond just Google Docs.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool - for retrieving content from various Google Drive file types. It doesn't explicitly state when NOT to use it or name alternatives, but the context is sufficiently clear for an agent to understand its purpose relative to siblings like get_doc_content.

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

Related 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/taylorwilsdon/google_workspace_mcp'

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