n8n_save_data
Save structured information to n8n via webhooks for storage, indexing, and retrieval. Submit project name, title, and text content for organized data management.
Instructions
Guardar información en n8n a través de webhook para indexación y almacenamiento
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectName | Yes | Nombre del proyecto | |
| title | Yes | Título del contenido | |
| text | Yes | Texto completo del contenido a guardar |
Implementation Reference
- index.ts:21-50 (registration)Registers the MCP tool 'n8n_save_data' with Zod input schema, description, and inline handler function that delegates to webhookTools.saveDataToWebhook and formats the markdown response.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 }], }; } );
- tools/webhook-client.ts:55-113 (handler)Core handler function that constructs the webhook payload, sends POST request to n8n webhook URL using fetch, handles HTTP responses, errors, and returns success/failure status with details.export async function saveDataToWebhook(args: SaveDataArgs): Promise<WebhookResponse> { try { console.error(`📤 Enviando datos al webhook n8n...`); console.error(`URL: ${WEBHOOK_URL}/${WEBHOOK_ID}`); const payload = buildWebhookPayload(args); console.error(`📋 Payload generado:`, JSON.stringify(payload, null, 2)); const response = await fetch(`${WEBHOOK_URL}/${WEBHOOK_ID}`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization-n8n-api-key': API_KEY, 'User-Agent': 'MCP-N8N-Webhook/1.0' }, body: JSON.stringify(payload) }); console.error(`📡 Respuesta HTTP: ${response.status} ${response.statusText}`); if (!response.ok) { const errorText = await response.text(); console.error(`❌ Error en respuesta:`, errorText); return { success: false, message: `Error HTTP ${response.status}: ${response.statusText}. ${errorText}`, timestamp: generateTimestamp() }; } let responseData: any; try { responseData = await response.json(); } catch (parseError) { // Si no es JSON válido, usar el texto de respuesta const textResponse = await response.text(); responseData = { message: textResponse }; } console.error(`✅ Datos enviados exitosamente:`, responseData); return { success: true, message: 'Datos guardados exitosamente en n8n', id: responseData.id || payload.project.id, timestamp: generateTimestamp() }; } catch (error) { console.error(`❌ Error enviando datos al webhook:`, error); return { success: false, message: `Error de conexión: ${(error as Error).message}`, timestamp: generateTimestamp() }; }
- index.ts:24-28 (schema)Zod schema defining input parameters for the 'n8n_save_data' tool: projectName, title, text.{ 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") },
- types/webhook.ts:32-36 (schema)TypeScript interface defining the input arguments for saveDataToWebhook, matching the tool schema.export interface SaveDataArgs { projectName: string; title: string; text: string; }
- tools/webhook-client.ts:32-50 (helper)Helper function to build the complete WebhookPayload object from input args, including metadata, project ID generation, and content.function buildWebhookPayload(args: SaveDataArgs): WebhookPayload { const timestamp = generateTimestamp(); return { metadata: { timestamp, source: 'mcp_assistant', version: '1.0' }, project: { id: generateProjectId(args.projectName), name: args.projectName }, content: { title: args.title, text: args.text } }; }