modify_email
Manage email labels in Gmail using the Google Workspace MCP Server. Add, remove, archive, trash, or mark emails as read/unread programmatically.
Instructions
Modify email labels (archive, trash, mark read/unread)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| addLabels | No | Labels to add | |
| id | Yes | Email ID | |
| removeLabels | No | Labels to remove |
Implementation Reference
- src/index.ts:504-536 (handler)The main handler function that executes the modify_email tool logic by calling the Gmail API to add or remove labels from an email.private async handleModifyEmail(args: any) { try { const { id, addLabels = [], removeLabels = [] } = args; const response = await this.gmail.users.messages.modify({ userId: "me", id, requestBody: { addLabelIds: addLabels, removeLabelIds: removeLabels, }, }); return { content: [ { type: "text", text: `Email modified successfully. Updated labels for message ID: ${response.data.id}`, }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error modifying email: ${error.message}`, }, ], isError: true, }; } }
- src/index.ts:136-159 (registration)Registers the 'modify_email' tool in the ListTools response, including its name, description, and input schema.{ name: "modify_email", description: "Modify email labels (archive, trash, mark read/unread)", inputSchema: { type: "object", properties: { id: { type: "string", description: "Email ID", }, addLabels: { type: "array", items: { type: "string" }, description: "Labels to add", }, removeLabels: { type: "array", items: { type: "string" }, description: "Labels to remove", }, }, required: ["id"], }, },
- src/index.ts:280-281 (registration)Dispatches CallTool requests for 'modify_email' to the handleModifyEmail handler function.case "modify_email": return await this.handleModifyEmail(request.params.arguments);
- src/index.ts:139-158 (schema)Defines the input schema for the 'modify_email' tool, specifying required 'id' and optional label arrays.inputSchema: { type: "object", properties: { id: { type: "string", description: "Email ID", }, addLabels: { type: "array", items: { type: "string" }, description: "Labels to add", }, removeLabels: { type: "array", items: { type: "string" }, description: "Labels to remove", }, }, required: ["id"], },