bulk_add_labels
Add labels to multiple emails in one action by providing email IDs and mailbox IDs for efficient email categorization.
Instructions
Add labels to multiple emails simultaneously
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailIds | Yes | Array of email IDs to add labels to | |
| mailboxIds | Yes | Array of mailbox IDs to add as labels |
Implementation Reference
- src/index.ts:918-937 (registration)Tool registration for 'bulk_add_labels' in the ListTools handler, defining the name, description, and inputSchema (accepts emailIds and mailboxIds arrays).
{ name: 'bulk_add_labels', description: 'Add labels to multiple emails simultaneously', inputSchema: { type: 'object', properties: { emailIds: { type: 'array', items: { type: 'string' }, description: 'Array of email IDs to add labels to', }, mailboxIds: { type: 'array', items: { type: 'string' }, description: 'Array of mailbox IDs to add as labels', }, }, required: ['emailIds', 'mailboxIds'], }, }, - src/index.ts:1707-1725 (handler)Handler for 'bulk_add_labels' tool call. Validates emailIds and mailboxIds arrays, then delegates to client.bulkAddLabels(emailIds, mailboxIds). Returns success message with count.
case 'bulk_add_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.bulkAddLabels(emailIds, mailboxIds); return { content: [ { type: 'text', text: `Labels added successfully to ${emailIds.length} emails`, }, ], }; } - src/jmap-client.ts:942-972 (handler)Core implementation of bulkAddLabels on JmapClient. Builds a JMAP patch to add mailboxId+ true, applies it to all emailIds in a single Email/set call. Throws if any updates fail.
async bulkAddLabels(emailIds: string[], mailboxIds: string[]): Promise<void> { const session = await this.getSession(); // Build patch object to add specific mailboxIds const patch: Record<string, any> = {}; mailboxIds.forEach(mailboxId => { patch[`mailboxIds/${mailboxId}`] = true; }); 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 }, 'bulkAddLabels'] ] }; 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 add labels to some emails.'); } }