List All Templates
list_templatesList all transactional templates from SendGrid, filtering by legacy or dynamic generation and setting page size up to 200.
Instructions
Retrieve all transactional templates (legacy and dynamic)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| generations | No | Filter by template generation (legacy or dynamic) | |
| page_size | No | Number of templates to return (max 200) |
Implementation Reference
- src/tools/templates.ts:6-23 (handler)The handler function for 'list_templates' that calls SendGrid API v3/templates with optional generations and page_size filters, returning the result as JSON text.
export const templateTools = { list_templates: { config: { title: "List All Templates", description: "Retrieve all transactional templates (legacy and dynamic)", inputSchema: { generations: z.string().optional().describe("Filter by template generation (legacy or dynamic)"), page_size: z.number().optional().default(50).describe("Number of templates to return (max 200)"), }, }, handler: async ({ generations, page_size }: { generations?: string; page_size?: number }): Promise<ToolResult> => { let url = `https://api.sendgrid.com/v3/templates?page_size=${page_size || 50}`; if (generations) url += `&generations=${generations}`; const result = await makeRequest(url); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, }, - src/tools/templates.ts:6-23 (schema)The inputSchema for list_templates defines optional 'generations' (string) and 'page_size' (number, default 50) parameters using Zod.
export const templateTools = { list_templates: { config: { title: "List All Templates", description: "Retrieve all transactional templates (legacy and dynamic)", inputSchema: { generations: z.string().optional().describe("Filter by template generation (legacy or dynamic)"), page_size: z.number().optional().default(50).describe("Number of templates to return (max 200)"), }, }, handler: async ({ generations, page_size }: { generations?: string; page_size?: number }): Promise<ToolResult> => { let url = `https://api.sendgrid.com/v3/templates?page_size=${page_size || 50}`; if (generations) url += `&generations=${generations}`; const result = await makeRequest(url); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, }, - src/tools/index.ts:7-7 (registration)Import of templateTools from templates.ts into the central allTools export
import { templateTools } from "./templates.js"; - src/tools/index.ts:16-16 (registration)Spread of templateTools into allTools, making list_templates available for registration
...templateTools, - src/index.ts:21-23 (registration)The MCP server registration loop that calls server.registerTool for each tool including list_templates
for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }