add_labels
Append specified mailbox labels to an email without removing existing ones.
Instructions
Add labels (mailboxes) to an email without removing existing ones
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailId | Yes | ID of the email to add labels to | |
| mailboxIds | Yes | Array of mailbox IDs to add as labels |
Implementation Reference
- src/jmap-client.ts:884-911 (handler)The `addLabels` method on JmapClient: builds a JMAP patch to add specific mailboxIds to an email's mailboxIds field and sends an Email/set request. This is the core handler that executes the label-adding logic via the Fastmail JMAP API.
async addLabels(emailId: 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 request: JmapRequest = { using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'], methodCalls: [ ['Email/set', { accountId: session.accountId, update: { [emailId]: patch } }, 'addLabels'] ] }; const response = await this.makeRequest(request); const result = this.getMethodResult(response, 0); if (result.notUpdated && result.notUpdated[emailId]) { throw new Error('Failed to add labels to email.'); } } - src/index.ts:1475-1493 (handler)The tool handler for 'add_labels' in the MCP request router: extracts emailId and mailboxIds from args, validates inputs, calls client.addLabels(), and returns a success message.
case 'add_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.addLabels(emailId, mailboxIds); return { content: [ { type: 'text', text: `Labels added successfully to email`, }, ], }; } - src/index.ts:680-698 (schema)The input schema registration for the 'add_labels' tool, defining the required emailId (string) and mailboxIds (array of strings) parameters.
{ name: 'add_labels', description: 'Add labels (mailboxes) to an email without removing existing ones', inputSchema: { type: 'object', properties: { emailId: { type: 'string', description: 'ID of the email to add labels to', }, mailboxIds: { type: 'array', items: { type: 'string' }, description: 'Array of mailbox IDs to add as labels', }, }, required: ['emailId', 'mailboxIds'], }, }, - src/index.ts:680-698 (registration)Registration of the 'add_labels' tool in the ListToolsRequestSchema handler, declaring its name, description, and input schema.
{ name: 'add_labels', description: 'Add labels (mailboxes) to an email without removing existing ones', inputSchema: { type: 'object', properties: { emailId: { type: 'string', description: 'ID of the email to add labels to', }, mailboxIds: { type: 'array', items: { type: 'string' }, description: 'Array of mailbox IDs to add as labels', }, }, required: ['emailId', 'mailboxIds'], }, },