Skip to main content
Glama

modify_message

Add or remove labels on Gmail messages to organize your inbox. Use this tool to categorize emails by applying or deleting specific labels based on message ID.

Instructions

Modify the labels on a message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe ID of the message to modify
addLabelIdsNoA list of label IDs to add to the message
removeLabelIdsNoA list of label IDs to remove from the message

Implementation Reference

  • The handler function for the 'modify_message' tool. It invokes the Gmail API's users.messages.modify method via the shared handleTool helper to add or remove labels from a specific message.
    async (params) => {
      return handleTool(config, async (gmail: gmail_v1.Gmail) => {
        const { data } = await gmail.users.messages.modify({ userId: 'me', id: params.id, requestBody: { addLabelIds: params.addLabelIds, removeLabelIds: params.removeLabelIds } })
        return formatResponse(data)
      })
    }
  • Input schema for the 'modify_message' tool defined using Zod, specifying parameters for message ID and optional label IDs to add or remove.
    {
      id: z.string().describe("The ID of the message to modify"),
      addLabelIds: z.array(z.string()).optional().describe("A list of label IDs to add to the message"),
      removeLabelIds: z.array(z.string()).optional().describe("A list of label IDs to remove from the message")
    },
  • src/index.ts:592-604 (registration)
    Registration of the 'modify_message' tool on the MCP server, including name, description, input schema, and handler function.
    server.tool("modify_message",
      "Modify the labels on a message",
      {
        id: z.string().describe("The ID of the message to modify"),
        addLabelIds: z.array(z.string()).optional().describe("A list of label IDs to add to the message"),
        removeLabelIds: z.array(z.string()).optional().describe("A list of label IDs to remove from the message")
      },
      async (params) => {
        return handleTool(config, async (gmail: gmail_v1.Gmail) => {
          const { data } = await gmail.users.messages.modify({ userId: 'me', id: params.id, requestBody: { addLabelIds: params.addLabelIds, removeLabelIds: params.removeLabelIds } })
          return formatResponse(data)
        })
      }
  • Shared helper function 'handleTool' used by the 'modify_message' handler (and other tools) to manage OAuth2 authentication, client creation, and execution of Gmail API calls.
    const handleTool = async (queryConfig: Record<string, any> | undefined, apiCall: (gmail: gmail_v1.Gmail) => Promise<any>) => {
      try {
        const oauth2Client = queryConfig ? createOAuth2Client(queryConfig) : defaultOAuth2Client
        if (!oauth2Client) throw new Error('OAuth2 client could not be created, please check your credentials')
    
        const credentialsAreValid = await validateCredentials(oauth2Client)
        if (!credentialsAreValid) throw new Error('OAuth2 credentials are invalid, please re-authenticate')
    
        const gmailClient = queryConfig ? google.gmail({ version: 'v1', auth: oauth2Client }) : defaultGmailClient
        if (!gmailClient) throw new Error('Gmail client could not be created, please check your credentials')
    
        const result = await apiCall(gmailClient)
        return result
      } catch (error: any) {
        return `Tool execution failed: ${error.message}`
      }
    }
  • Helper function 'formatResponse' used to standardize tool responses in MCP format.
    const formatResponse = (response: any) => ({ content: [{ type: "text", text: JSON.stringify(response) }] })
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 'modify' which implies mutation, but doesn't disclose behavioral traits like required permissions, whether changes are reversible, rate limits, or what happens if label IDs are invalid. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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 with zero waste. It's front-loaded with the core purpose and appropriately sized for the tool's complexity. Every word earns its place without redundancy.

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 a mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral context (e.g., error handling, side effects) and doesn't hint at return values. For a tool that modifies data, more guidance on outcomes and constraints is needed.

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 parameters are well-documented in the schema. The description adds minimal value beyond the schema by implying label modification but doesn't explain parameter interactions (e.g., can add and remove simultaneously) or provide examples. Baseline 3 is appropriate as the schema does the heavy lifting.

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 'Modify the labels on a message' clearly states the action (modify) and resource (labels on a message). It distinguishes from siblings like 'delete_message' or 'trash_message' by focusing on label modification rather than deletion or moving. However, it doesn't explicitly differentiate from 'batch_modify_messages' which handles multiple messages.

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 (e.g., needing message ID), contrast with 'batch_modify_messages' for bulk operations, or specify scenarios like organizing emails versus deleting them. Usage is implied but not articulated.

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

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/HitmanLy007/gmail-mcp'

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