Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

create_html_template

Generate email templates with HTML content and Handlebars support for SendGrid campaigns. Create templates with subject lines, plain text versions, and test data in a single operation.

Instructions

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

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "html_content": { "description": "Complete HTML email template (supports Handlebars)", "type": "string" }, "plain_content": { "description": "Plain text version (will auto-generate if not provided)", "type": "string" }, "subject": { "description": "Email subject line (supports Handlebars like {{firstName}})", "type": "string" }, "template_name": { "description": "Name of the template", "type": "string" }, "test_data": { "description": "JSON string with test data for preview (e.g., '{\"firstName\":\"John\",\"company\":\"Acme\"}')", "type": "string" }, "version_name": { "description": "Name for the initial version", "type": "string" } }, "required": [ "template_name", "version_name", "subject", "html_content" ], "type": "object" }

Implementation Reference

  • The handler function that implements the core logic of the create_html_template tool. It sequentially creates a new dynamic template and then an active version with the provided HTML, subject, and optional plain text/test data using SendGrid's API. Includes read-only mode check, error handling with cleanup, and detailed success response.
    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'}` }] }; } },
  • Zod-based input schema defining parameters for the create_html_template tool: required template_name, version_name, subject, html_content; optional plain_content and test_data.
    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\"}')") },
  • Registration of templateTools (including create_html_template) into the aggregated allTools export used for MCP tool exposure.
    ...templateTools,
  • src/tools/index.ts:7-7 (registration)
    Import of templateTools from templates.ts where create_html_template is defined.
    import { templateTools } from "./templates.js";
  • Full tool config including title, description, and input schema for 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\"}')") }, },

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