Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

create_template_version

Add a new version to an existing email template with updated HTML content, subject line, and settings for testing and deployment.

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 that executes the tool: checks read-only mode, constructs version data, handles optional fields, parses test_data if provided, and makes POST request to SendGrid API to create template version.
    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}` }] }; },
  • Tool configuration including title, description, and Zod-based input schema defining parameters for creating a 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"), }, },
  • Aggregates all individual tool modules (including templateTools containing create_template_version) into allTools export.
    export const allTools = { ...automationTools, ...campaignTools, ...contactTools, ...mailTools, ...miscTools, ...statsTools, ...templateTools, };
  • src/index.ts:21-23 (registration)
    Registers all tools from allTools to the MCP server using server.registerTool, including create_template_version.
    for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }

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