mcp-typebot
Version:
A small MCP server that exposes Typebot’s REST API as callable tools in Claude Desktop (via STDIO). You can create, list, get, update, delete, publish/unpublish Typebots, list results, and start chats—using natural-language commands.
131 lines (130 loc) • 4.73 kB
JavaScript
;
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"));
function ensureAuth() {
const header = axios_1.default.defaults.headers.common['Authorization'];
if (!header) {
throw new Error('No hay token configurado. Llama primero a authenticate o define TYPEBOT_TOKEN.');
}
}
async function createBot(args) {
ensureAuth();
const workspaceId = args.workspaceId || process.env.TYPEBOT_WORKSPACE_ID;
if (!workspaceId) {
throw new Error('createBot: falta workspaceId (ni en args ni en process.env)');
}
const payload = {
workspaceId,
typebot: {
name: args.name,
description: args.description,
},
};
const response = await axios_1.default.post('https://app.typebot.io/api/v1/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: falta workspaceId (ni en args ni en process.env)');
}
const response = await axios_1.default.get('https://app.typebot.io/api/v1/typebots', { params: { workspaceId } });
return response.data;
}
async function getBot(args) {
ensureAuth();
const { botId } = args;
if (!botId)
throw new Error('getBot: falta botId');
const response = await axios_1.default.get(`https://app.typebot.io/api/v1/typebots/${botId}`);
return response.data;
}
async function updateBot(args) {
ensureAuth();
const { botId, typebot: changes, overwrite = false } = args;
if (!botId)
throw new Error('updateBot: falta botId');
if (typeof changes !== 'object' || Object.keys(changes).length === 0) {
throw new Error('updateBot: el objeto `typebot` con campos a cambiar es obligatorio');
}
const getRes = await axios_1.default.get(`https://app.typebot.io/api/v1/typebots/${botId}`);
const version = getRes.data.typebot.version;
if (!version) {
throw new Error('updateBot: no pude obtener la versión actual del Typebot');
}
const payload = {
typebot: {
version,
...changes
}
};
if (overwrite) {
payload.overwrite = true;
}
const patchRes = await axios_1.default.patch(`https://app.typebot.io/api/v1/typebots/${botId}`, payload);
return patchRes.data;
}
async function deleteBot(args) {
ensureAuth();
const { botId } = args;
if (!botId)
throw new Error('deleteBot: falta botId');
const response = await axios_1.default.delete(`https://app.typebot.io/api/v1/typebots/${botId}`);
return response.data;
}
async function publishBot(args) {
ensureAuth();
const { botId } = args;
if (!botId)
throw new Error('publishBot: falta botId');
const response = await axios_1.default.post(`https://app.typebot.io/api/v1/typebots/${botId}/publish`, {});
return response.data;
}
async function unpublishBot(args) {
ensureAuth();
const { botId } = args;
if (!botId)
throw new Error('unpublishBot: falta botId');
const response = await axios_1.default.post(`https://app.typebot.io/api/v1/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: falta botId');
if (limit < 1 || limit > 100) {
throw new Error('listResults: limit debe estar entre 1 y 100');
}
const params = { limit, timeFilter };
if (cursor)
params.cursor = cursor;
if (timeZone)
params.timeZone = timeZone;
const response = await axios_1.default.get(`https://app.typebot.io/api/v1/typebots/${botId}/results`, { params });
return response.data;
}
async function startChat(args) {
ensureAuth();
const { botId, chat } = args;
if (!botId)
throw new Error('startChat: falta botId');
const payload = {};
if (chat)
payload.chat = chat;
const response = await axios_1.default.post(`https://app.typebot.io/api/v1/typebots/${botId}/chat/start`, payload);
return response.data;
}