bulk_remove_labels
Remove labels from multiple emails at once. Specify email IDs and mailbox IDs to bulk-remove labels, streamlining email organization.
Instructions
Remove labels from multiple emails simultaneously
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailIds | Yes | Array of email IDs to remove labels from | |
| mailboxIds | Yes | Array of mailbox IDs to remove as labels |
Implementation Reference
- src/index.ts:938-957 (registration)Tool registration with input schema definition (name 'bulk_remove_labels', requires 'emailIds' and 'mailboxIds' arrays)
{ name: 'bulk_remove_labels', description: 'Remove labels from multiple emails simultaneously', inputSchema: { type: 'object', properties: { emailIds: { type: 'array', items: { type: 'string' }, description: 'Array of email IDs to remove labels from', }, mailboxIds: { type: 'array', items: { type: 'string' }, description: 'Array of mailbox IDs to remove as labels', }, }, required: ['emailIds', 'mailboxIds'], }, }, - src/index.ts:1727-1745 (handler)Handler case for 'bulk_remove_labels' - extracts emailIds and mailboxIds from args, validates them, then calls client.bulkRemoveLabels()
case 'bulk_remove_labels': { const { emailIds, mailboxIds } = args as any; if (!emailIds || !Array.isArray(emailIds) || emailIds.length === 0) { throw new McpError(ErrorCode.InvalidParams, 'emailIds array is required and must not be empty'); } if (!mailboxIds || !Array.isArray(mailboxIds) || mailboxIds.length === 0) { throw new McpError(ErrorCode.InvalidParams, 'mailboxIds array is required and must not be empty'); } const client = initializeClient(); await client.bulkRemoveLabels(emailIds, mailboxIds); return { content: [ { type: 'text', text: `Labels removed successfully from ${emailIds.length} emails`, }, ], }; } - src/jmap-client.ts:974-1004 (helper)JMAP client implementation of bulkRemoveLabels - builds a patch to null out mailboxIds for each email, sends Email/set request
async bulkRemoveLabels(emailIds: string[], mailboxIds: string[]): Promise<void> { const session = await this.getSession(); // Build patch object to remove specific mailboxIds const patch: Record<string, any> = {}; mailboxIds.forEach(mailboxId => { patch[`mailboxIds/${mailboxId}`] = null; }); const updates: Record<string, any> = {}; emailIds.forEach(id => { updates[id] = patch; }); const request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update: updates }, 'bulkRemoveLabels'] ] }; const response = await this.makeRequest(request); const result = this.getMethodResult(response, 0); if (result.notUpdated && Object.keys(result.notUpdated).length > 0) { throw new Error('Failed to remove labels from some emails.'); } }