delete_email
Move an email to trash by providing its email ID. Use this tool to discard unwanted messages from your Fastmail inbox.
Instructions
Delete an email (move to trash)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailId | Yes | ID of the email to delete |
Implementation Reference
- src/index.ts:645-658 (registration)Tool registration/definition in the ListToolsRequestSchema handler. Defines the 'delete_email' tool with name, description, and inputSchema requiring an 'emailId' parameter.
{ name: 'delete_email', description: 'Delete an email (move to trash)', inputSchema: { type: 'object', properties: { emailId: { type: 'string', description: 'ID of the email to delete', }, }, required: ['emailId'], }, }, - src/index.ts:1438-1453 (handler)Handler in the CallToolRequestSchema switch statement. Extracts emailId from args, validates it's provided, calls client.deleteEmail(emailId), and returns a success message.
case 'delete_email': { const { emailId } = args as any; if (!emailId) { throw new McpError(ErrorCode.InvalidParams, 'emailId is required'); } const client = initializeClient(); await client.deleteEmail(emailId); return { content: [ { type: 'text', text: 'Email deleted successfully (moved to trash)', }, ], }; } - src/jmap-client.ts:802-836 (handler)Actual implementation of the deleteEmail method in JmapClient. Finds the Trash mailbox and uses JMAP Email/set to update the email's mailboxIds to point to trash only, effectively moving it to trash.
async deleteEmail(emailId: string): Promise<void> { const session = await this.getSession(); // Find the trash mailbox const mailboxes = await this.getMailboxes(); const trashMailbox = this.findMailboxByRoleOrName(mailboxes, 'trash', 'trash'); if (!trashMailbox) { throw new Error('Could not find Trash mailbox'); } const trashMailboxIds: Record<string, boolean> = {}; trashMailboxIds[trashMailbox.id] = true; const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update: { [emailId]: { mailboxIds: trashMailboxIds } } }, 'moveToTrash'] ] }; const response = await this.makeRequest(request); const result = this.getMethodResult(response, 0); if (result.notUpdated && result.notUpdated[emailId]) { throw new Error('Failed to delete email.'); } }