n8n_trigger_webhook
Trigger active n8n workflows by sending HTTP requests to their webhook URLs with custom data and headers.
Instructions
Trigger a workflow via its webhook URL. The workflow must be active and have a Webhook trigger node.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| webhookUrl | Yes | Full webhook URL (e.g., https://n8n.example.com/webhook/xxx-xxx-xxx) | |
| method | No | HTTP method (default: POST) | |
| data | No | Data to send with the webhook request | |
| headers | No | Additional HTTP headers |
Implementation Reference
- src/tools/execution-tools.ts:213-240 (handler)The main tool handler function for n8n_trigger_webhook that validates input arguments and calls N8nApiClient.triggerWebhook to execute the webhook trigger.n8n_trigger_webhook: async ( client: N8nApiClient, args: Record<string, unknown> ): Promise<ToolResult> => { const webhookUrl = args.webhookUrl as string; if (!webhookUrl) { throw new Error('Webhook URL is required'); } const result = await client.triggerWebhook(webhookUrl, { method: (args.method as 'GET' | 'POST' | 'PUT' | 'DELETE') || 'POST', data: args.data as Record<string, unknown> | undefined, headers: args.headers as Record<string, string> | undefined, }); return { content: [ { type: 'text' as const, text: JSON.stringify({ success: true, message: 'Webhook triggered successfully', response: result, }, null, 2), }, ], }; },
- src/tools/execution-tools.ts:72-98 (schema)The tool definition object containing the name, description, and input schema validation for n8n_trigger_webhook.{ name: 'n8n_trigger_webhook', description: 'Trigger a workflow via its webhook URL. The workflow must be active and have a Webhook trigger node.', inputSchema: { type: 'object', properties: { webhookUrl: { type: 'string', description: 'Full webhook URL (e.g., https://n8n.example.com/webhook/xxx-xxx-xxx)', }, method: { type: 'string', enum: ['GET', 'POST', 'PUT', 'DELETE'], description: 'HTTP method (default: POST)', }, data: { type: 'object', description: 'Data to send with the webhook request', }, headers: { type: 'object', description: 'Additional HTTP headers', }, }, required: ['webhookUrl'], }, },
- src/server.ts:127-131 (registration)Registration and dispatch logic in the MCP server's handleToolCall method that routes calls to 'n8n_trigger_webhook' to the corresponding handler in executionToolHandlers.// Execution tools if (name in executionToolHandlers) { const handler = executionToolHandlers[name as keyof typeof executionToolHandlers]; return handler(client, args); }
- Supporting utility method in N8nApiClient that performs the HTTP fetch request to the provided webhook URL, handling method, data, headers, and response parsing.async triggerWebhook( webhookUrl: string, options?: { method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; data?: Record<string, unknown>; headers?: Record<string, string>; } ): Promise<unknown> { const method = options?.method || 'POST'; logger.debug(`Triggering webhook: ${method} ${webhookUrl}`); const fetchOptions: RequestInit = { method, headers: { 'Content-Type': 'application/json', ...(options?.headers || {}), }, }; if (options?.data && method !== 'GET') { fetchOptions.body = JSON.stringify(options.data); } try { const response = await fetch(webhookUrl, fetchOptions); const text = await response.text(); if (!response.ok) { throw new Error(`Webhook error: HTTP ${response.status} - ${text}`); } try { return JSON.parse(text); } catch { return { response: text }; } } catch (error) { if (error instanceof Error) { logger.error(`Webhook error: ${error.message}`); throw error; } throw new Error('Unknown webhook error'); } }