google_gmail_list_emails
Retrieve and filter emails from specified Gmail labels or folders using search queries and set maximum results for efficient email management on the Google MCP server.
Instructions
List emails from a specific label or folder
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| labelIds | No | Label IDs to filter messages (e.g., 'INBOX', 'SENT') | |
| maxResults | No | Maximum number of emails to return | |
| query | No | Search query to filter emails |
Implementation Reference
- handlers/gmail.ts:31-48 (handler)The main handler function that validates the input arguments using isListEmailsArgs and invokes the GoogleGmail instance's listEmails method with labelIds, maxResults, and query parameters. It formats and returns the result as MCP content.export async function handleGmailListEmails( args: any, googleGmailInstance: GoogleGmail ) { if (!isListEmailsArgs(args)) { throw new Error("Invalid arguments for google_gmail_list_emails"); } const { labelIds, maxResults, query } = args; const result = await googleGmailInstance.listEmails( labelIds, maxResults, query ); return { content: [{ type: "text", text: result }], isError: false, }; }
- tools/gmail/index.ts:12-33 (schema)Defines the Tool schema including name, description, and detailed inputSchema for parameters labelIds (array of strings), maxResults (number), and query (string).export const LIST_EMAILS_TOOL: Tool = { name: "google_gmail_list_emails", description: "List emails from a specific label or folder", inputSchema: { type: "object", properties: { labelIds: { type: "array", items: { type: "string" }, description: "Label IDs to filter messages (e.g., 'INBOX', 'SENT')", }, maxResults: { type: "number", description: "Maximum number of emails to return", }, query: { type: "string", description: "Search query to filter emails", }, }, }, };
- server-setup.ts:139-143 (registration)Registers the tool handler in the MCP server's request handler switch statement, routing calls to the specific handleGmailListEmails function.case "google_gmail_list_emails": return await gmailHandlers.handleGmailListEmails( args, googleGmailInstance );
- tools/index.ts:14-16 (registration)Includes the Gmail tools (including google_gmail_list_emails) in the main tools export array by spreading the gmailTools array.// Gmail tools ...gmailTools,