Skip to main content
Glama
Soundhannes

IMAP MCP Server

by Soundhannes

process_auto_archive

Automatically archive emails from specified senders in your INBOX. Use dry_run to preview changes before applying them.

Instructions

Process INBOX and archive emails from listed senders. Use dry_run=true to preview without moving.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dry_runNoIf true, only report what would be archived without moving (default: false)

Implementation Reference

  • The actual implementation of the auto-archive logic in the IMAP client.
    def process_auto_archive(self, dry_run: bool = False) -> dict:
        """Process INBOX and archive emails from listed senders.
    
        Args:
            dry_run: If True, only report what would be archived without moving.
    
        Returns:
            dict with 'archived_count', 'archived_emails', and 'errors'.
        """
        self._ensure_connected()
    
        if not self.auto_archive_senders:
            return {"archived_count": 0, "archived_emails": [], "errors": [], "dry_run": dry_run, "message": "No senders in auto-archive list"}
    
        # Build set of sender emails/domains for fast lookup
        sender_patterns = set()
        for s in self.auto_archive_senders:
            sender_patterns.add(s.email.lower())
    
        # Get archive folder from config
        folders = self.config.get("folders", {})
        archive_folder = folders.get("archive", "Archive")
        inbox_folder = folders.get("inbox", "INBOX")
    
        # Select INBOX
        self.client.select_folder(inbox_folder)
    
        # Search all emails
        uids = self.client.search(["ALL"])
        if not uids:
            return {"archived_count": 0, "archived_emails": [], "errors": [], "dry_run": dry_run, "message": "INBOX is empty"}
    
        # Fetch envelopes to check senders
        messages = self.client.fetch(uids, ["ENVELOPE"])
    
        to_archive = []
        archived_emails = []
        errors = []
    
        for uid, data in messages.items():
            envelope = data.get(b"ENVELOPE")
            if not envelope or not envelope.from_:
                continue
    
            # Get sender email
            f = envelope.from_[0]
            mailbox = f.mailbox.decode() if f.mailbox else ""
            host = f.host.decode() if f.host else ""
            sender_email = f"{mailbox}@{host}".lower()
            sender_domain = f"@{host}".lower()
    
            # Check if sender matches
            if sender_email in sender_patterns or sender_domain in sender_patterns:
                subject = ""
                if envelope.subject:
                    try:
                        subject = envelope.subject.decode("utf-8", errors="replace")
                    except Exception:
                        subject = str(envelope.subject)
    
                to_archive.append(uid)
                archived_emails.append({
                    "uid": uid,
                    "sender": sender_email,
                    "subject": subject[:100],
                })
    
        # Move emails if not dry run
        if to_archive and not dry_run:
            try:
                self.client.move(to_archive, archive_folder)
            except Exception as e:
                errors.append(f"Failed to move emails: {str(e)}")
    
        return {
            "archived_count": len(to_archive),
            "archived_emails": archived_emails,
            "errors": errors,
            "dry_run": dry_run,
            "message": f"{'Would archive' if dry_run else 'Archived'} {len(to_archive)} emails",
        }
  • The registration of the 'process_auto_archive' tool in the MCP server's call handler.
    elif name == "process_auto_archive":
        return imap_client.process_auto_archive(
            dry_run=args.get("dry_run", False),
        )
Behavior3/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. It discloses key behavioral traits: the tool archives emails automatically based on a sender list, and the dry_run option allows previewing. However, it lacks details on permissions needed, rate limits, error handling, or what 'listed senders' refers to (likely from 'get_auto_archive_list').

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 two sentences with zero waste: the first states the core purpose, and the second provides crucial usage guidance for the parameter. It is front-loaded with the main action and efficiently covers essential information without redundancy.

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

Completeness4/5

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

Given no annotations and no output schema, the description is reasonably complete for a tool with one parameter. It covers purpose, usage, and parameter behavior. However, it could improve by mentioning dependencies (e.g., sender list from 'get_auto_archive_list') or output format, but the simplicity of the tool makes it mostly adequate.

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

Parameters4/5

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

The input schema has 100% description coverage, so the baseline is 3. The description adds value by explaining the practical use of the 'dry_run' parameter ('to preview without moving'), which enhances understanding beyond the schema's technical definition. With only one parameter, this extra context is sufficient for a higher score.

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

Purpose5/5

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

The description clearly states the tool's purpose with a specific verb ('process'), resource ('INBOX'), and action ('archive emails from listed senders'). It distinguishes from siblings like 'archive_email' (manual archiving) and 'get_auto_archive_list' (listing senders) by emphasizing automated processing based on a predefined sender list.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance: it specifies when to use the tool (to process and archive emails from listed senders) and when to use the dry_run parameter (to preview without moving). It implicitly distinguishes from alternatives like 'archive_email' (which archives specific emails) and 'search_by_sender' (which finds emails without archiving).

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