Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

search_flagged

Retrieve flagged or starred emails from an IMAP account to quickly access important messages. Specify mailbox and limit results as needed.

Instructions

Get all flagged/starred emails

Input Schema

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

Implementation Reference

  • Implementation of the search_flagged tool, which selects a mailbox, searches for FLAGGED emails, and returns them as a list of headers.
    def search_flagged(
        self, mailbox: Optional[str] = None, limit: int = 50
    ) -> list[EmailHeader]:
        """Get all flagged/starred emails."""
        self._ensure_connected()
        if mailbox:
            self.select_mailbox(mailbox)
        elif not self.current_mailbox:
            self.select_mailbox("INBOX")
    
        uids = self.client.search(["FLAGGED"])
        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()]
  • Tool definition for search_flagged in the MCP server tool list.
    make_tool(
        "search_flagged",
        "Get all flagged/starred emails",
        {
            "mailbox": {"type": "string", "description": "Mailbox name (default: current)"},
            "limit": {"type": "number", "description": "Max results (default: 50)"},
        },
    ),
  • Handler logic for search_flagged within the server's call_tool function.
    elif name == "search_flagged":
        return imap_client.search_flagged(
            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