Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

search_by_sender

Find emails from specific senders in your IMAP account. Specify sender address, mailbox, and result limit to locate relevant messages quickly.

Instructions

Search emails by sender address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
senderYesSender email address or name
mailboxNoMailbox name (default: current)
limitNoMax results (default: 50)

Implementation Reference

  • The actual implementation of the tool logic that interacts with the IMAP client.
    def search_by_sender(
        self, sender: str, mailbox: Optional[str] = None, limit: int = 50
    ) -> list[EmailHeader]:
        """Search emails by sender address."""
        self._ensure_connected()
        if mailbox:
            self.select_mailbox(mailbox)
        elif not self.current_mailbox:
            self.select_mailbox("INBOX")
    
        uids = self.client.search(["FROM", sender])
        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()]
  • The MCP tool registration and schema definition for search_by_sender.
    make_tool(
        "search_by_sender",
        "Search emails by sender address",
        {
            "sender": {"type": "string", "description": "Sender email address or name"},
            "mailbox": {"type": "string", "description": "Mailbox name (default: current)"},
            "limit": {"type": "number", "description": "Max results (default: 50)"},
        },
        ["sender"],
    ),
  • The MCP tool handler in server.py that routes the tool call to the client implementation.
    elif name == "search_by_sender":
        return imap_client.search_by_sender(
            sender=args["sender"],
            mailbox=args.get("mailbox"),
            limit=args.get("limit", 50),
        )

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