get-threads
Retrieve email threads from Gmail using a search query and specify the maximum number of results. Integrates with the Meme MCP Server for meme generation workflows.
Instructions
Get email threads
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | Maximum number of threads to retrieve | |
| query | No | Gmail search query to filter threads |
Implementation Reference
- src/tools.ts:447-486 (handler)The asynchronous handler function that implements the core logic for the 'get-threads' tool. It executes 'GMAIL_GET_THREADS' action via toolset, processes the threads into a formatted list, and returns a text response.}, async (args, extra) => { try { const userAddress = "default-user"; const result = await toolset.executeAction({ action: "GMAIL_GET_THREADS", entityId: userAddress, params: args }); if (result.successful) { const threads = result.data?.response_data as any; const threadList = threads.threads?.map((thread: any) => `• Thread ${thread.id} (${thread.snippet})` ).join('\n') || 'No threads found'; return { content: [{ type: "text", text: `🧵 Threads retrieved successfully!\n\n${threadList}\n\nTotal: ${threads.threads?.length || 0} threads` }], }; } else { return { content: [{ type: "text", text: `❌ Failed to get threads: ${result.error || 'Unknown error'}` }], }; } } catch (error) { console.error('Error getting threads:', error); return { content: [{ type: "text", text: `Error getting threads: ${error instanceof Error ? error.message : String(error)}` }], }; } });
- src/tools.ts:445-446 (schema)Input schema defined using Zod for validating parameters: optional maxResults (number) and query (string).maxResults: z.number().optional().describe("Maximum number of threads to retrieve"), query: z.string().optional().describe("Gmail search query to filter threads"),
- src/tools.ts:444-486 (registration)Registration of the 'get-threads' tool using server.tool(), including description, input schema, and inline handler function.server.tool("get-threads", "Get email threads", { maxResults: z.number().optional().describe("Maximum number of threads to retrieve"), query: z.string().optional().describe("Gmail search query to filter threads"), }, async (args, extra) => { try { const userAddress = "default-user"; const result = await toolset.executeAction({ action: "GMAIL_GET_THREADS", entityId: userAddress, params: args }); if (result.successful) { const threads = result.data?.response_data as any; const threadList = threads.threads?.map((thread: any) => `• Thread ${thread.id} (${thread.snippet})` ).join('\n') || 'No threads found'; return { content: [{ type: "text", text: `🧵 Threads retrieved successfully!\n\n${threadList}\n\nTotal: ${threads.threads?.length || 0} threads` }], }; } else { return { content: [{ type: "text", text: `❌ Failed to get threads: ${result.error || 'Unknown error'}` }], }; } } catch (error) { console.error('Error getting threads:', error); return { content: [{ type: "text", text: `Error getting threads: ${error instanceof Error ? error.message : String(error)}` }], }; } });