UNPKG

@sinch/mcp

Version:

Sinch MCP server

49 lines 2.85 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 utils_1 = require("../../utils"); const registerListEmailTemplates = (server, tags) => { if (!(0, utils_1.hasMatchingTag)(['all', 'email', 'notification'], tags)) { return; } server.tool('list-email-templates', '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') } }); if (!response.ok) { return new types_1.PromptResponse(`Mailgun API error: ${response.status} ${response.statusText}`).promptResponse; } let responseData; try { responseData = await response.json(); } catch (error) { return new types_1.PromptResponse(`Failed to parse JSON response: ${error}`).promptResponse; } let reply = `The following templates must be presented as an array ALL their data in 3 columns: Name, Description and Creation Date. Do not omit anything.\n\n`; reply += `Found ${responseData.items.length} Email templates for domain "${credentials.domain}":\n\n`; reply += '| Name | Description | Creation Date |\n'; reply += '|------|-------------|---------------|\n'; for (const template of responseData.items) { reply += `| ${template.name} | ${template.description || '(No description)'} | ${template.createdAt ? new Date(template.createdAt).toISOString() : ''} |\n`; } return new types_1.PromptResponse(reply).promptResponse; }; exports.listEmailTemplatesHandler = listEmailTemplatesHandler; //# sourceMappingURL=list-email-templates.js.map