Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

update_template_version

Modify email template versions in SendGrid by updating content, subject lines, and activation status to refine email campaigns.

Instructions

Update the content and settings of a template version

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_idYesID of the template
version_idYesID of the version to update
nameNoNew name for this version
subjectNoEmail subject line (supports Handlebars)
html_contentNoHTML content of the email template
plain_contentNoPlain text version
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

  • Handler function that performs PATCH request to SendGrid API to update the specified template version with provided parameters, including read-only check, input validation, and JSON parsing for test_data.
    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) }] };
    },
  • Zod input schema defining parameters for updating a template version, including template_id, version_id, and optional fields like name, subject, html_content, etc.
    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/index.ts:20-23 (registration)
    Main MCP server registration loop that registers all tools from allTools, including update_template_version, using server.registerTool.
    // Register all tools
    for (const [name, tool] of Object.entries(allTools)) {
      server.registerTool(name, tool.config as any, tool.handler as any);
    }
  • Aggregation of all tool sets into allTools object, including templateTools which contains update_template_version.
    export const allTools = {
      ...automationTools,
      ...campaignTools,
      ...contactTools,
      ...mailTools,
      ...miscTools,
      ...statsTools,
      ...templateTools,
  • Tool definition and registration within templateTools object export.
    update_template_version: {
      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"),
        },
      },
      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) }] };
      },
    },

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