Skip to main content
Glama
mailtrap

MCP Mailtrap Server

Official
by mailtrap

create-template

Destructive

Create email templates for transactional emails with customizable HTML, text content, and categories to streamline email communication workflows.

Instructions

Create a new email template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the template
subjectYesEmail subject line
htmlNoHTML content of the template (optional)
textNoPlain text version of the template (optional)
categoryNoTemplate category (optional, defaults to 'General')

Implementation Reference

  • The handler function for the 'create-template' tool. It creates a new email template using the Mailtrap API client, validates inputs, handles errors, and returns success or error messages.
    import { CreateTemplateRequest } from "../../types/mailtrap";
    import { client } from "../../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,
        };
      }
    }
    
    export default createTemplate;
  • The input schema for the 'create-template' tool, defining properties like name, subject, html, text, category with required fields.
    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, linking schema and handler.
    {
      name: "create-template",
      description: "Create a new email template",
      inputSchema: createTemplateSchema,
      handler: createTemplate,
      annotations: {
        destructiveHint: true,
      },
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description states 'Create a new email template' which aligns with the destructiveHint: true annotation (creation is a write operation). However, it adds minimal behavioral context beyond what the annotation already provides - no information about permissions needed, whether templates are immediately available for use, rate limits, or what happens on success/failure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core purpose without unnecessary words. It's appropriately sized for a creation operation and gets straight to the point with zero wasted verbiage.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a creation tool with destructiveHint annotation and no output schema, the description is minimally adequate. It identifies what's being created but doesn't address what the tool returns, how to verify success, or integration with related operations. The context signals show this is a moderately complex tool (5 parameters) that would benefit from more complete guidance.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, all parameters are well-documented in the schema itself. The description adds no parameter-specific information beyond the general concept of creating an email template. This meets the baseline expectation when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Create a new email template' clearly states the action (create) and resource (email template), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'update-template' beyond the basic verb difference, missing an opportunity to clarify that this is for initial creation rather than modification.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'update-template' or 'list-templates'. It doesn't mention prerequisites, dependencies, or contextual factors that would help an agent choose between this and sibling tools in the email template management workflow.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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