Skip to main content
Glama
taylorwilsdon

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

get_gmail_thread_content

Retrieve and format the full content of a Gmail conversation thread, including all messages, by specifying the thread ID and user email.

Instructions

Retrieves the complete content of a Gmail conversation thread, including all messages.

Args:
    thread_id (str): The unique ID of the Gmail thread to retrieve.
    user_google_email (str): The user's Google email address. Required.

Returns:
    str: The complete thread content with all messages formatted for reading.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serviceYes
thread_idYes
user_google_emailYes

Implementation Reference

  • The main handler function for the 'get_gmail_thread_content' tool. It fetches the full thread using Gmail API threads().get() and formats the output using a helper function.
    @server.tool()
    @require_google_service("gmail", "gmail_read")
    @handle_http_errors("get_gmail_thread_content", is_read_only=True, service_type="gmail")
    async def get_gmail_thread_content(
        service, thread_id: str, user_google_email: str
    ) -> str:
        """
        Retrieves the complete content of a Gmail conversation thread, including all messages.
    
        Args:
            thread_id (str): The unique ID of the Gmail thread to retrieve.
            user_google_email (str): The user's Google email address. Required.
    
        Returns:
            str: The complete thread content with all messages formatted for reading.
        """
        logger.info(
            f"[get_gmail_thread_content] Invoked. Thread ID: '{thread_id}', Email: '{user_google_email}'"
        )
    
        # Fetch the complete thread with all messages
        thread_response = await asyncio.to_thread(
            service.users().threads().get(userId="me", id=thread_id, format="full").execute
        )
    
        return _format_thread_content(thread_response, thread_id)
  • Supporting helper function that formats the raw thread data into a human-readable string, extracting subjects, senders, dates, and message bodies (text/HTML) for each message in the thread.
    def _format_thread_content(thread_data: dict, thread_id: str) -> str:
        """
        Helper function to format thread content from Gmail API response.
    
        Args:
            thread_data (dict): Thread data from Gmail API
            thread_id (str): Thread ID for display
    
        Returns:
            str: Formatted thread content
        """
        messages = thread_data.get("messages", [])
        if not messages:
            return f"No messages found in thread '{thread_id}'."
    
        # Extract thread subject from the first message
        first_message = messages[0]
        first_headers = {
            h["name"]: h["value"]
            for h in first_message.get("payload", {}).get("headers", [])
        }
        thread_subject = first_headers.get("Subject", "(no subject)")
    
        # Build the thread content
        content_lines = [
            f"Thread ID: {thread_id}",
            f"Subject: {thread_subject}",
            f"Messages: {len(messages)}",
            "",
        ]
    
        # Process each message in the thread
        for i, message in enumerate(messages, 1):
            # Extract headers
            headers = {
                h["name"]: h["value"] for h in message.get("payload", {}).get("headers", [])
            }
    
            sender = headers.get("From", "(unknown sender)")
            date = headers.get("Date", "(unknown date)")
            subject = headers.get("Subject", "(no subject)")
    
            # Extract both text and HTML bodies
            payload = message.get("payload", {})
            bodies = _extract_message_bodies(payload)
            text_body = bodies.get("text", "")
            html_body = bodies.get("html", "")
    
            # Format body content with HTML fallback
            body_data = _format_body_content(text_body, html_body)
    
            # Add message to content
            content_lines.extend(
                [
                    f"=== Message {i} ===",
                    f"From: {sender}",
                    f"Date: {date}",
                ]
            )
    
            # Only show subject if it's different from thread subject
            if subject != thread_subject:
                content_lines.append(f"Subject: {subject}")
    
            content_lines.extend(
                [
                    "",
                    body_data,
                    "",
                ]
            )
    
        return "\n".join(content_lines)
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It describes the retrieval action and output format but lacks behavioral details such as authentication requirements (implied by user_google_email but not stated), rate limits, error conditions, or whether this is a read-only operation. The description doesn't contradict annotations (none provided), but it's insufficient for a tool with no annotation coverage.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded with the core purpose in the first sentence. The Args and Returns sections are structured but include some redundancy (e.g., 'Required' is implied by the schema). It could be more concise by integrating parameter details more seamlessly.

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 no annotations, 0% schema coverage, and no output schema, the description provides basic purpose and parameter semantics but lacks behavioral transparency and full parameter coverage. It's minimally viable for a retrieval tool but incomplete due to missing details on the 'service' parameter and behavioral aspects like authentication or error handling.

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 meaning by explaining thread_id ('unique ID of the Gmail thread to retrieve') and user_google_email ('user's Google email address. Required.'), but it omits the 'service' parameter entirely. This partially compensates for the coverage gap but leaves one parameter undocumented.

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 specific action ('retrieves the complete content'), resource ('Gmail conversation thread'), and scope ('including all messages'). It distinguishes from sibling tools like get_gmail_message_content (single message) and get_gmail_messages_content_batch (batch of messages) by specifying it retrieves an entire thread.

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

Usage Guidelines3/5

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

The description implies usage by specifying it retrieves 'complete content of a Gmail conversation thread,' which suggests when you need all messages in a thread rather than individual messages. However, it doesn't explicitly state when to use this tool versus alternatives like get_gmail_message_content or get_gmail_messages_content_batch, nor does it mention prerequisites or exclusions.

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