list_labels
Retrieve all Gmail labels to organize your inbox and manage email categorization within the GMail Manager MCP server.
Instructions
List all Gmail labels
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:93-100 (handler)Tool handler for 'list_labels': calls GmailService.listLabels(), categorizes labels into system and user, and formats a response text.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 list_labels tool (no parameters).list_labels: z.object({}),
- src/tools.ts:50-55 (registration)Registers all tools including list_labels by generating JSON schemas from Zod definitions and descriptions.export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));
- src/gmail-service.ts:80-83 (helper)GmailService method that fetches and returns all Gmail labels using Google Gmail API.async listLabels(): Promise<Label[]> { const { data } = await this.gmail.users.labels.list({ userId: 'me' }); return (data.labels || []) as Label[]; }