Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

search_unread

Retrieve unread emails from an IMAP account to manage inbox priorities and track pending messages. Specify mailbox and limit parameters to filter results.

Instructions

Get all unread emails

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mailboxNoMailbox name (default: current)
limitNoMax results (default: 50)

Implementation Reference

  • The `search_unread` method in the `IMAPClient` class implements the logic to search for unread emails by selecting the mailbox and searching for the 'UNSEEN' flag.
    def search_unread(
        self, mailbox: Optional[str] = None, limit: int = 50
    ) -> list[EmailHeader]:
        """Get all unread emails."""
        self._ensure_connected()
        if mailbox:
            self.select_mailbox(mailbox)
        elif not self.current_mailbox:
            self.select_mailbox("INBOX")
    
        uids = self.client.search(["UNSEEN"])
        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 `search_unread` tool is registered and called in `src/imap_mcp/server.py` within the tool handler dispatch logic.
    elif name == "search_unread":
        return imap_client.search_unread(

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