n8n-nodes-tool-workflow-transformer
v0.1.4
Published
n8n AI tool node to execute workflows with JavaScript output transformation
Downloads
12
Maintainers
Readme
n8n Tool Workflow with Transformer
A custom n8n node that executes workflows as AI agent tools with JavaScript output transformation capabilities.
🎯 Overview
The Tool Workflow with Transformer node is based on the official n8n ToolWorkflow node, but adds a powerful feature: the ability to transform the workflow output using custom JavaScript code before returning it to the AI agent.
This is particularly useful when you need to:
- Format workflow output for specific AI agent requirements
- Extract only relevant data from complex workflow results
- Convert data structures to match expected formats
- Summarize or aggregate workflow outputs
✨ Features
- 🤖 AI Tool Integration: Designed to work as a tool for AI agents
- 🔄 Workflow Execution: Execute any n8n workflow from database or JSON
- 🔧 Output Transformation: Transform workflow output with custom JavaScript
- 📦 Flexible Input/Output: Handle various data formats
- ⚡ Error Handling: Robust error handling and reporting
📦 Installation
Using npm
npm install n8n-nodes-tool-workflow-transformerLocal Development
- Clone the repository:
git clone https://github.com/your-org/n8n-nodes-tool-workflow-transformer.git
cd n8n-nodes-tool-workflow-transformer- Install dependencies:
npm install- Build the project:
npm run build- Link to n8n:
npm link
cd /path/to/n8n
npm link n8n-nodes-tool-workflow-transformer🔧 Node Configuration
Parameters
Tool Configuration
- Name: The name of the tool function (alphanumeric with underscores)
- Description: Description of what the tool does for the AI agent
Workflow Source
- Source: Choose between:
- Database: Load workflow by ID from n8n database
- Define Below: Provide workflow JSON directly
Transformation
- Transform Output: Toggle to enable/disable output transformation
- Transformation Code: JavaScript code to transform the workflow output
Transformation Variables
The transformation code has access to:
$output: The output from the executed workflow (object or array)$input: The input that was sent to the workflow
📝 Usage Examples
Example 1: Extract Specific Fields
// Extract only names from an array of objects
if (Array.isArray($output)) {
return $output.map(item => item.name).join(', ');
}
return $output.name || 'Unknown';Example 2: Format for AI Response
// Format workflow output as a structured message
const count = Array.isArray($output) ? $output.length : 1;
return `Found ${count} results. Details: ${JSON.stringify($output, null, 2)}`;Example 3: Aggregate Data
// Sum values from workflow output
if (Array.isArray($output)) {
const total = $output.reduce((sum, item) => sum + (item.value || 0), 0);
return { total, itemCount: $output.length, average: total / $output.length };
}
return $output;Example 4: Error Handling
// Safely handle different output types
try {
if (!$output) return 'No data received';
if (Array.isArray($output)) {
return $output.filter(item => item.status === 'active');
}
return $output.status === 'active' ? $output : null;
} catch (error) {
return `Error processing data: ${error.message}`;
}🏗️ Architecture
The node extends the standard n8n workflow execution with:
- Workflow Execution: Executes the specified workflow with provided inputs
- Output Capture: Captures the workflow output data
- Transformation: Applies JavaScript transformation if enabled
- Result Return: Returns the (transformed) result to the AI agent
🛠️ Development
Project Structure
n8n-nodes-tool-workflow-transformer/
├── nodes/
│ ├── ToolWorkflowWithTransformer.node.ts
│ └── toolWorkflowWithTransformer.svg
├── dist/ # Compiled files
├── package.json
└── tsconfig.jsonAvailable Scripts
npm run build- Build the TypeScript codenpm run dev- Build in watch modenpm run lint- Run ESLintnpm run lintfix- Fix linting issues
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
MIT
🆘 Support
For issues or questions, please open an issue on GitHub.
