remove_labels
Remove specified labels from an email by providing the email ID and mailbox IDs to detach those labels.
Instructions
Remove specific labels (mailboxes) from an email
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailId | Yes | ID of the email to remove labels from | |
| mailboxIds | Yes | Array of mailbox IDs to remove as labels |
Implementation Reference
- src/jmap-client.ts:913-940 (handler)The actual handler method on JmapClient that removes labels from an email by building a JMAP patch object that sets each specified mailboxId to null (removing the label), then sending an Email/set request.
async removeLabels(emailId: 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 request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update: { [emailId]: patch } }, 'removeLabels'] ] }; const response = await this.makeRequest(request); const result = this.getMethodResult(response, 0); if (result.notUpdated && result.notUpdated[emailId]) { throw new Error('Failed to remove labels from email.'); } } - src/index.ts:696-714 (registration)Schema registration for the 'remove_labels' tool in the ListTools handler (lines 696-714) and the call handler (lines 1492-1510) that reads args and calls client.removeLabels(emailId, mailboxIds).
{ name: 'remove_labels', description: 'Remove specific labels (mailboxes) from an email', inputSchema: { type: 'object', properties: { emailId: { type: 'string', description: 'ID of the email to remove labels from', }, mailboxIds: { type: 'array', items: { type: 'string' }, description: 'Array of mailbox IDs to remove as labels', }, }, required: ['emailId', 'mailboxIds'], }, }, - src/index.ts:696-714 (schema)Input schema definition for the 'remove_labels' tool, specifying required emailId (string) and mailboxIds (array of strings).
{ name: 'remove_labels', description: 'Remove specific labels (mailboxes) from an email', inputSchema: { type: 'object', properties: { emailId: { type: 'string', description: 'ID of the email to remove labels from', }, mailboxIds: { type: 'array', items: { type: 'string' }, description: 'Array of mailbox IDs to remove as labels', }, }, required: ['emailId', 'mailboxIds'], }, }, - src/index.ts:1492-1510 (handler)Call handler for 'remove_labels' tool — validates emailId and mailboxIds, then delegates to JmapClient.removeLabels().
case 'remove_labels': { const { emailId, mailboxIds } = args as any; if (!emailId) { throw new McpError(ErrorCode.InvalidParams, 'emailId is required'); } 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.removeLabels(emailId, mailboxIds); return { content: [ { type: 'text', text: `Labels removed successfully from email`, }, ], }; }