Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

get_cached_overview

Retrieve cached email summaries from IMAP mailboxes to quickly review inbox, next actions, waiting, and someday messages without fetching full content.

Instructions

Get cached email overview for INBOX, next, waiting, someday (from in-memory cache)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mailboxNoSpecific mailbox to get (inbox, next, waiting, someday) or omit for all
limitNoMax emails per mailbox (default: 20)

Implementation Reference

  • The main logic for retrieving a cached overview of emails from IMAP folders.
    def get_cached_overview(
        self, mailbox: Optional[str] = None, limit: int = 20
    ) -> dict:
        """Get cached email overview for INBOX, next, waiting, someday (from in-memory cache)."""
        import time
    
        # If watcher is running, use its cache
        if self.watcher and self.watcher.running:
            # Wait briefly for cache to populate if empty
            for _ in range(10):
                cache = self.watcher.get_cache(mailbox)
                if cache:
                    return cache
                time.sleep(0.5)
            return self.watcher.get_cache(mailbox)
    
        # Fallback to manual fetch if watcher not running
        folders = self.config.get("folders", {})
        mailboxes = {
            "inbox": folders.get("inbox", "INBOX"),
            "next": folders.get("next", "next"),
            "waiting": folders.get("waiting", "waiting"),
            "someday": folders.get("someday", "someday"),
        }
    
        if mailbox:
            if mailbox not in mailboxes:
                return {}
            mailboxes = {mailbox: mailboxes[mailbox]}
    
        result = {}
        for key, folder in mailboxes.items():
            cache_key = f"overview_{folder}"
            if cache_key in self.cache:
                ttl = self.config.get("cache", {}).get("ttl_seconds", 300)
                cache_time = self.cache_timestamps.get(cache_key, datetime.min)
                if (datetime.now() - cache_time).total_seconds() < ttl:
                    result[key] = self.cache[cache_key]
                    continue
    
            try:
                emails = self.fetch_emails(folder, limit=limit)
                status = self.get_mailbox_status(folder)
                overview = {
                    "emails": [
                        {
                            "uid": e.uid,
                            "sender": e.from_address.email if e.from_address else "",
                            "sender_name": e.from_address.name if e.from_address else None,
                            "subject": e.subject,
                            "date": e.date.isoformat() if e.date else None,
                            "unread": "\\Seen" not in e.flags,
                        }
                        for e in emails
                    ],
                    "total": status.exists,
                    "unread": status.unseen,
                    "last_updated": datetime.now().isoformat(),
                }
                self.cache[cache_key] = overview
                self.cache_timestamps[cache_key] = datetime.now()
                result[key] = overview
            except Exception as e:
                result[key] = {"error": str(e)}
    
        return result
  • Tool registration logic for "get_cached_overview" within the MCP server handler.
    elif name == "get_cached_overview":
        return imap_client.get_cached_overview(
            mailbox=args.get("mailbox"),
            limit=args.get("limit", 20),
        )
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the data source ('in-memory cache'), which is useful context, but doesn't describe what 'overview' includes (e.g., summary counts, metadata), cache staleness, performance implications, or error behavior. For a read operation with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the key information ('Get cached email overview') and specifies the scope. Every word earns its place, with no redundant or vague phrasing, making it easy to parse quickly.

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

Completeness3/5

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

Given the tool has 2 parameters with full schema coverage and no output schema, the description is minimally complete for a read operation. It clarifies the cache aspect but lacks details on output format, error handling, or cache behavior. With no annotations to supplement, this leaves the agent with incomplete context for reliable use, though the core purpose is clear.

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 fully documents both parameters (mailbox with enum values and limit with default). The description adds no additional parameter semantics beyond implying the tool can handle multiple mailboxes ('or omit for all' is in the schema). Baseline 3 is appropriate as the schema does the heavy lifting, but the description doesn't enhance parameter understanding.

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

Purpose4/5

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

The description clearly states the action ('Get cached email overview') and specifies the target resources (INBOX, next, waiting, someday) with the source (in-memory cache). It distinguishes from siblings by focusing on cached overview rather than raw email data or operations like search_emails or get_email. However, it doesn't explicitly differentiate from get_mailbox_status or get_total_count, which might provide related but different information.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer this cached overview over fetching emails directly (e.g., fetch_emails), when cache freshness matters, or how it relates to siblings like get_mailbox_status or get_total_count. The agent must infer usage from the name and description alone.

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