get-emails
Retrieve emails from your inbox using search queries, label filters, and result limits to organize and access messages efficiently.
Instructions
Get emails from inbox
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | Maximum number of emails to retrieve (default: 10) | |
| query | No | Gmail search query to filter emails | |
| labelIds | No | Array of label IDs to filter by |
Implementation Reference
- src/tools.ts:123-162 (handler)Handler function that executes the GMAIL_GET_EMAILS action via VercelAIToolSet, formats the email list from snippets and IDs, and returns a text response with success or error message.}, async (args, extra) => { try { const userAddress = "default-user"; const result = await toolset.executeAction({ action: "GMAIL_GET_EMAILS", entityId: userAddress, params: args }); if (result.successful) { const emails = result.data?.response_data as any; const emailList = emails.messages?.map((email: any) => `• ${email.snippet} (${email.id})` ).join('\n') || 'No emails found'; return { content: [{ type: "text", text: `📧 Emails retrieved successfully!\n\n${emailList}\n\nTotal: ${emails.messages?.length || 0} emails` }], }; } else { return { content: [{ type: "text", text: `❌ Failed to get emails: ${result.error || 'Unknown error'}` }], }; } } catch (error) { console.error('Error getting emails:', error); return { content: [{ type: "text", text: `Error getting emails: ${error instanceof Error ? error.message : String(error)}` }], }; } });
- src/tools.ts:120-122 (schema)Input schema using Zod for parameters: maxResults (optional number), query (optional string), labelIds (optional string array). No output schema defined; returns text content.maxResults: z.number().optional().describe("Maximum number of emails to retrieve (default: 10)"), query: z.string().optional().describe("Gmail search query to filter emails"), labelIds: z.array(z.string()).optional().describe("Array of label IDs to filter by"),
- src/tools.ts:119-162 (registration)Registration of the 'get-emails' tool using McpServer.tool method within registerTools function, specifying name, description, input schema, and inline handler.server.tool("get-emails", "Get emails from inbox", { maxResults: z.number().optional().describe("Maximum number of emails to retrieve (default: 10)"), query: z.string().optional().describe("Gmail search query to filter emails"), labelIds: z.array(z.string()).optional().describe("Array of label IDs to filter by"), }, async (args, extra) => { try { const userAddress = "default-user"; const result = await toolset.executeAction({ action: "GMAIL_GET_EMAILS", entityId: userAddress, params: args }); if (result.successful) { const emails = result.data?.response_data as any; const emailList = emails.messages?.map((email: any) => `• ${email.snippet} (${email.id})` ).join('\n') || 'No emails found'; return { content: [{ type: "text", text: `📧 Emails retrieved successfully!\n\n${emailList}\n\nTotal: ${emails.messages?.length || 0} emails` }], }; } else { return { content: [{ type: "text", text: `❌ Failed to get emails: ${result.error || 'Unknown error'}` }], }; } } catch (error) { console.error('Error getting emails:', error); return { content: [{ type: "text", text: `Error getting emails: ${error instanceof Error ? error.message : String(error)}` }], }; } });