Skip to main content
Glama
mailtrap

MCP Mailtrap Server

Official
by mailtrap

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
NameRequiredDescriptionDefault
categoryNoTemplate category (optional, defaults to 'General')
htmlNoHTML content of the template (optional)
nameYesName of the template
subjectYesEmail subject line
textNoPlain 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, }, },
  • 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, };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mailtrap/mailtrap-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server