Skip to main content
Glama
ai-zerolab

MCP Email Server

by ai-zerolab

get_emails_content

Retrieve the full content and body of one or more emails using their email IDs obtained from list_emails_metadata. Requires account name and mailbox.

Instructions

Get the full content (including body) of one or more emails by their email_id. Use list_emails_metadata first to get the email_id.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_nameYesThe name of the email account.
email_idsYesList of email_id to retrieve (obtained from list_emails_metadata). Can be a single email_id or multiple email_ids.
mailboxNoThe mailbox to retrieve emails from.INBOX

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
emailsYes
requested_countYes
retrieved_countYes
failed_idsYes

Implementation Reference

  • ClassicEmailHandler.get_emails_content - concrete implementation that iterates over email_ids, fetches each email via IMAP, and returns EmailContentBatchResponse.
    async def get_emails_content(self, email_ids: list[str], mailbox: str = "INBOX") -> EmailContentBatchResponse:
        """Batch retrieve email body content"""
        emails = []
        failed_ids = []
    
        for email_id in email_ids:
            try:
                email_data = await self.incoming_client.get_email_body_by_id(email_id, mailbox)
                if email_data:
                    emails.append(
                        EmailBodyResponse(
                            email_id=email_data["email_id"],
                            message_id=email_data.get("message_id"),
                            subject=email_data["subject"],
                            sender=email_data["from"],
                            recipients=email_data["to"],
                            date=email_data["date"],
                            body=email_data["body"],
                            attachments=email_data["attachments"],
                        )
                    )
                else:
                    failed_ids.append(email_id)
            except Exception as e:
                logger.error(f"Failed to retrieve email {email_id}: {e}")
                failed_ids.append(email_id)
    
        return EmailContentBatchResponse(
            emails=emails,
            requested_count=len(email_ids),
            retrieved_count=len(emails),
            failed_ids=failed_ids,
        )
  • MCP tool registration using @mcp.tool decorator. This is the entry point that dispatches to the EmailHandler implementation.
    @mcp.tool(
        description="Get the full content (including body) of one or more emails by their email_id. Use list_emails_metadata first to get the email_id."
    )
    async def get_emails_content(
        account_name: Annotated[str, Field(description="The name of the email account.")],
        email_ids: Annotated[
            list[str],
            Field(
                description="List of email_id to retrieve (obtained from list_emails_metadata). Can be a single email_id or multiple email_ids."
            ),
        ],
        mailbox: Annotated[str, Field(default="INBOX", description="The mailbox to retrieve emails from.")] = "INBOX",
    ) -> EmailContentBatchResponse:
        handler = dispatch_handler(account_name)
        return await handler.get_emails_content(email_ids, mailbox)
  • Pydantic response model for batch email content results.
    class EmailContentBatchResponse(BaseModel):
        """Batch email content response for multiple emails"""
    
        emails: list[EmailBodyResponse]
        requested_count: int
        retrieved_count: int
        failed_ids: list[str]
  • Pydantic model for a single email's body response (extends EmailMetadata with body field).
    class EmailBodyResponse(EmailMetadata):
        """Single email body response - extends EmailMetadata with body content"""
    
        body: str
  • EmailClient.get_email_body_by_id - helper that connects to IMAP, fetches and parses a single email's full content.
    async def get_email_body_by_id(self, email_id: str, mailbox: str = "INBOX") -> dict[str, Any] | None:
        imap = self._imap_connect()
        try:
            # Wait for the connection to be established
            await imap._client_task
            await imap.wait_hello_from_server()
    
            # Login and select inbox
            await imap.login(self.email_server.user_name, self.email_server.password.get_secret_value())
            await _send_imap_id(imap)
            await imap.select(_quote_mailbox(mailbox))
    
            # Fetch the specific email by UID
            data = await self._fetch_email_with_formats(imap, email_id)
            if not data:
                logger.error(f"Failed to fetch UID {email_id} with any format")
                return None
    
            # Extract raw email data
            raw_email = self._extract_raw_email(data)
            if not raw_email:
                logger.error(f"Could not find email data in response for email ID: {email_id}")
                return None
    
            # Parse the email
            try:
                return self._parse_email_data(raw_email, email_id)
            except Exception as e:
                logger.error(f"Error parsing email: {e!s}")
                return None
    
        finally:
            # Ensure we logout properly
            try:
                await imap.logout()
            except Exception as e:
                logger.info(f"Error during logout: {e}")
Behavior3/5

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

With no annotations, description carries full burden. It mentions returning full content including body, but omits details like permissions, rate limits, or whether operation is read-only. Adequate but minimal.

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?

Two concise sentences, front-loaded with key information. No redundant words; every sentence adds value.

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?

Given output schema exists and no annotations, description covers core purpose, prerequisite, and what is retrieved. Could mention ability to retrieve multiple emails but is sufficient for a simple read tool.

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 coverage is 100%, so parameters are well-documented by schema. Description reinforces that email_ids come from list_emails_metadata but adds no extra semantic meaning beyond schema.

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?

Description clearly states the action: get full content of emails by email_id. It distinguishes from sibling list_emails_metadata by noting it as a prerequisite, defining the tool's role in the workflow.

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?

Explicitly instructs to use list_emails_metadata first to obtain email_id, providing clear guidance on when to use this tool. Lacks explicit when-not-to-use but strong prerequisite indication.

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/ai-zerolab/mcp-email-server'

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