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
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"messageIds": "<messageIds>"
},
"name": "batch_delete_emails"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| messageIds | Yes | Array of email message IDs to delete |
Implementation Reference
- src/gmail-service.ts:76-78 (handler)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)); } - src/gmail-service.ts:113-123 (helper)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 }; } - src/gmail-service.ts:72-74 (handler)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 }); } - src/tools.ts:12-12 (schema)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": {