get-emails
Retrieve emails from an inbox based on Gmail search queries or label IDs. Specify maximum results to fetch filtered messages efficiently via the MCP server.
Instructions
Get emails from inbox
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| labelIds | No | Array of label IDs to filter by | |
| maxResults | No | Maximum number of emails to retrieve (default: 10) | |
| query | No | Gmail search query to filter emails |
Implementation Reference
- src/tools.ts:123-162 (handler)The handler function for the 'get-emails' tool. It uses the Composio toolset to execute the 'GMAIL_GET_EMAILS' action with the provided parameters, processes the response to extract email snippets and IDs, formats them into a list, and returns a formatted text response 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:119-123 (schema)The registration call including the input schema for 'get-emails' tool, defining optional parameters maxResults, query, and labelIds using Zod for validation.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) => {
- src/tools.ts:119-162 (registration)The full server.tool registration for the 'get-emails' tool within the registerTools function, including 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)}` }], }; } });