WF

n8n Workflows

Automation

Create and troubleshoot n8n workflows with support for LangChain AI integrations, data transformations, and email processing.

Available MCP Tools

Basic Workflow Structure

Every workflow consists of:

Common Workflow Pattern

Trigger → Transform Data → AI Analysis → Store Results → Send Output

Example: Email Processing

Email IMAP Trigger
  → Extract Email Data (Set node)
  → Basic LLM Chain (with Anthropic + Parser)
  → Parse Results (Code node)
  → Insert into Supabase
  → Prepare Reply (Set node)
  → Send Email

Key Data Structure Requirements

Code Node Returns

Critical: Always return an array of objects with json keys:

return [{
  json: {
    field1: "value",
    field2: 123
  },
  binary: item.binary  // If preserving attachments
}];

Accessing Other Nodes

const data = $('Node Name').first().json;

LangChain Integration

Basic LLM Chain + Anthropic Pattern

Three nodes required:

Output Parser Configuration

{
  "parameters": {
    "jsonSchemaExample": "{\"sentiment\": \"positive\", \"category\": \"inquiry\"}"
  }
}

Email Attachment Handling

Email attachments are in the binary property:

const binaryData = item.binary || {};
const attachments = [];

for (const [key, value] of Object.entries(binaryData)) {
  if (value && value.fileName) {
    attachments.push({
      fileName: value.fileName,
      mimeType: value.mimeType,
      fileSize: value.fileSize
    });
  }
}

Troubleshooting

When workflows fail validation or execution:

  1. Use validation tool first: n8n_validate_workflow({id: "workflow-id"})
  2. Check common issues:
    • Code nodes returning wrong format
    • Missing required parameters
    • Undefined variables in Code nodes
    • Broken connections between nodes

Key Learnings