Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

Create Complete HTML Template

create_html_template

Create SendGrid email templates with HTML content and Handlebars variables to automate personalized email campaigns.

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 for 'create_html_template' that creates a new dynamic template and adds an active version with the provided HTML content, subject, and optional plain text/test data using SendGrid API endpoints.
        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 (Zod validation) for 'create_html_template' defining parameters: template_name, version_name, subject, html_content, plain_content (optional), test_data (optional).
    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:20-23 (registration)
    Registration of all tools (including create_html_template via allTools) to the MCP server using server.registerTool in a loop over Object.entries(allTools).
    // Register all tools
    for (const [name, tool] of Object.entries(allTools)) {
      server.registerTool(name, tool.config as any, tool.handler as any);
    }
  • Aggregation of templateTools (containing create_html_template) into allTools export via spread operator, after importing from './templates.js'.
    import { templateTools } from "./templates.js";
    
    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?

No annotations are provided, so the description carries full burden. It mentions 'in one step' suggesting efficiency but lacks critical behavioral details: whether this is a write operation (implied by 'create'), what permissions are needed, if it's idempotent, error handling, or what happens on success/failure. The description is insufficient for a mutation tool with no annotation coverage.

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

Conciseness4/5

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

The description is a single, efficient sentence that gets straight to the point without unnecessary words. It could be slightly more structured by separating purpose from context, but it's appropriately sized and front-loaded.

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?

For a mutation tool with 6 parameters, no annotations, and no output schema, the description is incomplete. It lacks behavioral transparency (e.g., side effects, permissions), usage guidelines versus siblings, and any information about return values or errors. The description doesn't compensate for the missing structured data.

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 schema fully documents all 6 parameters. The description adds no parameter-specific information beyond what's in the schema (e.g., no extra syntax, format, or constraint details). Baseline 3 is appropriate when the schema does all the parameter documentation work.

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 clearly states the tool creates a new template with HTML content in one step, specifying the resource (template) and action (create). It distinguishes from siblings like 'create_template' by emphasizing HTML content and AI-generated designs, though it doesn't explicitly contrast with 'create_template_version' which might be similar.

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 minimal guidance, only noting it's 'perfect for AI-generated designs' without explaining when to use this versus alternatives like 'create_template' or 'create_template_version'. No explicit when-not-to-use or prerequisite information is given.

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