Skip to main content
Glama

gmail_get_email

Retrieve complete email content including subject, sender, recipients, date, labels, and body text using a Gmail message ID.

Instructions

Get the full content of a specific email by its Gmail message ID. Returns subject, sender, recipients, date, labels, and full body text.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
email_idYesThe Gmail message ID obtained from search or list results.

Implementation Reference

  • Input schema definition for the 'gmail_get_email' tool, specifying the required 'email_id' parameter.
    Tool(
        name="gmail_get_email",
        description="Get the full content of a specific email by its ID",
        inputSchema={
            "type": "object",
            "properties": {
                "email_id": {
                    "type": "string",
                    "description": "The Gmail message ID",
                },
            },
            "required": ["email_id"],
        },
    ),
  • The main handler in the MCP server's call_tool function that executes the 'gmail_get_email' tool by retrieving the email via GmailClient and formatting it for response.
    elif name == "gmail_get_email":
        email_id = arguments.get("email_id")
        if not email_id:
            return [TextContent(type="text", text="Error: email_id is required")]
        email = await client.get_email(email_id)
        return [
            TextContent(
                type="text",
                text=_format_full_email(email),
            )
        ]
  • Core implementation in GmailClient that fetches the full email from Gmail API using users.messages.get and parses it into an Email object.
    async def get_email(self, message_id: str) -> Email:
        """Get a single email by ID with full content."""
        try:
            msg = (
                self.service.users()
                .messages()
                .get(userId="me", id=message_id, format="full")
                .execute()
            )
            return self._parse_message(msg, include_body=True)
        except HttpError as e:
            logger.error(f"Failed to get email {message_id}: {e}")
            raise
  • Helper function used by the handler to format the retrieved email into a readable text response.
    def _format_full_email(email) -> str:
        """Format full email for display."""
        categories = f"Categories: {', '.join(email.categories)}" if email.categories else ""
    
        attachments = ""
        if email.attachments:
            att_list = ", ".join(a.filename for a in email.attachments)
            attachments = f"\nAttachments: {att_list}"
    
        body = email.body_text or "(No text content)"
        if len(body) > 2000:
            body = body[:2000] + "\n\n... [truncated]"
    
        return f"""
    **Subject:** {email.subject}
    **From:** {email.sender}
    **To:** {', '.join(str(t) for t in email.to)}
    **Date:** {email.date.strftime('%Y-%m-%d %H:%M:%S')}
    **Labels:** {', '.join(email.labels)}
    {categories}
    {attachments}
    
    ---
    
    {body}
    """
  • Helper function in GmailClient that parses the raw Gmail API message into a structured Email object, including body extraction, categorization, and metadata parsing.
    def _parse_message(self, msg: dict, include_body: bool = False) -> Email:
        """Parse Gmail API message into Email model."""
        payload = msg.get("payload", {})
        headers = payload.get("headers", [])
    
        # Parse date
        date_str = self._get_header(headers, "Date")
        try:
            date = parsedate_to_datetime(date_str)
        except Exception:
            # Fallback to internal date
            internal_date = int(msg.get("internalDate", 0)) / 1000
            date = datetime.fromtimestamp(internal_date, tz=timezone.utc)
    
        # Parse labels
        label_ids = msg.get("labelIds", [])
        is_read = "UNREAD" not in label_ids
        is_starred = "STARRED" in label_ids
        is_important = "IMPORTANT" in label_ids
    
        # Extract body if requested
        text_body, html_body = None, None
        if include_body:
            text_body, html_body = self._extract_body(payload)
    
        # Extract attachments
        attachments = self._extract_attachments(payload)
    
        email = Email(
            id=msg["id"],
            thread_id=msg["threadId"],
            subject=self._get_header(headers, "Subject") or "(No Subject)",
            snippet=msg.get("snippet", ""),
            body_text=text_body,
            body_html=html_body,
            sender=self._parse_email_address(self._get_header(headers, "From")),
            to=self._parse_email_addresses(self._get_header(headers, "To")),
            cc=self._parse_email_addresses(self._get_header(headers, "Cc")),
            reply_to=self._parse_email_address(self._get_header(headers, "Reply-To"))
            if self._get_header(headers, "Reply-To")
            else None,
            date=date,
            labels=label_ids,
            is_read=is_read,
            is_starred=is_starred,
            is_important=is_important,
            attachments=attachments,
            has_attachments=len(attachments) > 0,
        )
    
        # Categorize
        email.categories = self._categorize_email(email)
        email.priority = self._get_priority(email.categories)
    
        return email
Behavior3/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 discloses the tool's read-only nature by stating 'Get' and listing return fields, but it doesn't mention behavioral traits like error handling (e.g., invalid IDs), authentication needs, rate limits, or whether it retrieves attachments. The description adds some context but leaves gaps 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.

Conciseness5/5

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

The description is front-loaded with the core purpose in the first sentence and efficiently lists return fields in the second. Every sentence earns its place by adding critical information without redundancy, making it appropriately sized and easy to parse.

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 and no output schema, the description is moderately complete for a simple read operation. It covers the purpose, parameter semantics, and return fields, but lacks details on error cases, authentication, or behavioral nuances. For a tool with 1 parameter and no complex outputs, it's adequate but has clear gaps in transparency.

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?

The input schema has 1 parameter with 100% coverage, providing a clear description. The description adds value by specifying that the email_id is 'obtained from search or list results,' which clarifies its source beyond the schema's technical definition. This compensates well, though it doesn't detail format constraints beyond what's implied.

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 ('Get the full content'), resource ('a specific email'), and key identifier ('by its Gmail message ID'). It distinguishes from siblings like gmail_search (which finds emails) and gmail_list_unread (which lists emails) by focusing on retrieving detailed content for a single identified message.

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 when you need detailed email content for a known message ID, but it doesn't explicitly state when to use this versus alternatives like gmail_search (which might return summaries) or prerequisites like needing the ID from another tool. It provides basic context but lacks explicit guidance on exclusions or named alternatives.

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/murphy360/mcp_gmail'

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