Skip to main content
Glama

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
NameRequiredDescriptionDefault
addLabelIdsNoLabels to add to the message
messageIdYesID of the email to modify
removeLabelIdsNoLabels to remove from the message

Implementation Reference

  • 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, }; }
  • 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) }` ); } }
  • 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"], }, };
  • 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 );
  • 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)) ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vakharwalad23/google-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server