list_labels
List all Gmail labels and folders to view your email organization structure. No input parameters needed.
Instructions
List all Gmail labels and folders.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/gmail.ts:124-135 (handler)The actual Gmail API call that fetches labels from the Gmail API. Calls gmail.users.labels.list, then maps the response to GmailLabel objects.
export async function listLabels(): Promise<GmailLabel[]> { const gmail = await getGmailClient(); const response = await gmail.users.labels.list({ userId: USER_ID }); return (response.data.labels ?? []).map((label) => ({ id: label.id, name: label.name, type: label.type, messageListVisibility: label.messageListVisibility, labelListVisibility: label.labelListVisibility, })); } - src/gmail.ts:32-38 (schema)The GmailLabel type definition used as the return type of listLabels().
export type GmailLabel = { id?: string | null; name?: string | null; type?: string | null; messageListVisibility?: string | null; labelListVisibility?: string | null; }; - src/index.ts:61-63 (registration)The MCP tool registration: server.tool('list_labels', ...) with no inputs and a handler that calls the imported listLabels() function.
server.tool("list_labels", "List all Gmail labels and folders.", {}, async () => jsonResult(await listLabels()), ); - src/index.ts:10-10 (helper)Import of the listLabels function from './gmail.js' in src/index.ts, wiring it to the MCP tool registration.
const { getEmail, listInboxEmails, listLabels, searchEmails } = await import("./gmail.js");