bulk_add_labels
Add labels to multiple emails in bulk by providing an array of email IDs and an array of mailbox IDs to apply as labels.
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:921-940 (registration)Registration of the 'bulk_add_labels' tool in the ListTools handler with input schema definition
{ 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:1710-1728 (handler)CallToolRequestSchema handler case for 'bulk_add_labels' that validates inputs and delegates to JmapClient.bulkAddLabels
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)Actual JMAP implementation of bulkAddLabels that builds mailboxId patches and sends an Email/set request with updates for multiple email IDs
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.'); } }