UNPKG

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.

132 lines (131 loc) 5.65 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const dotenv_1 = __importDefault(require("dotenv")); dotenv_1.default.config(); const axios_1 = __importDefault(require("axios")); if (process.env.TYPEBOT_TOKEN) { axios_1.default.defaults.headers.common['Authorization'] = `Bearer ${process.env.TYPEBOT_TOKEN}`; } const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js"); const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js"); const zod_1 = require("zod"); const bots_1 = require("./tools/bots"); async function main() { const server = new mcp_js_1.McpServer({ name: 'mcp-typebot', version: '1.0.0', }); const toolsMap = new Map([ ['createBot', { func: bots_1.createBot, description: 'Crea un nuevo Typebot. Requiere “name”, opcional “description”', schema: zod_1.z.object({ workspaceId: zod_1.z.string().optional(), name: zod_1.z.string().min(1, "El campo 'name' es obligatorio."), description: zod_1.z.string().optional(), }), }], ['listBots', { func: bots_1.listBots, description: 'Lista todos los Typebots de un workspace', schema: zod_1.z.object({ workspaceId: zod_1.z.string().optional() }), }], ['getBot', { func: bots_1.getBot, description: 'Recupera un Typebot por su ID', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio.") }), }], ['updateBot', { func: bots_1.updateBot, description: 'Actualiza un Typebot existente (p.ej. cambia nombre)', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio."), typebot: zod_1.z.record(zod_1.z.any()).refine(x => typeof x === 'object', "El campo 'typebot' es obligatorio."), overwrite: zod_1.z.boolean().optional(), }), }], ['deleteBot', { func: bots_1.deleteBot, description: 'Elimina un Typebot por su ID', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio.") }), }], ['publishBot', { func: bots_1.publishBot, description: 'Publica un Typebot existente', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio.") }), }], ['unpublishBot', { func: bots_1.unpublishBot, description: 'Despublica un Typebot existente', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio.") }), }], ['listResults', { func: bots_1.listResults, description: 'Lista resultados de un Typebot', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio."), limit: zod_1.z.number().int().min(1).max(100).optional(), cursor: zod_1.z.string().optional(), timeFilter: zod_1.z.string().optional(), timeZone: zod_1.z.string().optional(), }), }], ['startChat', { func: bots_1.startChat, description: 'Inicia un chat con un Typebot. Requiere botId, opcional chat.context', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio."), chat: zod_1.z.object({ context: zod_1.z.record(zod_1.z.any()).optional(), }).optional(), }), }], ]); for (const [name, { func, description, schema }] of toolsMap) { server.registerTool(name, { title: name, description, inputSchema: schema.shape, }, async (rawArgs, _extra) => { if (process.env.TYPEBOT_TOKEN) { axios_1.default.defaults.headers.common['Authorization'] = `Bearer ${process.env.TYPEBOT_TOKEN}`; } const parsed = schema.safeParse(rawArgs); if (!parsed.success) { return { content: [{ type: 'text', text: `Error de validación en ${name}: ${parsed.error.message}` }] }; } try { const result = await func(parsed.data); return { content: [{ type: 'text', text: JSON.stringify(result) }] }; } catch (e) { return { content: [{ type: 'text', text: `Error en ${name}: ${e.message}` }] }; } }); } const transport = new stdio_js_1.StdioServerTransport(); await server.connect(transport); } main().catch(err => { console.error('Error al arrancar MCP server:', err); process.exit(1); });