Skip to main content
Glama

MCP N8N Webhook Server

by gcorroto
index.ts3.9 kB
#!/usr/bin/env node import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; // Import webhook tools import * as webhookTools from "./tools/webhook-client.js"; import { VERSION } from "./common/version.js"; // Create the MCP Server with proper configuration const server = new McpServer({ name: "n8n-webhook-mcp-server", version: VERSION, }); // ----- HERRAMIENTAS MCP PARA WEBHOOK N8N ----- // 1. Guardar datos en n8n webhook server.tool( "n8n_save_data", "Guardar información en n8n a través de webhook para indexación y almacenamiento", { projectName: z.string().describe("Nombre del proyecto"), title: z.string().describe("Título del contenido"), text: z.string().describe("Texto completo del contenido a guardar") }, async (args) => { console.error(`📤 Guardando datos en n8n: ${args.title}`); const result = await webhookTools.saveDataToWebhook({ projectName: args.projectName, title: args.title, text: args.text }); const statusIcon = result.success ? '✅' : '❌'; const content = result.success ? `${statusIcon} **Datos guardados exitosamente**\n\n**Proyecto:** ${args.projectName}\n**Título:** ${args.title}\n**ID:** ${result.id}\n**Timestamp:** ${result.timestamp}\n\n${result.message}` : `${statusIcon} **Error al guardar datos**\n\n**Error:** ${result.message}\n**Timestamp:** ${result.timestamp}`; return { content: [{ type: "text", text: content }], }; } ); // 2. Health check del webhook server.tool( "n8n_health_check", "Verificar la conectividad y estado del webhook de n8n", {}, async () => { console.error(`🔍 Verificando estado del webhook n8n...`); const result = await webhookTools.healthCheckWebhook(); const statusIcon = result.success ? '✅' : '❌'; const content = `${statusIcon} **Estado del Webhook N8N**\n\n**Estado:** ${result.success ? 'DISPONIBLE' : 'NO DISPONIBLE'}\n**Mensaje:** ${result.message}\n**Verificado:** ${result.timestamp}`; return { content: [{ type: "text", text: content }], }; } ); async function runServer() { try { console.error("Creating N8N Webhook MCP Server..."); console.error("Server info: n8n-webhook-mcp-server"); console.error("Version:", VERSION); // Validate environment variables const webhookUrl = process.env.N8N_WEBHOOK_URL || 'https://grec0-n8n.sytes.net/webhook-test'; const webhookId = process.env.N8N_WEBHOOK_ID || 'f9c6e821-b9d5-4f80-9d82-bdca6255e48d'; const apiKey = process.env.N8N_API_KEY || 'lkmQ3Ppasi7oe7r8V66mks7K8uYL'; const indexName = process.env.N8N_INDEX_NAME || 'PROJECT_CONVERSATIONS'; const tableCategory = process.env.N8N_TABLE_CATEGORY || 'DEVELOPMENT_LOGS'; console.error("N8N_WEBHOOK_URL:", webhookUrl); console.error("N8N_WEBHOOK_ID:", webhookId); console.error("N8N_API_KEY:", apiKey ? "***configured***" : "***not set***"); console.error("N8N_INDEX_NAME:", indexName); console.error("N8N_TABLE_CATEGORY:", tableCategory); console.error("Starting N8N Webhook MCP Server in stdio mode..."); // Create transport const transport = new StdioServerTransport(); console.error("Connecting server to transport..."); // Connect server to transport - this should keep the process alive await server.connect(transport); console.error("MCP Server connected and ready!"); console.error("Available tools:", [ "n8n_save_data", "n8n_health_check" ]); } catch (error) { console.error("Error starting server:", error); console.error("Stack trace:", (error as Error).stack); process.exit(1); } } // Start the server runServer();

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gcorroto/mcp-n8n-webhook'

If you have feedback or need assistance with the MCP directory API, please join our Discord server