google_gmail_modify_labels
Manage Gmail labels by adding or removing them from specific emails using the message ID. Integrates with AI clients for efficient email organization.
Instructions
Add or remove labels from an email
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| addLabelIds | No | Labels to add to the message | |
| messageId | Yes | ID of the email to modify | |
| removeLabelIds | No | Labels to remove from the message |
Implementation Reference
- handlers/gmail.ts:156-173 (handler)Handler function that validates input and calls the Gmail service to modify labels on an email.export async function handleGmailModifyLabels( args: any, googleGmailInstance: GoogleGmail ) { if (!isModifyLabelsArgs(args)) { throw new Error("Invalid arguments for google_gmail_modify_labels"); } const { messageId, addLabelIds, removeLabelIds } = args; const result = await googleGmailInstance.modifyLabels( messageId, addLabelIds, removeLabelIds ); return { content: [{ type: "text", text: result }], isError: false, }; }
- utils/gmail.ts:545-576 (helper)Core implementation in GoogleGmail class that calls Gmail API to modify labels on a message.async modifyLabels( messageId: string, addLabelIds?: string[], removeLabelIds?: string[] ) { try { await this.gmail.users.messages.modify({ userId: "me", id: messageId, requestBody: { addLabelIds: addLabelIds || [], removeLabelIds: removeLabelIds || [], }, }); let result = `Successfully modified labels for message ${messageId}.`; if (addLabelIds && addLabelIds.length > 0) { result += `\nAdded labels: ${addLabelIds.join(", ")}`; } if (removeLabelIds && removeLabelIds.length > 0) { result += `\nRemoved labels: ${removeLabelIds.join(", ")}`; } return result; } catch (error) { throw new Error( `Failed to modify labels: ${ error instanceof Error ? error.message : String(error) }` ); } }
- tools/gmail/index.ts:232-255 (schema)Tool definition including input schema for google_gmail_modify_labels.export const MODIFY_LABELS_TOOL: Tool = { name: "google_gmail_modify_labels", description: "Add or remove labels from an email", inputSchema: { type: "object", properties: { messageId: { type: "string", description: "ID of the email to modify", }, addLabelIds: { type: "array", items: { type: "string" }, description: "Labels to add to the message", }, removeLabelIds: { type: "array", items: { type: "string" }, description: "Labels to remove from the message", }, }, required: ["messageId"], }, };
- server-setup.ts:169-173 (registration)Switch case in server request handler that routes calls to the Gmail modify labels handler.case "google_gmail_modify_labels": return await gmailHandlers.handleGmailModifyLabels( args, googleGmailInstance );
- utils/helper.ts:224-235 (schema)Type guard function for validating arguments to google_gmail_modify_labels.export function isModifyLabelsArgs(args: any): args is { messageId: string; addLabelIds?: string[]; removeLabelIds?: string[]; } { return ( args && typeof args.messageId === "string" && (args.addLabelIds === undefined || Array.isArray(args.addLabelIds)) && (args.removeLabelIds === undefined || Array.isArray(args.removeLabelIds)) ); }