Skip to main content
Glama
ai-zerolab

MCP Email Server

by ai-zerolab

delete_emails

Remove specific emails from an email account by their IDs to manage mailbox storage and organization.

Instructions

Delete one or more emails by their email_id. Use list_emails_metadata first to get the email_id.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_nameYesThe name of the email account.
email_idsYesList of email_id to delete (obtained from list_emails_metadata).
mailboxNoThe mailbox to delete emails from.INBOX

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP 'delete_emails' tool handler: decorated with @mcp.tool (registration), defines input schema with Annotated[Field], dispatches to account-specific handler.delete_emails and formats response.
    @mcp.tool(
        description="Delete one or more emails by their email_id. Use list_emails_metadata first to get the email_id."
    )
    async def delete_emails(
        account_name: Annotated[str, Field(description="The name of the email account.")],
        email_ids: Annotated[
            list[str],
            Field(description="List of email_id to delete (obtained from list_emails_metadata)."),
        ],
        mailbox: Annotated[str, Field(default="INBOX", description="The mailbox to delete emails from.")] = "INBOX",
    ) -> str:
        handler = dispatch_handler(account_name)
        deleted_ids, failed_ids = await handler.delete_emails(email_ids, mailbox)
    
        result = f"Successfully deleted {len(deleted_ids)} email(s)"
        if failed_ids:
            result += f", failed to delete {len(failed_ids)} email(s): {', '.join(failed_ids)}"
        return result
  • ClassicEmailHandler.delete_emails method: delegates deletion to the underlying incoming_client (EmailClient).
    async def delete_emails(self, email_ids: list[str], mailbox: str = "INBOX") -> tuple[list[str], list[str]]:
        """Delete emails by their UIDs. Returns (deleted_ids, failed_ids)."""
        return await self.incoming_client.delete_emails(email_ids, mailbox)
  • EmailClient.delete_emails core implementation: connects to IMAP server, marks each email ID (UID) with \Deleted flag, expunges mailbox to permanently delete, handles failures.
    async def delete_emails(self, email_ids: list[str], mailbox: str = "INBOX") -> tuple[list[str], list[str]]:
        """Delete emails by their UIDs. Returns (deleted_ids, failed_ids)."""
        imap = self.imap_class(self.email_server.host, self.email_server.port)
        deleted_ids = []
        failed_ids = []
    
        try:
            await imap._client_task
            await imap.wait_hello_from_server()
            await imap.login(self.email_server.user_name, self.email_server.password)
            await imap.select(mailbox)
    
            for email_id in email_ids:
                try:
                    await imap.uid("store", email_id, "+FLAGS", r"(\Deleted)")
                    deleted_ids.append(email_id)
                except Exception as e:
                    logger.error(f"Failed to delete email {email_id}: {e}")
                    failed_ids.append(email_id)
    
            await imap.expunge()
        finally:
            try:
                await imap.logout()
            except Exception as e:
                logger.info(f"Error during logout: {e}")
    
        return deleted_ids, failed_ids
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. While it mentions the destructive action ('Delete'), it doesn't disclose critical behavioral traits like whether deletion is permanent or reversible, what permissions are required, error handling for invalid IDs, or rate limits. The description only covers the basic operation without safety or implementation details.

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 perfectly concise with two sentences that each earn their place: the first states the core purpose, the second provides essential usage guidance. It's front-loaded with the main action and wastes no words on redundant information already in the schema.

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 an output schema (which handles return values) and 100% schema coverage for parameters, the description is reasonably complete for basic understanding. However, as a destructive mutation tool with no annotations, it should ideally disclose more about behavioral consequences, permissions, or safety considerations to be fully complete.

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 thoroughly. The description adds minimal value beyond the schema by mentioning 'email_id' (already in schema) and implying they come from 'list_emails_metadata' (helpful context). This meets the baseline for high schema coverage without significant additional parameter explanation.

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 specific action ('Delete one or more emails') and the resource ('by their email_id'), distinguishing it from siblings like 'send_email' (creation) or 'list_emails_metadata' (read-only). It provides a precise verb+resource combination that leaves no ambiguity about the tool's function.

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 explicitly states when to use this tool ('Delete one or more emails') and provides a clear prerequisite ('Use list_emails_metadata first to get the email_id'), naming the specific sibling tool needed beforehand. This gives perfect guidance on the workflow sequence.

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/ai-zerolab/mcp-email-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server