UNPKG

@sinch/mcp

Version:

Sinch MCP server

59 lines 3.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listEmailTemplatesHandler = exports.registerListEmailTemplates = void 0; const types_1 = require("../../types"); const zod_1 = require("zod"); const mailgun_service_helper_1 = require("./utils/mailgun-service-helper"); const mailgun_tools_helper_1 = require("./utils/mailgun-tools-helper"); const utils_1 = require("../../utils"); const TOOL_KEY = 'listEmailTemplates'; const TOOL_NAME = (0, mailgun_tools_helper_1.getToolName)(TOOL_KEY); const registerListEmailTemplates = (server, tags) => { if (!(0, utils_1.matchesAnyTag)(tags, mailgun_tools_helper_1.toolsConfig[TOOL_KEY].tags)) return; server.tool(TOOL_NAME, 'Get a list of Email templates from Mailgun for a specific domain. Note that the Messaging templates (omni-channel or channel-specific such as WhatsApp) are NOT included in this list - they can be found with another tool: list-messaging-templates. Do not try to use this tool to list Messaging templates, it will not work.', { domain: zod_1.z.string().optional().describe('The domain to use for sending the email. It would override the domain provided in the environment variables.') }, exports.listEmailTemplatesHandler); }; exports.registerListEmailTemplates = registerListEmailTemplates; const listEmailTemplatesHandler = async ({ domain }) => { const maybeCredentials = await (0, mailgun_service_helper_1.getMailgunCredentials)(domain); if ((0, utils_1.isPromptResponse)(maybeCredentials)) { return maybeCredentials.promptResponse; } const credentials = maybeCredentials; const url = `https://api.mailgun.net/v3/${credentials.domain}/templates`; const response = await fetch(url, { headers: { 'Authorization': 'Basic ' + Buffer.from(`api:${credentials.apiKey}`).toString('base64'), 'User-Agent': (0, utils_1.formatUserAgent)(TOOL_NAME, (0, mailgun_tools_helper_1.sha256)(credentials.apiKey)), } }); if (!response.ok) { return new types_1.PromptResponse(JSON.stringify({ success: false, error: `Mailgun API error: ${response.status} ${response.statusText}` })).promptResponse; } let responseData; try { responseData = await response.json(); } catch (error) { return new types_1.PromptResponse(JSON.stringify({ success: false, error: error instanceof Error ? error.message : String(error) })).promptResponse; } return new types_1.PromptResponse(JSON.stringify({ templates: responseData.items.map(template => ({ id: template.id, name: template.name, description: template.description || null, createdAt: template.createdAt ? new Date(template.createdAt).toISOString() : null })), total_count: responseData.items.length })).promptResponse; }; exports.listEmailTemplatesHandler = listEmailTemplatesHandler; //# sourceMappingURL=list-email-templates.js.map