Skip to main content
Glama

batch_apply_labels

Apply labels to multiple emails simultaneously in Gmail to organize your inbox efficiently.

Instructions

Apply labels to multiple emails at once

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageIdsYesArray of email message IDs
labelIdsYesArray of label IDs to apply

Implementation Reference

  • Core handler function that batches label applications to multiple emails by calling batchOperation with modifyMessage.
    async batchApplyLabels(messageIds: string[], labelIds: string[]): Promise<{ successes: number; failures: number }> { return this.batchOperation(messageIds, (id) => this.modifyMessage(id, { addLabelIds: labelIds })); }
  • Zod input schema validation for the batch_apply_labels tool parameters.
    batch_apply_labels: z.object({ messageIds: z.array(z.string()).describe("Array of email message IDs"), labelIds: z.array(z.string()).describe("Array of label IDs to apply") }),
  • src/tools.ts:50-55 (registration)
    Generates MCP tool definitions including schema and description for batch_apply_labels.
    export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));
  • Dispatcher in handleToolCall that validates input and invokes the GmailService batchApplyLabels handler.
    case "batch_apply_labels": { const v = validated as z.infer<typeof schemas.batch_apply_labels>; const result = await gmailService.batchApplyLabels(v.messageIds, v.labelIds); return { content: [{ type: "text", text: `Batch label application completed:\nSuccessfully processed: ${result.successes} emails\nFailed: ${result.failures} emails` }] }; }
  • Helper function used by batchApplyLabels to process operations in batches with success/failure counting.
    private async batchOperation<T>(items: T[], operation: (item: T) => Promise<any>): Promise<{ successes: number; failures: number }> { let successes = 0, failures = 0; const batchSize = 50; for (let i = 0; i < items.length; i += batchSize) { const results = await Promise.allSettled(items.slice(i, i + batchSize).map(operation)); results.forEach(r => r.status === 'fulfilled' ? successes++ : failures++); } return { successes, failures }; }

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/muammar-yacoob/GMail-Manager-MCP'

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