UNPKG

typebot-mcp

Version:

[![smithery badge](https://smithery.ai/badge/@hithereiamaliff/typebot-mcp)](https://smithery.ai/server/@hithereiamaliff/typebot-mcp)

147 lines (146 loc) 5.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBot = createBot; exports.listBots = listBots; exports.getBot = getBot; exports.updateBot = updateBot; exports.deleteBot = deleteBot; exports.publishBot = publishBot; exports.unpublishBot = unpublishBot; exports.listResults = listResults; exports.startChat = startChat; const axios_1 = __importDefault(require("axios")); // Get API base URL from environment variable const getApiBaseUrl = () => { if (!process.env.TYPEBOT_API_URL) { throw new Error('TYPEBOT_API_URL environment variable is not set'); } return process.env.TYPEBOT_API_URL; }; function ensureAuth() { const header = axios_1.default.defaults.headers.common['Authorization']; if (!header) { throw new Error('No token configured. Call authenticate first or define TYPEBOT_TOKEN.'); } } async function createBot(args) { ensureAuth(); const workspaceId = args.workspaceId || process.env.TYPEBOT_WORKSPACE_ID; if (!workspaceId) { throw new Error('createBot: missing workspaceId (neither in args nor in process.env)'); } const payload = { workspaceId, typebot: { name: args.name, description: args.description, }, }; const apiBaseUrl = getApiBaseUrl(); const response = await axios_1.default.post(`${apiBaseUrl}/typebots`, payload); return response.data; } async function listBots(args = {}) { ensureAuth(); const workspaceId = args.workspaceId || process.env.TYPEBOT_WORKSPACE_ID; if (!workspaceId) { throw new Error('listBots: missing workspaceId (neither in args nor in process.env)'); } const apiBaseUrl = getApiBaseUrl(); const response = await axios_1.default.get(`${apiBaseUrl}/typebots`, { params: { workspaceId } }); return response.data; } async function getBot(args) { ensureAuth(); const { botId } = args; if (!botId) throw new Error('getBot: missing botId'); const apiBaseUrl = getApiBaseUrl(); const response = await axios_1.default.get(`${apiBaseUrl}/typebots/${botId}`); return response.data; } async function updateBot(args) { ensureAuth(); const { botId, typebot: changes, overwrite = false } = args; if (!botId) throw new Error('updateBot: missing botId'); if (typeof changes !== 'object' || Object.keys(changes).length === 0) { throw new Error('updateBot: the `typebot` object with fields to change is required'); } const apiBaseUrl = getApiBaseUrl(); const getRes = await axios_1.default.get(`${apiBaseUrl}/typebots/${botId}`); const version = getRes.data.typebot.version; if (!version) { throw new Error('updateBot: could not get the current version of the Typebot'); } const payload = { typebot: { version, ...changes } }; if (overwrite) { payload.overwrite = true; } const patchRes = await axios_1.default.patch(`${apiBaseUrl}/typebots/${botId}`, payload); return patchRes.data; } async function deleteBot(args) { ensureAuth(); const { botId } = args; if (!botId) throw new Error('deleteBot: missing botId'); const apiBaseUrl = getApiBaseUrl(); const response = await axios_1.default.delete(`${apiBaseUrl}/typebots/${botId}`); return response.data; } async function publishBot(args) { ensureAuth(); const { botId } = args; if (!botId) throw new Error('publishBot: missing botId'); const apiBaseUrl = getApiBaseUrl(); const response = await axios_1.default.post(`${apiBaseUrl}/typebots/${botId}/publish`, {}); return response.data; } async function unpublishBot(args) { ensureAuth(); const { botId } = args; if (!botId) throw new Error('unpublishBot: missing botId'); const apiBaseUrl = getApiBaseUrl(); const response = await axios_1.default.post(`${apiBaseUrl}/typebots/${botId}/unpublish`, {}); return response.data; } async function listResults(args) { ensureAuth(); const { botId, limit = 50, cursor, timeFilter = 'last7Days', timeZone, } = args; if (!botId) throw new Error('listResults: missing botId'); if (limit < 1 || limit > 100) { throw new Error('listResults: limit must be between 1 and 100'); } const params = { limit, timeFilter }; if (cursor) params.cursor = cursor; if (timeZone) params.timeZone = timeZone; const apiBaseUrl = getApiBaseUrl(); const response = await axios_1.default.get(`${apiBaseUrl}/typebots/${botId}/results`, { params }); return response.data; } async function startChat(args) { ensureAuth(); const { botId, chat } = args; if (!botId) throw new Error('startChat: missing botId'); const payload = {}; if (chat) payload.chat = chat; const apiBaseUrl = getApiBaseUrl(); const response = await axios_1.default.post(`${apiBaseUrl}/typebots/${botId}/chat/start`, payload); return response.data; }