apply_label
Apply a Gmail label to organize emails by categorizing messages with specific identifiers for better inbox management.
Instructions
Apply a label to an email
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| messageId | Yes | Email message ID | |
| labelId | Yes | Label ID to apply |
Implementation Reference
- src/tools.ts:114-118 (handler)MCP tool handler for 'apply_label': validates input using Zod schema, calls GmailService.applyLabel, and returns formatted success response.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 input schema for the 'apply_label' tool defining messageId and labelId parameters with descriptions.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)Function exporting JSON schemas and descriptions for all MCP tools, including 'apply_label', for server registration.export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));
- src/gmail-service.ts:97-99 (helper)GmailService helper method implementing label application by calling Gmail API's messages.modify with addLabelIds.async applyLabel(messageId: string, labelId: string): Promise<void> { await this.modifyMessage(messageId, { addLabelIds: [labelId] }); }
- src/gmail-service.ts:109-111 (helper)Private helper in GmailService that performs the actual Gmail API call to modify message labels.private async modifyMessage(id: string, requestBody: any): Promise<void> { await this.gmail.users.messages.modify({ userId: 'me', id, requestBody }); }