Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

search_emails

Find specific emails in IMAP mailboxes using search queries to locate messages based on content, sender, date, or other criteria.

Instructions

Search emails with query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query (IMAP SEARCH syntax or text)
mailboxNoMailbox name (default: current)
limitNoMax results (default: 50)

Implementation Reference

  • The actual implementation of the search_emails functionality in the IMAP client class.
    def search_emails(
        self, query: str, mailbox: Optional[str] = None, limit: int = 50
    ) -> list[EmailHeader]:
        """Search emails with query (IMAP SEARCH syntax or text)."""
        self._ensure_connected()
        if mailbox:
            self.select_mailbox(mailbox)
        elif not self.current_mailbox:
            self.select_mailbox("INBOX")
    
        # Try to parse as IMAP search criteria, fallback to TEXT search
        try:
            if any(kw in query.upper() for kw in ["FROM", "TO", "SUBJECT", "BODY", "ALL", "UNSEEN"]):
                uids = self.client.search(query.split())
            else:
                uids = self.client.search(["TEXT", query])
        except Exception:
            uids = self.client.search(["TEXT", query])
    
        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 of the search_emails tool within the MCP server definition.
    make_tool(
        "search_emails",
        "Search emails with query",
        {
            "query": {"type": "string", "description": "Search query (IMAP SEARCH syntax or text)"},
            "mailbox": {"type": "string", "description": "Mailbox name (default: current)"},
            "limit": {"type": "number", "description": "Max results (default: 50)"},
        },
        ["query"],
    ),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It only states the action without disclosing behavioral traits like whether this is a read-only operation, what permissions are needed, how results are returned (e.g., pagination, format), or any rate limits. For a search tool with no annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at four words, with no wasted text. However, it's arguably too brief given the complexity of the tool and lack of sibling differentiation, bordering on under-specification rather than optimal conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 3 parameters, no annotations, no output schema, and many sibling alternatives, the description is incomplete. It doesn't explain what the tool returns, how to interpret results, or when to choose it over other search tools. This leaves significant gaps for an agent to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all three parameters (query, mailbox, limit) with their types and default values. The description adds no additional meaning beyond implying a search action, which is already clear from the tool name. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Search emails with query' states the basic action (search) and resource (emails), but it's vague about scope and doesn't distinguish from many sibling search tools like search_by_date, search_by_sender, search_by_subject, search_flagged, or search_unread. It mentions 'query' but doesn't clarify what kind of search this performs compared to the specialized siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus the many sibling search alternatives. The description doesn't mention any prerequisites, context, or exclusions, leaving the agent to guess based on tool names alone. This is a significant gap given the server has multiple specialized search tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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