Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

get_thread

Retrieve complete email conversations by providing a single message UID. This tool fetches all related messages in a thread from IMAP mailboxes for comprehensive email review.

Instructions

Get email thread/conversation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYesEmail UID (any email in thread)
mailboxNoMailbox name (default: current)

Implementation Reference

  • The actual implementation of the get_thread tool logic in the IMAP client.
    def get_thread(self, uid: int, mailbox: Optional[str] = None) -> list[EmailHeader]:
        """Get email thread/conversation."""
        self._ensure_connected()
        if mailbox:
            self.select_mailbox(mailbox)
    
        # Get the email to find its references
        email_data = self.get_email(uid, mailbox)
        message_id = email_data.header.message_id
        subject = email_data.header.subject
    
        # Search for related emails by subject (simplified thread detection)
        if subject:
            # Remove Re: Fwd: etc. prefixes
            clean_subject = subject
            for prefix in ["Re:", "RE:", "Fwd:", "FWD:", "Fw:", "AW:", "Aw:"]:
                clean_subject = clean_subject.replace(prefix, "").strip()
    
            uids = self.client.search(["SUBJECT", clean_subject])
            if uids:
  • Registration of the get_thread tool in the server configuration.
    make_tool(
        "get_thread",
        "Get email thread/conversation",
        {
            "uid": {"type": "number", "description": "Email UID (any email in thread)"},
            "mailbox": {"type": "string", "description": "Mailbox name (default: current)"},
        },
        ["uid"],
    ),
  • Handling the get_thread tool call by routing it to the imap_client.
    elif name == "get_thread":
        return imap_client.get_thread(
            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