Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

Create Template Version

create_template_version

Add a new version to an existing email template with HTML content, subject, and optional plain text, supporting Handlebars variables for dynamic content.

Instructions

Create a new version of a template with HTML content and settings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_idYesID of the template to add version to
nameYesName for this version
subjectYesEmail subject line (supports Handlebars)
html_contentYesHTML content of the email template (supports Handlebars)
plain_contentNoPlain text version (optional)
activeNoSet as active version (1 = active, 0 = inactive)
generate_plain_contentNoAuto-generate plain text from HTML
test_dataNoJSON string of test data for Handlebars variables

Implementation Reference

  • The handler function for create_template_version. Calls SendGrid POST /v3/templates/{template_id}/versions to create a new template version with HTML content, subject, and optional plain_content, test_data, active, generate_plain_content settings. Returns version details and template_id.
    handler: async ({ 
      template_id, 
      name, 
      subject, 
      html_content, 
      plain_content, 
      active, 
      generate_plain_content, 
      test_data 
    }: { 
      template_id: string; 
      name: string; 
      subject: string; 
      html_content: string; 
      plain_content?: string; 
      active?: number; 
      generate_plain_content?: boolean; 
      test_data?: string; 
    }): Promise<ToolResult> => {
      const readOnlyCheck = checkReadOnlyMode();
      if (readOnlyCheck.blocked) {
        return { content: [{ type: "text", text: readOnlyCheck.message! }] };
      }
      
      const versionData: any = {
        name,
        subject,
        html_content,
        active: active ?? 1,
        generate_plain_content: generate_plain_content ?? true,
      };
      
      if (plain_content) {
        versionData.plain_content = plain_content;
      }
      
      if (test_data) {
        try {
          versionData.test_data = JSON.parse(test_data);
        } catch (error) {
          return { content: [{ type: "text", text: "Error: test_data must be valid JSON" }] };
        }
      }
      
      const result = await makeRequest(`https://api.sendgrid.com/v3/templates/${template_id}/versions`, {
        method: "POST",
        body: JSON.stringify(versionData),
      });
      
      return { 
        content: [{ 
          type: "text", 
          text: `Template version created successfully!\n\n${JSON.stringify(result, null, 2)}\n\nYou can now use this template with the Mail API using template_id: ${template_id}` 
        }] 
      };
    },
  • Input schema for create_template_version defining required fields (template_id, name, subject, html_content) and optional fields (plain_content, active with default 1, generate_plain_content with default true, test_data as JSON string).
    config: {
      title: "Create Template Version",
      description: "Create a new version of a template with HTML content and settings",
      inputSchema: {
        template_id: z.string().describe("ID of the template to add version to"),
        name: z.string().describe("Name for this version"),
        subject: z.string().describe("Email subject line (supports Handlebars)"),
        html_content: z.string().describe("HTML content of the email template (supports Handlebars)"),
        plain_content: z.string().optional().describe("Plain text version (optional)"),
        active: z.number().optional().default(1).describe("Set as active version (1 = active, 0 = inactive)"),
        generate_plain_content: z.boolean().optional().default(true).describe("Auto-generate plain text from HTML"),
        test_data: z.string().optional().describe("JSON string of test data for Handlebars variables"),
      },
    },
  • The tool definition within the templateTools export object. The key 'create_template_version' is the tool name registered with the MCP server.
    create_template_version: {
      config: {
        title: "Create Template Version",
        description: "Create a new version of a template with HTML content and settings",
        inputSchema: {
          template_id: z.string().describe("ID of the template to add version to"),
          name: z.string().describe("Name for this version"),
          subject: z.string().describe("Email subject line (supports Handlebars)"),
          html_content: z.string().describe("HTML content of the email template (supports Handlebars)"),
          plain_content: z.string().optional().describe("Plain text version (optional)"),
          active: z.number().optional().default(1).describe("Set as active version (1 = active, 0 = inactive)"),
          generate_plain_content: z.boolean().optional().default(true).describe("Auto-generate plain text from HTML"),
          test_data: z.string().optional().describe("JSON string of test data for Handlebars variables"),
        },
      },
      handler: async ({ 
        template_id, 
        name, 
        subject, 
        html_content, 
        plain_content, 
        active, 
        generate_plain_content, 
        test_data 
      }: { 
        template_id: string; 
        name: string; 
        subject: string; 
        html_content: string; 
        plain_content?: string; 
        active?: number; 
        generate_plain_content?: boolean; 
        test_data?: string; 
      }): Promise<ToolResult> => {
        const readOnlyCheck = checkReadOnlyMode();
        if (readOnlyCheck.blocked) {
          return { content: [{ type: "text", text: readOnlyCheck.message! }] };
        }
        
        const versionData: any = {
          name,
          subject,
          html_content,
          active: active ?? 1,
          generate_plain_content: generate_plain_content ?? true,
        };
        
        if (plain_content) {
          versionData.plain_content = plain_content;
        }
        
        if (test_data) {
          try {
            versionData.test_data = JSON.parse(test_data);
          } catch (error) {
            return { content: [{ type: "text", text: "Error: test_data must be valid JSON" }] };
          }
        }
        
        const result = await makeRequest(`https://api.sendgrid.com/v3/templates/${template_id}/versions`, {
          method: "POST",
          body: JSON.stringify(versionData),
        });
        
        return { 
          content: [{ 
            type: "text", 
            text: `Template version created successfully!\n\n${JSON.stringify(result, null, 2)}\n\nYou can now use this template with the Mail API using template_id: ${template_id}` 
          }] 
        };
      },
    },
  • src/index.ts:20-23 (registration)
    Where all tools including create_template_version are registered with the MCP server via server.registerTool(name, config, handler).
    // Register all tools
    for (const [name, tool] of Object.entries(allTools)) {
      server.registerTool(name, tool.config as any, tool.handler as any);
    }
  • Help text describing create_template_version as 'Create a new version with HTML content and settings' within the Template Version Management section.
    Template Version Management:
    - create_template_version: Create a new version with HTML content and settings
    - get_template_version: Get details of a specific template version
    - update_template_version: Update version content and settings  
    - delete_template_version: Delete a specific version
    
    AI-Friendly Tools:
    - create_html_template: Create complete template with HTML in one step (perfect for AI)
    - open_template_editor: Open SendGrid's visual editor in browser
    
    What are Dynamic Templates?
    Dynamic templates are reusable email templates that support Handlebars syntax for personalization. They're perfect for transactional emails like welcome messages, receipts, password resets, and notifications.
    
    Key Features:
    - Handlebars syntax: {{firstName}}, {{#each items}}, {{#if condition}}
    - Dynamic content replacement at send time
    - HTML and plain text versions
    - Test data for preview
    - Version management (up to 300 versions per template)
    - Visual editor integration
    
    Creating Templates with AI:
    
    1. Simple Approach - Use create_html_template:
       - Provide: template name, subject, HTML content
       - Supports Handlebars variables like {{name}}, {{company}}
       - Creates template and version in one step
    
    2. Advanced Approach - Multi-step:
       - create_template: Create base template
       - create_template_version: Add HTML content and settings
       - Allows for multiple versions and complex configurations
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavioral traits. It only mentions 'create' and 'settings', but does not address side effects, permissions, rate limits, or whether the version becomes active by default. The schema includes 'active' and 'generate_plain_content' but the description omits these details.

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

Conciseness3/5

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

The description is a single sentence, which is concise but lacks structure. It does not front-load key information or use formatting to aid scanning. It is not overly verbose, but it could be better organized.

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

Completeness2/5

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

With 8 parameters and no output schema, the description is too brief. It does not explain the return behavior, what happens when a version is created, or how 'active' and 'generate_plain_content' interact. It feels incomplete for a creation tool.

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?

Schema coverage is 100%, so baseline is 3. The description adds no additional meaning beyond the schema; it merely states 'HTML content and settings' without elaborating on optional parameters like 'test_data' or 'generate_plain_content'. It does not enhance understanding.

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

Purpose5/5

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

The description clearly states the action ('Create a new version'), the resource ('a template'), and the key content ('HTML content and settings'). It distinguishes from siblings like 'update_template_version' and 'create_template' by specifying it adds a version to an existing template.

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 (e.g., 'update_template_version' for modifying an existing version) or prerequisites (e.g., template must already exist). It lacks explicit usage context.

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/deyikong/sendgrid-mcp'

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