Skip to main content
Glama

n8n_test_workflow

Execute and test n8n workflows with webhook, form, or chat triggers by providing workflow ID and trigger-specific data.

Instructions

Test/trigger workflow execution. Auto-detects trigger type (webhook/form/chat). Supports: webhook (HTTP), form (fields), chat (message). Note: Only workflows with these trigger types can be executed externally.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflowIdYesWorkflow ID to execute (required)
triggerTypeNoTrigger type. Auto-detected if not specified. Workflow must have a matching trigger node.
httpMethodNoFor webhook: HTTP method (default: from workflow config or POST)
webhookPathNoFor webhook: override the webhook path
messageNoFor chat: message to send (required for chat triggers)
sessionIdNoFor chat: session ID for conversation continuity
dataNoInput data/payload for webhook, form fields, or execution data
headersNoCustom HTTP headers
timeoutNoTimeout in ms (default: 120000)
waitForResponseNoWait for workflow completion (default: true)

Implementation Reference

  • Main handler function that implements the core logic for the 'n8n_test_workflow' tool. Fetches workflow, auto-detects or validates trigger type (webhook/form/chat), checks prerequisites (active status, required params), retrieves appropriate trigger handler from registry, and executes the trigger.
    export async function handleTestWorkflow(args: unknown, context?: InstanceContext): Promise<McpToolResponse> {
      try {
        const client = ensureApiConfigured(context);
        const input = testWorkflowSchema.parse(args);
    
        // Import trigger system (lazy to avoid circular deps)
        const {
          detectTriggerFromWorkflow,
          ensureRegistryInitialized,
          TriggerRegistry,
        } = await import('../triggers');
    
        // Ensure registry is initialized
        await ensureRegistryInitialized();
    
        // Fetch the workflow to analyze its trigger
        const workflow = await client.getWorkflow(input.workflowId);
    
        // Determine trigger type
        let triggerType: TriggerType | undefined = input.triggerType as TriggerType | undefined;
        let triggerInfo;
    
        // Auto-detect from workflow
        const detection = detectTriggerFromWorkflow(workflow);
    
        if (!triggerType) {
          if (detection.detected && detection.trigger) {
            triggerType = detection.trigger.type;
            triggerInfo = detection.trigger;
          } else {
            // No externally-triggerable trigger found
            return {
              success: false,
              error: 'Workflow cannot be triggered externally',
              details: {
                workflowId: input.workflowId,
                reason: detection.reason,
                hint: 'Only workflows with webhook, form, or chat triggers can be executed via the API. Add one of these trigger nodes to your workflow.',
              },
            };
          }
        } else {
          // User specified a trigger type, verify it matches workflow
          if (detection.detected && detection.trigger?.type === triggerType) {
            triggerInfo = detection.trigger;
          } else if (!detection.detected || detection.trigger?.type !== triggerType) {
            return {
              success: false,
              error: `Workflow does not have a ${triggerType} trigger`,
              details: {
                workflowId: input.workflowId,
                requestedTrigger: triggerType,
                detectedTrigger: detection.trigger?.type || 'none',
                hint: detection.detected
                  ? `Workflow has a ${detection.trigger?.type} trigger. Either use that type or omit triggerType for auto-detection.`
                  : 'Workflow has no externally-triggerable triggers (webhook, form, or chat).',
              },
            };
          }
        }
    
        // Get handler for trigger type
        const handler = TriggerRegistry.getHandler(triggerType, client, context);
        if (!handler) {
          return {
            success: false,
            error: `No handler registered for trigger type: ${triggerType}`,
            details: {
              supportedTypes: TriggerRegistry.getRegisteredTypes(),
            },
          };
        }
    
        // Check if workflow is active (if required by handler)
        if (handler.capabilities.requiresActiveWorkflow && !workflow.active) {
          return {
            success: false,
            error: 'Workflow must be active to trigger via this method',
            details: {
              workflowId: input.workflowId,
              triggerType,
              hint: 'Activate the workflow in n8n using n8n_update_partial_workflow with [{type: "activateWorkflow"}]',
            },
          };
        }
    
        // Validate chat trigger has message
        if (triggerType === 'chat' && !input.message) {
          return {
            success: false,
            error: 'Chat trigger requires a message parameter',
            details: {
              hint: 'Provide message="your message" for chat triggers',
            },
          };
        }
    
        // Build trigger-specific input
        const triggerInput = {
          workflowId: input.workflowId,
          triggerType,
          httpMethod: input.httpMethod,
          webhookPath: input.webhookPath,
          message: input.message || '',
          sessionId: input.sessionId,
          data: input.data,
          formData: input.data, // For form triggers
          headers: input.headers,
          timeout: input.timeout,
          waitForResponse: input.waitForResponse,
        };
    
        // Execute the trigger
        const response = await handler.execute(triggerInput as any, workflow, triggerInfo);
    
        return {
          success: response.success,
          data: response.data,
          message: response.success
            ? `Workflow triggered successfully via ${triggerType}`
            : response.error,
          executionId: response.executionId,
          workflowId: input.workflowId,
          details: {
            triggerType,
            metadata: response.metadata,
            ...(response.details || {}),
          },
        };
      } catch (error) {
        if (error instanceof z.ZodError) {
          return {
            success: false,
            error: 'Invalid input',
            details: { errors: error.errors },
          };
        }
    
        if (error instanceof N8nApiError) {
          return {
            success: false,
            error: getUserFriendlyErrorMessage(error),
            code: error.code,
            details: error.details as Record<string, unknown> | undefined,
          };
        }
    
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error occurred',
        };
      }
    }
  • ToolDefinition object defining the 'n8n_test_workflow' tool for MCP registration, including name, description, and complete inputSchema for parameter validation.
    name: 'n8n_test_workflow',
    description: `Test/trigger workflow execution. Auto-detects trigger type (webhook/form/chat). Supports: webhook (HTTP), form (fields), chat (message). Note: Only workflows with these trigger types can be executed externally.`,
    inputSchema: {
      type: 'object',
      properties: {
        workflowId: {
          type: 'string',
          description: 'Workflow ID to execute (required)'
        },
        triggerType: {
          type: 'string',
          enum: ['webhook', 'form', 'chat'],
          description: 'Trigger type. Auto-detected if not specified. Workflow must have a matching trigger node.'
        },
        // Webhook options
        httpMethod: {
          type: 'string',
          enum: ['GET', 'POST', 'PUT', 'DELETE'],
          description: 'For webhook: HTTP method (default: from workflow config or POST)'
        },
        webhookPath: {
          type: 'string',
          description: 'For webhook: override the webhook path'
        },
        // Chat options
        message: {
          type: 'string',
          description: 'For chat: message to send (required for chat triggers)'
        },
        sessionId: {
          type: 'string',
          description: 'For chat: session ID for conversation continuity'
        },
        // Common options
        data: {
          type: 'object',
          description: 'Input data/payload for webhook, form fields, or execution data'
        },
        headers: {
          type: 'object',
          description: 'Custom HTTP headers'
        },
        timeout: {
          type: 'number',
          description: 'Timeout in ms (default: 120000)'
        },
        waitForResponse: {
          type: 'boolean',
          description: 'Wait for workflow completion (default: true)'
        }
      },
      required: ['workflowId']
    }
  • Comprehensive ToolDocumentation providing detailed descriptions, parameter specs, examples, performance notes, best practices, pitfalls, and related tools for 'n8n_test_workflow'.
    export const n8nTestWorkflowDoc: ToolDocumentation = {
      name: 'n8n_test_workflow',
      category: 'workflow_management',
      essentials: {
        description: 'Test/trigger workflow execution. Auto-detects trigger type (webhook/form/chat). Only workflows with these triggers can be executed externally.',
        keyParameters: ['workflowId', 'triggerType', 'data', 'message'],
        example: 'n8n_test_workflow({workflowId: "123"}) - auto-detect trigger',
        performance: 'Immediate trigger, response time depends on workflow complexity',
        tips: [
          'Auto-detects trigger type from workflow if not specified',
          'Workflow must have a webhook, form, or chat trigger to be executable',
          'For chat triggers, message is required',
          'All trigger types require the workflow to be ACTIVE'
        ]
      },
      full: {
        description: `Test and trigger n8n workflows through HTTP-based methods. This unified tool supports multiple trigger types:
    
    **Trigger Types:**
    - **webhook**: HTTP-based triggers (GET/POST/PUT/DELETE)
    - **form**: Form submission triggers
    - **chat**: AI chat triggers with conversation support
    
    **Important:** n8n's public API does not support direct workflow execution. Only workflows with webhook, form, or chat triggers can be executed externally. Workflows with schedule, manual, or other trigger types cannot be triggered via this API.
    
    The tool auto-detects the appropriate trigger type by analyzing the workflow's trigger node. You can override this with the triggerType parameter.`,
        parameters: {
          workflowId: {
            type: 'string',
            required: true,
            description: 'Workflow ID to execute'
          },
          triggerType: {
            type: 'string',
            required: false,
            enum: ['webhook', 'form', 'chat'],
            description: 'Trigger type. Auto-detected if not specified. Workflow must have matching trigger node.'
          },
          httpMethod: {
            type: 'string',
            required: false,
            enum: ['GET', 'POST', 'PUT', 'DELETE'],
            description: 'For webhook: HTTP method (default: from workflow config or POST)'
          },
          webhookPath: {
            type: 'string',
            required: false,
            description: 'For webhook: override the webhook path'
          },
          message: {
            type: 'string',
            required: false,
            description: 'For chat: message to send (required for chat triggers)'
          },
          sessionId: {
            type: 'string',
            required: false,
            description: 'For chat: session ID for conversation continuity'
          },
          data: {
            type: 'object',
            required: false,
            description: 'Input data/payload for webhook or form fields'
          },
          headers: {
            type: 'object',
            required: false,
            description: 'Custom HTTP headers'
          },
          timeout: {
            type: 'number',
            required: false,
            description: 'Timeout in ms (default: 120000)'
          },
          waitForResponse: {
            type: 'boolean',
            required: false,
            description: 'Wait for workflow completion (default: true)'
          }
        },
        returns: `Execution response including:
    - success: boolean
    - data: workflow output data
    - executionId: for tracking/debugging
    - triggerType: detected or specified trigger type
    - metadata: timing and request details`,
        examples: [
          'n8n_test_workflow({workflowId: "123"}) - Auto-detect and trigger',
          'n8n_test_workflow({workflowId: "123", triggerType: "webhook", data: {name: "John"}}) - Webhook with data',
          'n8n_test_workflow({workflowId: "123", triggerType: "chat", message: "Hello AI"}) - Chat trigger',
          'n8n_test_workflow({workflowId: "123", triggerType: "form", data: {email: "test@example.com"}}) - Form submission'
        ],
        useCases: [
          'Test workflows during development',
          'Trigger AI chat workflows with messages',
          'Submit form data to form-triggered workflows',
          'Integrate n8n workflows with external systems via webhooks'
        ],
        performance: `Performance varies based on workflow complexity and waitForResponse setting:
    - Webhook: Immediate trigger, depends on workflow
    - Form: Immediate trigger, depends on workflow
    - Chat: May have additional AI processing time`,
        errorHandling: `**Error Response with Execution Guidance**
    
    When execution fails, the response includes guidance for debugging:
    
    **With Execution ID** (workflow started but failed):
    - Use n8n_executions({action: 'get', id: executionId, mode: 'preview'}) to investigate
    
    **Without Execution ID** (workflow didn't start):
    - Use n8n_executions({action: 'list', workflowId: 'wf_id'}) to find recent executions
    
    **Common Errors:**
    - "Workflow not found" - Check workflow ID exists
    - "Workflow not active" - Activate workflow (required for all trigger types)
    - "Workflow cannot be triggered externally" - Workflow has no webhook/form/chat trigger
    - "Chat message required" - Provide message parameter for chat triggers
    - "SSRF protection" - URL validation failed`,
        bestPractices: [
          'Let auto-detection choose the trigger type when possible',
          'Ensure workflow has a webhook, form, or chat trigger before testing',
          'For chat workflows, provide sessionId for multi-turn conversations',
          'Use mode="preview" with n8n_executions for efficient debugging',
          'Test with small data payloads first',
          'Activate workflows before testing (use n8n_update_partial_workflow with activateWorkflow)'
        ],
        pitfalls: [
          'All trigger types require the workflow to be ACTIVE',
          'Workflows without webhook/form/chat triggers cannot be executed externally',
          'Chat trigger requires message parameter',
          'Form data must match expected form fields',
          'Webhook method must match node configuration'
        ],
        relatedTools: ['n8n_executions', 'n8n_get_workflow', 'n8n_create_workflow', 'n8n_validate_workflow']
      }
    };
  • The tool is registered as part of the n8nManagementTools array exported from this file, which is imported and used by the MCP server to register management tools.
    {
      name: 'n8n_test_workflow',
      description: `Test/trigger workflow execution. Auto-detects trigger type (webhook/form/chat). Supports: webhook (HTTP), form (fields), chat (message). Note: Only workflows with these trigger types can be executed externally.`,
      inputSchema: {
        type: 'object',
        properties: {
          workflowId: {
            type: 'string',
            description: 'Workflow ID to execute (required)'
          },
          triggerType: {
            type: 'string',
            enum: ['webhook', 'form', 'chat'],
            description: 'Trigger type. Auto-detected if not specified. Workflow must have a matching trigger node.'
          },
          // Webhook options
          httpMethod: {
            type: 'string',
            enum: ['GET', 'POST', 'PUT', 'DELETE'],
            description: 'For webhook: HTTP method (default: from workflow config or POST)'
          },
          webhookPath: {
            type: 'string',
            description: 'For webhook: override the webhook path'
          },
          // Chat options
          message: {
            type: 'string',
            description: 'For chat: message to send (required for chat triggers)'
          },
          sessionId: {
            type: 'string',
            description: 'For chat: session ID for conversation continuity'
          },
          // Common options
          data: {
            type: 'object',
            description: 'Input data/payload for webhook, form fields, or execution data'
          },
          headers: {
            type: 'object',
            description: 'Custom HTTP headers'
          },
          timeout: {
            type: 'number',
            description: 'Timeout in ms (default: 120000)'
          },
          waitForResponse: {
            type: 'boolean',
            description: 'Wait for workflow completion (default: true)'
          }
        },
        required: ['workflowId']
      }
    },
  • Central export module for the trigger system used by n8n_test_workflow handler, providing trigger detection, registry, and base handler functionality.
    /**
     * Trigger system for n8n_test_workflow tool
     *
     * Provides extensible trigger handling for different n8n trigger types:
     * - webhook: HTTP-based triggers
     * - form: Form submission triggers
     * - chat: Chat/AI triggers
     *
     * Note: n8n's public API does not support direct workflow execution.
     * Only workflows with these trigger types can be triggered externally.
     */
    
    // Types
    export {
      TriggerType,
      BaseTriggerInput,
      WebhookTriggerInput,
      FormTriggerInput,
      ChatTriggerInput,
      TriggerInput,
      TriggerResponse,
      TriggerHandlerCapabilities,
      DetectedTrigger,
      TriggerDetectionResult,
      TestWorkflowInput,
    } from './types';
    
    // Detector
    export {
      detectTriggerFromWorkflow,
      buildTriggerUrl,
      describeTrigger,
    } from './trigger-detector';
    
    // Registry
    export {
      TriggerRegistry,
      initializeTriggerRegistry,
      ensureRegistryInitialized,
    } from './trigger-registry';
    
    // Base handler
    export {
      BaseTriggerHandler,
      TriggerHandlerConstructor,
    } from './handlers/base-handler';
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate readOnlyHint=false (mutation) and destructiveHint=false (non-destructive), but the description adds valuable context: it clarifies that this tool triggers workflow execution, which involves running workflows potentially with side effects. It also notes the auto-detection feature and external execution constraint. However, it doesn't mention rate limits, authentication needs, or detailed execution behavior beyond what's implied, leaving some gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by supporting details in a structured list format. Every sentence adds value: specifying trigger types, auto-detection, and constraints. There is no wasted text, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (10 parameters, mutation tool) and lack of output schema, the description does well by explaining the tool's purpose, trigger types, and constraints. However, it could improve by detailing return values or error handling, which are missing. The annotations help cover safety aspects, but some behavioral context (e.g., execution outcomes) remains unspecified.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 10 parameters. The description adds minimal parameter semantics beyond the schema, only implying that parameters like 'triggerType' map to webhook/form/chat contexts. It doesn't explain parameter interactions or provide additional syntax details, resulting in a baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Test/trigger workflow execution') and resource ('workflow'), distinguishing it from siblings like 'n8n_get_workflow' (read) or 'n8n_create_workflow' (create). It specifies the scope of trigger types (webhook/form/chat) and the constraint that only workflows with these triggers can be executed externally, making the purpose highly specific and differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use this tool: for testing/triggering workflows with specific trigger types (webhook, form, chat). It mentions the auto-detection feature and the constraint about external execution. However, it doesn't explicitly state when NOT to use it or name alternatives (e.g., using other tools for workflows without these triggers), which prevents a perfect score.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/czlonkowski/n8n-mcp'

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