Skip to main content
Glama

batch_apply_labels

Apply labels to multiple email messages at once to quickly organize your Gmail inbox by categorizing or filtering groups of emails.

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

  • Zod schema for batch_apply_labels input: requires messageIds (array of strings) and labelIds (array of strings).
    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")
    }),
  • Core handler: batchApplyLabels method on GmailService that calls modifyMessage for each messageId with all labelIds, using batchOperation for concurrency control.
    async batchApplyLabels(messageIds: string[], labelIds: string[]): Promise<{ successes: number; failures: number }> {
        return this.batchOperation(messageIds, (id) => this.modifyMessage(id, { addLabelIds: labelIds }));
    }
  • src/tools.ts:126-131 (registration)
    Registration handler: case 'batch_apply_labels' in handleToolCall switch, validates input via Zod schema and delegates to GmailService.batchApplyLabels.
    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: batchOperation method processes items in batches of 50 with Promise.allSettled, returning success/failure counts.
    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 };
    }
  • Helper: modifyMessage calls the Gmail API users.messages.modify endpoint.
    private async modifyMessage(id: string, requestBody: any): Promise<void> {
        await this.gmail.users.messages.modify({ userId: 'me', id, requestBody });
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must disclose all behavioral traits. However, it only says 'apply labels', which implies mutation, but does not mention side effects, idempotency, partial failure handling, or authorization needs. This is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence with no wasted words. While it could include more detail, it is appropriately front-loaded and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of batch operations (potential partial failures, idempotency, return values), the description is too minimal. No output schema exists, so the description should explain what is returned or what happens on success/failure. This is a significant gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already describes both parameters (messageIds and labelIds). The description adds no additional meaning beyond what the schema provides. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (apply labels) and the scope (multiple emails at once). It effectively distinguishes from siblings like 'apply_label' (single email) and 'batch_delete_emails' (different operation).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use batch vs single apply_label, no prerequisites, and no exclusions. The description simply states the action without context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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