Skip to main content
Glama

batch_apply_labels

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

Instructions

Apply labels to multiple emails at once

Input Schema

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

Implementation Reference

  • MCP tool handler for 'batch_apply_labels': validates input using Zod schema and delegates to GmailService.batchApplyLabels, formats success/failure response.
    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` }] }; }
  • Core GmailService method implementing batch label application by applying addLabelIds modification to multiple message IDs via batchOperation.
    async batchApplyLabels(messageIds: string[], labelIds: string[]): Promise<{ successes: number; failures: number }> { return this.batchOperation(messageIds, (id) => this.modifyMessage(id, { addLabelIds: labelIds })); }
  • Zod input schema for batch_apply_labels tool defining messageIds and labelIds arrays.
    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") }),
  • Reusable batchOperation helper function that processes items in batches of 50, counts successes and failures using Promise.allSettled; used by batchApplyLabels.
    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 }; }
  • src/tools.ts:50-55 (registration)
    getToolDefinitions function that registers all tools including batch_apply_labels by converting Zod schemas to JSON schemas for MCP ListTools response.
    export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));

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