Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

Create Complete HTML Template

create_html_template

Create an email template with HTML content, subject line, and version in one step, supporting Handlebars variables and optional plain text and test data.

Instructions

Create a new template with HTML content in one step - perfect for AI-generated designs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_nameYesName of the template
version_nameYesName for the initial version
subjectYesEmail subject line (supports Handlebars like {{firstName}})
html_contentYesComplete HTML email template (supports Handlebars)
plain_contentNoPlain text version (will auto-generate if not provided)
test_dataNoJSON string with test data for preview (e.g., '{"firstName":"John","company":"Acme"}')

Implementation Reference

  • Handler function that executes the create_html_template tool logic. Creates a SendGrid dynamic template and version with HTML content in one step. Handles template creation, version creation with subject/html/plain_content, test data parsing, and returns detailed success response with template/version IDs.
        handler: async ({ 
          template_name, 
          version_name, 
          subject, 
          html_content, 
          plain_content,
          test_data 
        }: { 
          template_name: string; 
          version_name: string; 
          subject: string; 
          html_content: string; 
          plain_content?: string;
          test_data?: string;
        }): Promise<ToolResult> => {
          const readOnlyCheck = checkReadOnlyMode();
          if (readOnlyCheck.blocked) {
            return { content: [{ type: "text", text: readOnlyCheck.message! }] };
          }
          
          try {
            // Step 1: Create the template
            const template = await makeRequest("https://api.sendgrid.com/v3/templates", {
              method: "POST",
              body: JSON.stringify({
                name: template_name,
                generation: "dynamic"
              }),
            });
            
            const template_id = template.id;
            
            // Step 2: Create the version with HTML content
            const versionData: any = {
              name: version_name,
              subject: subject,
              html_content: html_content,
              active: 1,
              generate_plain_content: !plain_content, // Auto-generate if no plain content provided
            };
            
            if (plain_content) {
              versionData.plain_content = plain_content;
            }
            
            if (test_data) {
              try {
                versionData.test_data = JSON.parse(test_data);
              } catch (error) {
                // Delete the template we just created since version failed
                await makeRequest(`https://api.sendgrid.com/v3/templates/${template_id}`, {
                  method: "DELETE",
                });
                return { content: [{ type: "text", text: "Error: test_data must be valid JSON. Template creation cancelled." }] };
              }
            }
            
            const version = await makeRequest(`https://api.sendgrid.com/v3/templates/${template_id}/versions`, {
              method: "POST",
              body: JSON.stringify(versionData),
            });
            
            return { 
              content: [{ 
                type: "text", 
                text: `✅ HTML Template created successfully!
    
    📧 Template Details:
    - Template ID: ${template_id}
    - Template Name: ${template_name}
    - Version ID: ${version.id}
    - Version Name: ${version_name}
    - Subject: ${subject}
    - Status: Active and ready to use
    
    🚀 Usage:
    You can now send emails using this template with the Mail API:
    - Use template_id: "${template_id}"
    - Include dynamic_template_data with your Handlebars variables
    
    🔗 Quick Actions:
    - View in SendGrid UI: https://mc.sendgrid.com/dynamic-templates/${template_id}
    - Test the template with sample data in the SendGrid editor
    
    ${JSON.stringify({ template, version }, null, 2)}` 
              }] 
            };
          } catch (error: any) {
            return { 
              content: [{ 
                type: "text", 
                text: `❌ Error creating template: ${error.message || 'Unknown error occurred'}` 
              }] 
            };
          }
        },
  • Input schema definitions for create_html_template using Zod. Defines required fields: template_name, version_name, subject, html_content. Optional fields: plain_content, test_data.
    create_html_template: {
      config: {
        title: "Create Complete HTML Template",
        description: "Create a new template with HTML content in one step - perfect for AI-generated designs",
        inputSchema: {
          template_name: z.string().describe("Name of the template"),
          version_name: z.string().describe("Name for the initial version"),
          subject: z.string().describe("Email subject line (supports Handlebars like {{firstName}})"),
          html_content: z.string().describe("Complete HTML email template (supports Handlebars)"),
          plain_content: z.string().optional().describe("Plain text version (will auto-generate if not provided)"),
          test_data: z.string().optional().describe("JSON string with test data for preview (e.g., '{\"firstName\":\"John\",\"company\":\"Acme\"}')")
        },
  • src/index.ts:17-21 (registration)
    Registration of all tools (including create_html_template) with the MCP server. Iterates over allTools and calls server.registerTool for each.
      server.registerResource(uri, uri, resource.config, resource.handler);
    }
    
    // Register all tools
    for (const [name, tool] of Object.entries(allTools)) {
  • Consolidation of all tool definitions into a single allTools object, including spread of templateTools which contains create_html_template.
    export const allTools = {
      ...automationTools,
      ...campaignTools,
      ...contactTools,
      ...mailTools,
      ...miscTools,
      ...statsTools,
      ...templateTools,
    };
Behavior2/5

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

With no annotations, the description bears full burden for behavioral disclosure. It only states the action without mentioning side effects, auth needs, rate limits, or implications of auto-generating plain content. The schema's auto-generation note is not echoed in the description, leaving gaps.

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, focused sentence with no wasted words. It is appropriately sized for the tool's simplicity.

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?

Given 6 parameters, 4 required, and no output schema, the description is too brief. It fails to explain the template-version relationship, how the tool integrates with the broader template system, or what success looks like.

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 description coverage is 100%, so the description adds minimal value beyond schema. It includes no parameter details, meeting the baseline of 3 for high coverage.

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 tool creates a template with HTML content in one step, distinguishing it from generic template creation or version creation siblings. 'Perfect for AI-generated designs' adds specific context.

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

Usage Guidelines3/5

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

The description implies usage for AI-generated designs but lacks explicit guidance on when to use versus alternatives like create_template or create_template_version. No 'when not to use' or exclusionary criteria are provided.

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