trash_message
Move Gmail messages to trash to declutter your inbox and manage email storage. Specify the message ID to permanently remove unwanted emails.
Instructions
Move a message to the trash
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the message to move to trash |
Implementation Reference
- src/index.ts:643-654 (registration)Registration of the trash_message tool using McpServer.tool, defining its name, description, input schema (message ID), and inline handler function that uses the Gmail API to move the message to trash.server.tool("trash_message", "Move a message to the trash", { id: z.string().describe("The ID of the message to move to trash") }, async (params) => { return handleTool(config, async (gmail: gmail_v1.Gmail) => { const { data } = await gmail.users.messages.trash({ userId: 'me', id: params.id }) return formatResponse(data) }) } )
- src/index.ts:648-653 (handler)The handler function for trash_message tool, which invokes handleTool to authenticate and call gmail.users.messages.trash API with the provided message ID.async (params) => { return handleTool(config, async (gmail: gmail_v1.Gmail) => { const { data } = await gmail.users.messages.trash({ userId: 'me', id: params.id }) return formatResponse(data) }) }
- src/index.ts:645-647 (schema)Input schema for trash_message tool using Zod: requires a string 'id' parameter for the message ID.{ id: z.string().describe("The ID of the message to move to trash") },
- src/index.ts:49-65 (helper)Shared helper function handleTool used by trash_message (and other tools) to manage OAuth2 authentication, credential validation, Gmail client creation, and API call execution with error handling.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-48 (helper)Helper function formatResponse used to standardize tool responses into MCP content format by JSON stringifying the API response.const formatResponse = (response: any) => ({ content: [{ type: "text", text: JSON.stringify(response) }] })