Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

search_by_subject

Find emails by subject text to locate specific messages in your IMAP mailbox. Specify subject, mailbox, and result limit for targeted email searches.

Instructions

Search emails by subject

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subjectYesSubject text to search
mailboxNoMailbox name (default: current)
limitNoMax results (default: 50)

Implementation Reference

  • Implementation of the `search_by_subject` tool which connects to IMAP, selects the mailbox, performs a search by subject, and returns a list of EmailHeader objects.
    def search_by_subject(
        self, subject: str, mailbox: Optional[str] = None, limit: int = 50
    ) -> list[EmailHeader]:
        """Search emails by subject."""
        self._ensure_connected()
        if mailbox:
            self.select_mailbox(mailbox)
        elif not self.current_mailbox:
            self.select_mailbox("INBOX")
    
        uids = self.client.search(["SUBJECT", subject])
        uids = sorted(uids, reverse=True)[:limit]
        if not uids:
            return []
    
        messages = self.client.fetch(uids, ["ENVELOPE", "FLAGS", "RFC822.SIZE"])
        return [self._parse_email_header(uid, data) for uid, data in messages.items()]
  • Registration and invocation logic for `search_by_subject` in the MCP server handler.
    elif name == "search_by_subject":
        return imap_client.search_by_subject(

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