Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

get_email_headers

Extract email headers quickly to preview sender, subject, and date information without downloading full message content.

Instructions

Get only email headers (faster)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYesEmail UID
mailboxNoMailbox name (default: current)

Implementation Reference

  • The core implementation of get_email_headers which fetches and parses email headers using the IMAP client.
    def get_email_headers(self, uid: int, mailbox: Optional[str] = None) -> EmailHeader:
        """Get only email headers (faster)."""
        self._ensure_connected()
        if mailbox:
            self.select_mailbox(mailbox)
    
        data = self.client.fetch([uid], ["ENVELOPE", "FLAGS", "RFC822.SIZE"])
        if uid not in data:
            raise ValueError(f"Email with UID {uid} not found")
    
        return self._parse_email_header(uid, data[uid])
  • Tool definition and registration for 'get_email_headers' within the MCP server.
    make_tool(
        "get_email_headers",
        "Get only email headers (faster)",
        {
            "uid": {"type": "number", "description": "Email UID"},
            "mailbox": {"type": "string", "description": "Mailbox name (default: current)"},
        },
        ["uid"],
    ),
  • The MCP server call handler that routes the 'get_email_headers' tool request to the IMAP client method.
    elif name == "get_email_headers":
        return imap_client.get_email_headers(
            uid=args["uid"],
            mailbox=args.get("mailbox"),
        )

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/Soundhannes/IMAP-MCP'

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