Skip to main content
< All Topics
Print

n8n Workflow Development

name: n8n-workflow-development

description: Building n8n workflows using the MCP SDK with proper node discovery, expression patterns, credential management, and webhook design. Use when creating or updating n8n automations, debugging workflow execution, or orchestrating multi-step integrations.

n8n Workflow Development

Instructions

Build n8n workflows programmatically using the MCP SDK. Follow this mandatory sequence:

SDK build sequence:

  1. get_sdk_reference — learn SDK patterns, coding guidelines, and design guidance
  2. search_nodes — discover nodes for services (e.g., “gmail”, “slack”) and utilities (“set”, “if”, “merge”, “code”); note discriminators (resource/operation/mode)
  3. get_node_types — get exact TypeScript parameter definitions for ALL nodes including discriminators; never guess parameter names
  4. validate_workflow — validate full code before deployment; fix errors and re-validate until clean
  5. create_workflow_from_code — save the workflow to n8n with a short description
  6. publish_workflow — activate the workflow; required after every create or update

Expression engine safe patterns:

  • Use || for fallbacks, never ?? (nullish coalescing is unsupported in n8n expressions)
  • Use $execution.id for memory session keys to ensure uniqueness per run
  • Keep jsonBody expressions simple — avoid nested ternaries or complex logic
  • Reference previous node output via $('Node Name').item.json.fieldName

Credential management:

  • Create credentials via REST API: POST /api/v1/credentials with type, name, and data
  • Reference credentials in nodes by credential type and ID
  • Never hardcode secrets in workflow JSON — always use credential references

Webhook design:

  • Use Webhook trigger node for inbound HTTP; set path, method, and authentication
  • Return responses via “Respond to Webhook” node for synchronous flows
  • For async: acknowledge immediately, process in background branch

Workflow patterns:

  • Sequential: linear node chain for step-by-step processing
  • Parallel: split with multiple outputs from a single node; merge results downstream
  • Router: Switch node for conditional branching by field value or expression

Updating existing workflows:

  • Batch patch via PUT /api/v1/workflows/{id} with the full workflow JSON body
  • After every PUT, call publish_workflow to re-activate — updates are inactive until published
Table of Contents