@sinch/mcp
Version:
Sinch MCP server
54 lines • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.rentNumbersHandler = exports.registerRentNumbers = void 0;
const zod_1 = require("zod");
const types_1 = require("../../types");
const utils_1 = require("../../utils");
const numbers_tools_helper_1 = require("./utils/numbers-tools-helper");
const numbers_service_helper_1 = require("./utils/numbers-service-helper");
const TOOL_KEY = 'rentNumbers';
const TOOL_NAME = (0, numbers_tools_helper_1.getToolName)(TOOL_KEY);
const registerRentNumbers = (server, tags) => {
if (!(0, utils_1.matchesAnyTag)(tags, numbers_tools_helper_1.toolsConfig[TOOL_KEY].tags))
return;
server.tool(TOOL_NAME, 'Activates a phone number that matches the search criteria provided in the request. Currently the rentAny operation works only for US LOCAL numbers', {
numbers: zod_1.z.array(zod_1.z.string()).describe('Array of phone numbers to rent. Each number should be in E.164 format with leading `+`'),
}, exports.rentNumbersHandler);
};
exports.registerRentNumbers = registerRentNumbers;
const rentNumbersHandler = async ({ numbers }) => {
const maybeService = (0, numbers_service_helper_1.getNumbersService)(TOOL_NAME);
if ((0, utils_1.isPromptResponse)(maybeService)) {
return maybeService.promptResponse;
}
const numbersService = maybeService;
const successfulRentals = [];
const failedRentals = [];
for (const number of numbers) {
try {
const response = await numbersService.rent({
phoneNumber: number,
rentNumberRequestBody: {}
});
successfulRentals.push({ number, details: response });
}
catch (error) {
failedRentals.push({
number,
error: error instanceof Error ? error.message : String(error)
});
}
}
return new types_1.PromptResponse(JSON.stringify({
success: failedRentals.length === 0,
successful_rentals: successfulRentals,
failed_rentals: failedRentals,
summary: {
total: numbers.length,
successful: successfulRentals.length,
failed: failedRentals.length
}
})).promptResponse;
};
exports.rentNumbersHandler = rentNumbersHandler;
//# sourceMappingURL=rent-numbers.js.map