list_labels
Retrieve all Gmail labels to organize and categorize emails for better inbox management and filtering.
Instructions
List all Gmail labels
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:93-100 (handler)Executes the list_labels tool by calling GmailService.listLabels(), filtering labels into system and user categories, and formatting a structured text response.case "list_labels": { const labels = await gmailService.listLabels(); const system = labels.filter(l => l.type === 'system'); const user = labels.filter(l => l.type === 'user'); return { content: [{ type: "text", text: labels.length ? `System Labels (${system.length}):\n${system.map(l => ` - ${l.name} (${l.id})`).join('\n')}\n\nUser Labels (${user.length}):\n${user.map(l => ` - ${l.name} (${l.id})`).join('\n')}` : "No labels found." }] }; }
- src/tools.ts:13-13 (schema)Zod input schema for the list_labels tool, which accepts no parameters.list_labels: z.object({}),
- src/tools.ts:50-55 (registration)Generates MCP tool definitions including name, description, and input schema for list_labels and other tools, used in ListTools handler.export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));
- src/gmail-service.ts:80-83 (helper)Core implementation that fetches all Gmail labels via the Google Gmail API v1.async listLabels(): Promise<Label[]> { const { data } = await this.gmail.users.labels.list({ userId: 'me' }); return (data.labels || []) as Label[]; }
- src/gmail-service.ts:18-22 (schema)TypeScript interface defining the structure of Label objects returned by listLabels.export interface Label { id?: string | null; name?: string | null; type?: string | null; }