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))
      );
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the tool modifies labels (implying mutation) but doesn't disclose behavioral traits like whether it requires specific permissions, if changes are reversible, rate limits, or what happens if label IDs don't exist. For a mutation tool with zero annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a tool with clear parameters and no complex behavior to explain.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., success confirmation, updated email object), error conditions, or important behavioral context needed for safe use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all three parameters (messageId, addLabelIds, removeLabelIds) with clear descriptions. The description adds no additional meaning beyond what the schema provides, which meets the baseline of 3 when schema coverage is high.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Add or remove') and resource ('labels from an email'), making the purpose immediately understandable. However, it doesn't differentiate this tool from potential sibling tools in the Gmail domain (like google_gmail_list_labels or google_gmail_get_email), which would require a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (like needing an existing email ID), when not to use it, or how it relates to other Gmail tools (e.g., use google_gmail_list_labels first to get label IDs).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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