list_templates
Retrieve all email templates from your Mailchimp account to review, select, or manage your email marketing designs.
Instructions
List all templates in your Mailchimp account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/index.ts:825-846 (handler)The main tool handler in handleToolCall that processes the list_templates tool call, invokes the service method, maps and formats the templates for response.case "list_templates": const templates = await service.listTemplates(); return { content: [ { type: "text", text: JSON.stringify( templates.templates.map((t) => ({ id: t.id, name: t.name, type: t.type, drag_and_drop: t.drag_and_drop, responsive: t.responsive, active: t.active, date_created: t.date_created, })), null, 2 ), }, ], };
- src/tools/index.ts:265-272 (registration)Tool registration in getToolDefinitions array, including name, description, and empty input schema.name: "list_templates", description: "List all templates in your Mailchimp account", inputSchema: { type: "object", properties: {}, required: [], }, },
- src/services/mailchimp.ts:232-238 (handler)The service method listTemplates that implements the core logic by calling Mailchimp API endpoint /templates with pagination.async listTemplates(): Promise<{ templates: MailchimpTemplate[] }> { return await this.makePaginatedRequest( "/templates", "date_created", "DESC" ); }
- src/services/mailchimp.ts:65-95 (helper)Helper method makePaginatedRequest used by listTemplates to fetch paginated data from Mailchimp API with sorting.private async makePaginatedRequest<T = any>( endpoint: string, sortField: string = "create_time", sortDirection: "ASC" | "DESC" = "DESC" ): Promise<T> { // Mailchimp API allows up to 1000 items per page const params = new URLSearchParams({ count: "1000", sort_field: sortField, sort_dir: sortDirection, }); const url = `${this.baseUrl}${endpoint}?${params.toString()}`; const auth = Buffer.from(`anystring:${this.apiKey}`).toString("base64"); const response = await fetch(url, { headers: { Authorization: `Basic ${auth}`, "Content-Type": "application/json", }, }); if (!response.ok) { const errorText = await response.text(); throw new Error( `Mailchimp API Error: ${response.status} ${response.statusText} - ${errorText}` ); } return response.json() as Promise<T>; }