apply_label
Apply a Gmail label to organize specific emails using message and label identifiers for better inbox management.
Instructions
Apply a label to an email
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| labelId | Yes | Label ID to apply | |
| messageId | Yes | Email message ID |
Implementation Reference
- src/tools.ts:114-118 (handler)Handler for the 'apply_label' tool within handleToolCall function. Validates input using Zod schema and delegates to GmailService.applyLabel.case "apply_label": { const v = validated as z.infer<typeof schemas.apply_label>; await gmailService.applyLabel(v.messageId, v.labelId); return { content: [{ type: "text", text: `Label ${v.labelId} applied to email ${v.messageId}.` }] }; }
- src/tools.ts:16-19 (schema)Zod schema definition for the 'apply_label' tool input parameters: messageId and labelId.apply_label: z.object({ messageId: z.string().describe("Email message ID"), labelId: z.string().describe("Label ID to apply") }),
- src/tools.ts:50-55 (registration)Tool registration via getToolDefinitions, which generates MCP tool definitions including 'apply_label' from schemas and descriptions.export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));
- src/gmail-service.ts:97-99 (helper)Core implementation of applying a label to an email message using Gmail API's modifyMessage with addLabelIds.async applyLabel(messageId: string, labelId: string): Promise<void> { await this.modifyMessage(messageId, { addLabelIds: [labelId] }); }