update_template_version
Modify email template versions by updating content, subject lines, and activation status to maintain current messaging across email campaigns.
Instructions
Update the content and settings of a template version
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| active | No | Set as active version (1 = active, 0 = inactive) | |
| generate_plain_content | No | Auto-generate plain text from HTML | |
| html_content | No | HTML content of the email template | |
| name | No | New name for this version | |
| plain_content | No | Plain text version | |
| subject | No | Email subject line (supports Handlebars) | |
| template_id | Yes | ID of the template | |
| test_data | No | JSON string of test data for Handlebars variables | |
| version_id | Yes | ID of the version to update |
Implementation Reference
- src/tools/templates.ts:213-266 (handler)The main handler function implementing the tool logic: checks read-only mode, builds update payload from provided parameters, validates test_data JSON if present, ensures at least one field to update, and performs PATCH request to SendGrid API endpoint /templates/{template_id}/versions/{version_id}.handler: async ({ template_id, version_id, name, subject, html_content, plain_content, active, generate_plain_content, test_data }: { template_id: string; version_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 = {}; if (name !== undefined) versionData.name = name; if (subject !== undefined) versionData.subject = subject; if (html_content !== undefined) versionData.html_content = html_content; if (plain_content !== undefined) versionData.plain_content = plain_content; if (active !== undefined) versionData.active = active; if (generate_plain_content !== undefined) versionData.generate_plain_content = generate_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" }] }; } } if (Object.keys(versionData).length === 0) { return { content: [{ type: "text", text: "Error: Please provide at least one field to update" }] }; } const result = await makeRequest(`https://api.sendgrid.com/v3/templates/${template_id}/versions/${version_id}`, { method: "PATCH", body: JSON.stringify(versionData), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; },
- src/tools/templates.ts:198-212 (schema)Tool configuration including Zod inputSchema defining all optional parameters for updating template version content and settings.config: { title: "Update Template Version", description: "Update the content and settings of a template version", inputSchema: { template_id: z.string().describe("ID of the template"), version_id: z.string().describe("ID of the version to update"), name: z.string().optional().describe("New name for this version"), subject: z.string().optional().describe("Email subject line (supports Handlebars)"), html_content: z.string().optional().describe("HTML content of the email template"), plain_content: z.string().optional().describe("Plain text version"), active: z.number().optional().describe("Set as active version (1 = active, 0 = inactive)"), generate_plain_content: z.boolean().optional().describe("Auto-generate plain text from HTML"), test_data: z.string().optional().describe("JSON string of test data for Handlebars variables"), }, },
- src/tools/index.ts:7-16 (registration)Aggregates all tool modules including templateTools (which contains update_template_version) into single allTools export used by MCP server.import { templateTools } from "./templates.js"; export const allTools = { ...automationTools, ...campaignTools, ...contactTools, ...mailTools, ...miscTools, ...statsTools, ...templateTools,
- src/index.ts:20-23 (registration)Final MCP server registration loop that registers every tool from allTools (including update_template_version) by calling 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); }