UNPKG

typebot-mcp

Version:

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

132 lines (131 loc) 5.59 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: 'typebot-mcp', version: '1.0.0', }); const toolsMap = new Map([ ['createBot', { func: bots_1.createBot, description: 'Create a new Typebot. Requires "name", optional "description"', schema: zod_1.z.object({ workspaceId: zod_1.z.string().optional(), name: zod_1.z.string().min(1, "The 'name' field is required."), description: zod_1.z.string().optional(), }), }], ['listBots', { func: bots_1.listBots, description: 'List all Typebots in a workspace', schema: zod_1.z.object({ workspaceId: zod_1.z.string().optional() }), }], ['getBot', { func: bots_1.getBot, description: 'Get a Typebot by its ID', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio.") }), }], ['updateBot', { func: bots_1.updateBot, description: 'Update an existing Typebot (e.g., change name)', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "The 'botId' field is required."), typebot: zod_1.z.record(zod_1.z.any()).refine((x) => typeof x === 'object', "The 'typebot' field is required."), overwrite: zod_1.z.boolean().optional(), }), }], ['deleteBot', { func: bots_1.deleteBot, description: 'Delete a Typebot by its ID', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio.") }), }], ['publishBot', { func: bots_1.publishBot, description: 'Publish an existing Typebot', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio.") }), }], ['unpublishBot', { func: bots_1.unpublishBot, description: 'Unpublish an existing Typebot', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "El campo 'botId' es obligatorio.") }), }], ['listResults', { func: bots_1.listResults, description: 'List results of a Typebot', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "The 'botId' field is required."), 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: 'Start a chat with a Typebot. Requires botId, optional chat.context', schema: zod_1.z.object({ botId: zod_1.z.string().min(1, "The 'botId' field is required."), 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: `Validation error in ${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 in ${name}: ${e.message}` }] }; } }); } const transport = new stdio_js_1.StdioServerTransport(); await server.connect(transport); } main().catch(err => { console.error('Error starting MCP server:', err); process.exit(1); });