bulk_remove_labels
Remove labels from a batch of email messages by providing their IDs and the label mailboxes to detach. Organize your inbox efficiently.
Instructions
Remove labels from multiple emails simultaneously
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": {
"emailIds": "<emailIds>",
"mailboxIds": "<mailboxIds>"
},
"name": "bulk_remove_labels"
}
}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:941-959 (schema)Schema registration for bulk_remove_labels tool, listing its input parameters (emailIds and mailboxIds, both required arrays of strings).
{ 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:1730-1748 (handler)Handler for the bulk_remove_labels tool: validates inputs, then calls client.bulkRemoveLabels() and returns a success message.
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/index.ts:941-960 (registration)Registration of the bulk_remove_labels tool in the ListToolsRequestSchema handler.
{ 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/jmap-client.ts:974-1004 (helper)Core JMAP implementation of bulkRemoveLabels: builds patch objects setting mailboxIds to null for each email, then sends a single Email/set request with updates for all email IDs at once.
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.'); } }