Skip to main content
Glama

apply_label

Apply a Gmail label to organize emails by categorizing messages with specific identifiers for better inbox management.

Instructions

Apply a label to an email

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageIdYesEmail message ID
labelIdYesLabel ID to apply

Implementation Reference

  • MCP tool handler for 'apply_label': validates input using Zod schema, calls GmailService.applyLabel, and returns formatted success response.
    case "apply_label": { const v = validated as z.infer<typeof schemas.apply_label>; await gmailService.applyLabel(v.messageId, v.labelId); return { content: [{ type: "text", text: `Label ${v.labelId} applied to email ${v.messageId}.` }] }; }
  • Zod input schema for the 'apply_label' tool defining messageId and labelId parameters with descriptions.
    apply_label: z.object({ messageId: z.string().describe("Email message ID"), labelId: z.string().describe("Label ID to apply") }),
  • src/tools.ts:50-55 (registration)
    Function exporting JSON schemas and descriptions for all MCP tools, including 'apply_label', for server registration.
    export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));
  • GmailService helper method implementing label application by calling Gmail API's messages.modify with addLabelIds.
    async applyLabel(messageId: string, labelId: string): Promise<void> { await this.modifyMessage(messageId, { addLabelIds: [labelId] }); }
  • Private helper in GmailService that performs the actual Gmail API call to modify message labels.
    private async modifyMessage(id: string, requestBody: any): Promise<void> { await this.gmail.users.messages.modify({ userId: 'me', id, requestBody }); }

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