Skip to main content
Glama

batch_delete_emails

Delete multiple Gmail messages simultaneously by specifying an array of message IDs. Streamline inbox cleanup by removing unwanted emails in bulk.

Instructions

Delete multiple emails at once

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageIdsYesArray of email message IDs to delete

Implementation Reference

  • The core handler method that batch-deletes emails. Delegates to the private batchOperation helper, calling deleteEmail for each message ID. Returns a count of successes and failures.
    async batchDeleteEmails(ids: string[]): Promise<{ successes: number; failures: number }> {
        return this.batchOperation(ids, (id) => this.deleteEmail(id));
    }
  • Private helper that processes items in batches of 50 using Promise.allSettled, counting successes and failures. Used by batchDeleteEmails.
    private async batchOperation<T>(items: T[], operation: (item: T) => Promise<any>): Promise<{ successes: number; failures: number }> {
        let successes = 0, failures = 0;
        const batchSize = 50;
        
        for (let i = 0; i < items.length; i += batchSize) {
            const results = await Promise.allSettled(items.slice(i, i + batchSize).map(operation));
            results.forEach(r => r.status === 'fulfilled' ? successes++ : failures++);
        }
        
        return { successes, failures };
    }
  • The underlying deleteEmail method called per-message-ID in the batch operation. Calls the Gmail API to permanently delete a message.
    async deleteEmail(id: string): Promise<void> {
        await this.gmail.users.messages.delete({ userId: 'me', id });
    }
  • Zod schema definition for batch_delete_emails. Validates that messageIds is an array of strings (email message IDs).
    batch_delete_emails: z.object({ messageIds: z.array(z.string()).describe("Array of email message IDs to delete") }),
  • src/tools.ts:55-86 (registration)
    Handler case in the switch statement of handleToolCall. Validates input via schema, calls gmailService.batchDeleteEmails, and returns a result text with success/failure counts.
        }));
    
    export async function handleToolCall(gmailService: GmailService, name: string, args: any) {
        try {
            const schema = schemas[name as keyof typeof schemas];
            if (!schema) throw new Error(`Unknown tool: ${name}`);
            
            const validated = schema.parse(args);
            
            switch (name) {
                case "search_emails": {
                    const v = validated as z.infer<typeof schemas.search_emails>;
                    const results = await gmailService.searchEmails(v.query, v.maxResults);
                    return { content: [{ type: "text", text: results.length ? 
                        results.map(e => `ID: ${e.id}\nSubject: ${e.subject}\nFrom: ${e.from}\nDate: ${e.date}\nSnippet: ${e.snippet}\nGmail URL: ${gmailService.getEmailUrl(e.id)}\n`).join('---\n') : 
                        "No emails found." }] };
                }
                
                case "read_email": {
                    const v = validated as z.infer<typeof schemas.read_email>;
                    const email = await gmailService.readEmail(v.messageId);
                    return { content: [{ type: "text", 
                        text: `Subject: ${email.subject}\nFrom: ${email.from}\nTo: ${email.to}\nDate: ${email.date}\nThread ID: ${email.threadId}\nGmail URL: ${gmailService.getEmailUrl(v.messageId)}\n\nContent:\n${email.body}` }] };
                }
                
                case "delete_email": {
                    const v = validated as z.infer<typeof schemas.delete_email>;
                    await gmailService.deleteEmail(v.messageId);
                    return { content: [{ type: "text", text: `Email ${v.messageId} deleted successfully.` }] };
                }
                
                case "batch_delete_emails": {
Behavior2/5

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

No annotations exist, and the description only says 'delete multiple emails at once' without disclosing whether the deletion is permanent, if there are any limits, or side effects. The burden on the description is high due to missing annotations.

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 a single concise sentence. It is front-loaded and efficient, though it could benefit from slightly more detail to improve completeness.

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 lack of annotations and output schema, the description is too minimal. It does not address potential failure modes, rate limits, or the nature of the deletion, making it incomplete for a reliable tool invocation.

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?

The input schema has 100% description coverage for the only parameter 'messageIds' ('Array of email message IDs to delete'). The tool description adds no additional parameter semantics beyond what the schema already provides.

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 'Delete multiple emails at once' clearly states the verb (delete) and resource (emails, multiple). It distinguishes itself from sibling tool 'delete_email' which deletes a single email.

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 batch_delete_emails versus delete_email or other alternatives. The description lacks any context about prerequisites or scenarios.

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/muammar-yacoob/GMail-Manager-MCP'

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