UNPKG

@sinch/mcp

Version:

Sinch MCP server

62 lines 2.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listAllAppsHandler = exports.registerListAllApps = void 0; const utils_1 = require("../../utils"); const format_list_all_apps_response_1 = require("./utils/format-list-all-apps-response"); const conversation_service_helper_1 = require("./utils/conversation-service-helper"); const conversation_tools_helper_1 = require("./utils/conversation-tools-helper"); const types_1 = require("../../types"); const sdk_client_1 = require("@sinch/sdk-client"); const TOOL_KEY = 'listConversationApps'; const TOOL_NAME = (0, conversation_tools_helper_1.getToolName)(TOOL_KEY); const registerListAllApps = (server, tags) => { if (!(0, utils_1.matchesAnyTag)(tags, conversation_tools_helper_1.toolsConfig[TOOL_KEY].tags)) return; server.tool(TOOL_NAME, 'Get a list of all Conversation apps in the account. Apps are created and configured in the Sinch Dashboard or with the Conversation API. The App is the entity that holds the credentials related to the various channels', exports.listAllAppsHandler); }; exports.registerListAllApps = registerListAllApps; const listAllAppsHandler = async () => { const maybeService = (0, conversation_service_helper_1.getConversationService)(TOOL_NAME); if ((0, utils_1.isPromptResponse)(maybeService)) { return maybeService.promptResponse; } const conversationService = maybeService; const supportedRegions = Object.values(sdk_client_1.SupportedConversationRegion); try { const allApps = []; const errors = []; for (const region of supportedRegions) { try { (0, conversation_service_helper_1.setConversationRegion)(region, conversationService); const response = await conversationService.app.list({}); const formatted = (0, format_list_all_apps_response_1.formatListAllAppsResponse)(response); if (formatted.apps && formatted.apps.length > 0) { allApps.push(...formatted.apps.map((app) => ({ ...app, region }))); } } catch (error) { errors.push({ region, error: error instanceof Error ? error.message : 'Unknown error' }); } } return new types_1.PromptResponse(JSON.stringify({ success: errors.length === 0, apps: allApps, total_count: allApps.length, ...(errors.length > 0 && { errors }) })).promptResponse; } catch (error) { return new types_1.PromptResponse(JSON.stringify({ success: false, error: error instanceof Error ? error.message : 'Unknown error' })).promptResponse; } }; exports.listAllAppsHandler = listAllAppsHandler; //# sourceMappingURL=list-all-apps.js.map