search-emails
Find specific emails in Gmail by using search queries like 'from:example@gmail.com', 'subject:meeting', or 'is:unread' to locate messages based on sender, subject, or status.
Instructions
Search emails using Gmail search syntax
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Gmail search query (e.g., 'from:example@gmail.com', 'subject:meeting', 'is:unread') | |
| maxResults | No | Maximum number of results to return |
Implementation Reference
- src/tools.ts:492-531 (handler)The async handler function that implements the core logic of the 'search-emails' tool. It uses the Composio VercelAIToolSet to execute the 'GMAIL_SEARCH_EMAILS' action, processes the response to format a list of matching emails with snippets and IDs, and returns a structured text response or error message.}, async (args, extra) => { try { const userAddress = "default-user"; const result = await toolset.executeAction({ action: "GMAIL_SEARCH_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 matching your search'; return { content: [{ type: "text", text: `🔍 Search results for "${args.query}":\n\n${emailList}\n\nTotal: ${emails.messages?.length || 0} emails found` }], }; } else { return { content: [{ type: "text", text: `❌ Failed to search emails: ${result.error || 'Unknown error'}` }], }; } } catch (error) { console.error('Error searching emails:', error); return { content: [{ type: "text", text: `Error searching emails: ${error instanceof Error ? error.message : String(error)}` }], }; } });
- src/tools.ts:489-492 (schema)The Zod schema defining the input parameters for the 'search-emails' tool: 'query' (required string for Gmail search syntax) and 'maxResults' (optional number). This is passed as the third argument to server.tool.server.tool("search-emails", "Search emails using Gmail search syntax", { query: z.string().describe("Gmail search query (e.g., 'from:example@gmail.com', 'subject:meeting', 'is:unread')"), maxResults: z.number().optional().describe("Maximum number of results to return"), }, async (args, extra) => {
- src/tools.ts:489-489 (registration)The registration of the 'search-emails' tool using server.tool, specifying the name, description, and referencing the schema and handler.server.tool("search-emails", "Search emails using Gmail search syntax", {