get-email-templates
Retrieve all available email templates from the SMTP MCP Server for use in automated email campaigns with variable substitution.
Instructions
Get all email templates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/requestHandler.ts:406-421 (handler)The main handler function for the 'get-email-templates' tool. It retrieves all email templates using getEmailTemplates() from config.ts and returns them wrapped in a success response object.async function handleGetEmailTemplates() { try { const templates = await getEmailTemplates(); return { success: true, templates: templates }; } catch (error) { logToFile('Error in handleGetEmailTemplates:'); logToFile(error instanceof Error ? error.message : 'Unknown error'); return { success: false, message: error instanceof Error ? error.message : 'Unknown error' }; }
- src/tools.ts:285-292 (schema)The tool schema definition for 'get-email-templates', including name, description, and empty input schema (no parameters required)."get-email-templates": { name: "get-email-templates", description: "Get all email templates", inputSchema: { type: "object", properties: {}, required: [] }
- src/requestHandler.ts:87-88 (registration)Switch case in the CallToolRequestSchema handler that dispatches 'get-email-templates' tool calls to the handleGetEmailTemplates function.case "get-email-templates": return await handleGetEmailTemplates();
- src/index.ts:59-62 (registration)Creates the tool definitions object (including 'get-email-templates') using createToolDefinitions() and passes it to setupRequestHandlers for server registration.const TOOLS = createToolDefinitions(); // Setup request handlers await setupRequestHandlers(server, TOOLS);
- src/config.ts:204-222 (helper)Helper function getEmailTemplates() that reads all JSON template files from the templates directory and returns the list of EmailTemplate objects. Called by the tool handler.export async function getEmailTemplates(): Promise<EmailTemplate[]> { try { const files = await fs.readdir(TEMPLATES_DIR); const templates: EmailTemplate[] = []; for (const file of files) { if (file.endsWith('.json')) { const templatePath = path.join(TEMPLATES_DIR, file); const template = await fs.readJson(templatePath) as EmailTemplate; templates.push(template); } } return templates; } catch (error) { logToFile('Error reading email templates:'); return [DEFAULT_TEMPLATE, BUSINESS_TEMPLATE, NEWSLETTER_TEMPLATE]; } }