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
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-emails"
}
}Input 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)}` }], }; } });