list-templates
Retrieve all email templates from the Mailtrap Email Sending platform to manage and reuse transactional email designs.
Instructions
List all email templates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function that lists email templates from the Mailtrap API, formats them, and returns as content blocks, handling errors appropriately.import { client } from "../../client"; async function listTemplates(): Promise<{ content: any[]; isError?: boolean }> { try { if (!client) { throw new Error("MAILTRAP_API_TOKEN environment variable is required"); } const templates = await client.templates.getList(); if (!templates || templates.length === 0) { return { content: [ { type: "text", text: "No templates found in your Mailtrap account.", }, ], }; } const templateList = templates .map( (template) => `• ${template.name} (ID: ${template.id}, UUID: ${template.uuid})\n Subject: ${template.subject}\n Category: ${template.category}\n Created: ${template.created_at}\n` ) .join("\n"); return { content: [ { type: "text", text: `Found ${templates.length} template(s):\n\n${templateList}`, }, ], }; } catch (error) { console.error("Error listing templates:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Failed to list templates: ${errorMessage}`, }, ], isError: true, }; } } export default listTemplates;
- The input schema for the list-templates tool, defining an empty object (no parameters required).const listTemplatesSchema = { type: "object", properties: {}, additionalProperties: false, }; export default listTemplatesSchema;
- src/server.ts:55-63 (registration)Registration of the 'list-templates' tool, specifying name, description, input schema, handler function, and read-only annotation.{ name: "list-templates", description: "List all email templates", inputSchema: listTemplatesSchema, handler: listTemplates, annotations: { readOnlyHint: true, }, },