create_template
Create new email templates in SendGrid for marketing campaigns, transactional emails, or automated communications by defining HTML content, plain text versions, and default subject lines.
Instructions
Create a new email template in SendGrid
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the template | |
| subject | Yes | Default subject line for the template | |
| html_content | Yes | HTML content of the template | |
| plain_content | Yes | Plain text content of the template |
Implementation Reference
- src/services/sendgrid.ts:156-202 (handler)Core handler implementing the creation of a dynamic SendGrid email template and its first version using the SendGrid API.async createTemplate(params: { name: string; html_content: string; plain_content: string; subject: string; }): Promise<SendGridTemplate> { const [response] = await this.client.request({ method: 'POST', url: '/v3/templates', body: { name: params.name, generation: 'dynamic' } }); const templateId = (response.body as { id: string }).id; // Create the first version of the template const [versionResponse] = await this.client.request({ method: 'POST', url: `/v3/templates/${templateId}/versions`, body: { template_id: templateId, name: `${params.name} v1`, subject: params.subject, html_content: params.html_content, plain_content: params.plain_content, active: 1 } }); return { id: templateId, name: params.name, generation: 'dynamic', updated_at: new Date().toISOString(), versions: [{ id: (versionResponse.body as { id: string }).id, template_id: templateId, active: 1, name: `${params.name} v1`, html_content: params.html_content, plain_content: params.plain_content, subject: params.subject }] }; }
- src/tools/index.ts:130-155 (registration)Tool registration in getToolDefinitions array, defining name, description, and input schema for 'create_template'.{ name: 'create_template', description: 'Create a new email template in SendGrid', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the template' }, subject: { type: 'string', description: 'Default subject line for the template' }, html_content: { type: 'string', description: 'HTML content of the template' }, plain_content: { type: 'string', description: 'Plain text content of the template' } }, required: ['name', 'subject', 'html_content', 'plain_content'] } },
- src/tools/index.ts:411-413 (handler)MCP tool handler in handleToolCall that invokes the SendGrid service's createTemplate method and formats the response.case 'create_template': const template = await service.createTemplate(args); return { content: [{ type: 'text', text: `Template "${args.name}" created with ID: ${template.id}` }] };
- src/tools/index.ts:133-154 (schema)Input schema defining parameters for the create_template tool.inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the template' }, subject: { type: 'string', description: 'Default subject line for the template' }, html_content: { type: 'string', description: 'HTML content of the template' }, plain_content: { type: 'string', description: 'Plain text content of the template' } }, required: ['name', 'subject', 'html_content', 'plain_content'] }