Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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, }; }
  • 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 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 );
  • 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; }
  • 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) }` ); } }

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/vakharwalad23/google-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server