modify_message
Add or remove labels from Gmail messages to organize your inbox and categorize emails for better email management.
Instructions
Modify the labels on a message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the message to modify | |
| addLabelIds | No | A list of label IDs to add to the message | |
| removeLabelIds | No | A list of label IDs to remove from the message |
Implementation Reference
- src/index.ts:592-605 (registration)Registration of the 'modify_message' MCP tool, including schema definition 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) }) } )
- src/index.ts:599-604 (handler)Handler function executes the tool logic by calling Gmail API's messages.modify method via the handleTool helper.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) }) }
- src/index.ts:594-597 (schema)Zod schema defining input parameters: message id (required), optional addLabelIds and removeLabelIds arrays.{ 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:49-65 (helper)Shared helper function that handles OAuth2 authentication validation and Gmail client creation before executing the API call.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}` } }
- src/index.ts:47-47 (helper)Helper to format API responses as MCP content blocks.const formatResponse = (response: any) => ({ content: [{ type: "text", text: JSON.stringify(response) }] })