google_gmail_list_labels
Retrieve all available Gmail labels using this integration tool, designed to streamline access and organization within Google MCP server workflows.
Instructions
List all available Gmail labels
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- handlers/gmail.ts:14-29 (handler)The main handler function that validates the input arguments using isListLabelsArgs and calls googleGmailInstance.listLabels() to retrieve and format Gmail labels for the tool response.
export async function handleGmailListLabels( args: any, googleGmailInstance: GoogleGmail ) { if (!isListLabelsArgs(args)) { throw new Error("Invalid arguments for google_gmail_list_labels"); } const labels = await googleGmailInstance.listLabels(); const formattedResult = labels .map((label: any) => `${label.name} - ID: ${label.id} (${label.type})`) .join("\n"); return { content: [{ type: "text", text: formattedResult }], isError: false, }; } - tools/gmail/index.ts:1-10 (schema)MCP tool schema definition specifying the name, description, and input schema (empty object, no parameters required).
import { type Tool } from "@modelcontextprotocol/sdk/types.js"; export const LIST_LABELS_TOOL: Tool = { name: "google_gmail_list_labels", description: "List all available Gmail labels", inputSchema: { type: "object", properties: {}, }, }; - server-setup.ts:134-138 (registration)Server request handler switch case that registers and dispatches calls to the google_gmail_list_labels tool by invoking the corresponding Gmail handler.
case "google_gmail_list_labels": return await gmailHandlers.handleGmailListLabels( args, googleGmailInstance ); - utils/helper.ts:122-124 (helper)Helper function (type guard) that validates tool arguments, ensuring no arguments are provided as per the schema.
export function isListLabelsArgs(args: any): args is Record<string, never> { return args && Object.keys(args).length === 0; } - utils/gmail.ts:26-44 (helper)Core Gmail service method in GoogleGmail class that makes the actual Google Gmail API call to list user labels.
async listLabels() { try { const response = await this.gmail.users.labels.list({ userId: "me", }); return response.data.labels.map((label: any) => ({ id: label.id, name: label.name, type: label.type, })); } catch (error) { throw new Error( `Failed to list labels: ${ error instanceof Error ? error.message : String(error) }` ); } }