create-template
Create email templates with subject lines and optional HTML/text content for transactional emails and testing workflows.
Instructions
Create a new email template
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | Template category (optional, defaults to 'General') | |
| html | No | HTML content of the template (optional) | |
| name | Yes | Name of the template | |
| subject | Yes | Email subject line | |
| text | No | Plain text version of the template (optional) |
Implementation Reference
- Implementation of the createTemplate handler function that creates a new email template using Mailtrap API client.async function createTemplate({ name, subject, html, text, category, }: CreateTemplateRequest): Promise<{ content: any[]; isError?: boolean }> { try { if (!client) { throw new Error("MAILTRAP_API_TOKEN environment variable is required"); } // Validate that at least one of html or text is provided if (!html && !text) { return { content: [ { type: "text", text: "Failed to create template: At least one of 'html' or 'text' content must be provided.", }, ], isError: true, }; } const createParams: any = { name, subject, category: category || "General", }; if (html) { createParams.body_html = html; } if (text) { createParams.body_text = text; } const template = await client.templates.create(createParams); return { content: [ { type: "text", text: `Template "${name}" created successfully!\nTemplate ID: ${template.id}\nTemplate UUID: ${template.uuid}`, }, ], }; } catch (error) { console.error("Error creating template:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Failed to create template: ${errorMessage}`, }, ], isError: true, }; } }
- JSON schema definition for the input parameters of the create-template tool.const createTemplateSchema = { type: "object", properties: { name: { type: "string", description: "Name of the template", }, subject: { type: "string", description: "Email subject line", }, html: { type: "string", description: "HTML content of the template (optional)", }, text: { type: "string", description: "Plain text version of the template (optional)", }, category: { type: "string", description: "Template category (optional, defaults to 'General')", }, }, required: ["name", "subject"], additionalProperties: false, }; export default createTemplateSchema;
- src/server.ts:46-54 (registration)Registration of the 'create-template' tool in the tools array used by the MCP server.{ name: "create-template", description: "Create a new email template", inputSchema: createTemplateSchema, handler: createTemplate, annotations: { destructiveHint: true, }, },
- src/tools/templates/index.ts:1-19 (helper)Index file re-exporting the createTemplate handler and schema for use in server.ts.import createTemplateSchema from "./schemas/createTemplate"; import createTemplate from "./createTemplate"; import listTemplatesSchema from "./schemas/listTemplates"; import listTemplates from "./listTemplates"; import updateTemplateSchema from "./schemas/updateTemplate"; import updateTemplate from "./updateTemplate"; import deleteTemplateSchema from "./schemas/deleteTemplate"; import deleteTemplate from "./deleteTemplate"; export { createTemplateSchema, createTemplate, listTemplatesSchema, listTemplates, updateTemplateSchema, updateTemplate, deleteTemplateSchema, deleteTemplate, };