n8n-code-toolkit
v2.0.0
Published
TypeScript SDK for n8n workflow automation - token-efficient management across multiple instances
Maintainers
Readme
n8n Code-Based Toolkit
98% Token Savings | TypeScript-based n8n workflow management across multiple instances.
Replaces MCP server with direct TypeScript code execution for massive token efficiency gains.
Quick Start
import { createClient, listWorkflows, getWorkflowHealth, filterWorkflows, activateWorkflow, deleteWorkflow } from 'n8n-code-toolkit';
// Connect to n8n instance
const client = createClient('homelab'); // or 'broski', 'brian', 'sarah', etc.
// Check workflow health
const health = await getWorkflowHealth(client, 'workflow-123');
console.log(`Success rate: ${health.successRate}%`); // e.g., 98%
// Find production workflows
const prodWorkflows = await filterWorkflows(client, {
tags: ['production'],
metadataOnly: true // 90%+ smaller response
});
// Activate a workflow
await activateWorkflow(client, 'workflow-abc');
// Delete a workflow
await deleteWorkflow(client, 'workflow-xyz');Progressive Disclosure Guide
Data returned at 4 levels - use the minimum you need:
| Level | Size | Use Case | Example |
|-------|------|----------|---------|
| name | 50B | Lists, dropdowns | Node search results |
| description | 200B | Browse, preview | Template discovery |
| essentials | 2KB | Planning, analysis | Workflow selection |
| full | 20KB+ | Implementation | Deployment, editing |
Examples
// Level 1: Name only (~50 bytes)
const nodes = await searchNodes('slack', { detailLevel: 'name' });
// Level 2: With description (~200 bytes)
const templates = await searchTemplates(client, 'notification', { maxResults: 10 });
// Level 3: Essentials for planning (~2KB)
const nodeInfo = await getNodeInfo(client, 'n8n-nodes-base.slack', 'essentials');
// Level 4: Full data for implementation (~20KB)
const workflow = await getWorkflow(client, 'workflow-123'); // Full workflow JSONMulti-Instance Setup
Configure up to 6 n8n instances via environment variables:
# .env file
N8N_DEFAULT_INSTANCE=homelab
# HomeLab instance
N8N_HOMELAB_URL=http://10.0.0.211:5678
N8N_HOMELAB_API_KEY=n8n_api_xxxxx
# VPS instances
N8N_BROSKI_URL=https://n8n-broski.yourdomain.com
N8N_BROSKI_API_KEY=n8n_api_yyyyy
N8N_BRIAN_URL=https://n8n-brian.yourdomain.com
N8N_BRIAN_API_KEY=n8n_api_zzzzz
# ... (sarah, fluff, simmons)Three initialization patterns:
// Pattern 1: Default instance (from N8N_DEFAULT_INSTANCE or 'homelab')
const client = createClient();
// Pattern 2: Named instance
const broskiClient = createClient('broski');
// Pattern 3: Custom configuration
const customClient = createClient({
url: 'https://n8n.example.com',
apiKey: 'n8n_api_xxxxx'
});Token Savings Examples
| Operation | MCP Tokens | Code Tokens | Savings | |-----------|------------|-------------|---------| | Workflow discovery | 150,000 | 2,000 | 98.7% | | Execution viewing (preview) | 130,000 | 1,000 | 99.2% | | Node search (name only) | 45,000 | 500 | 98.9% | | Template search (metadata) | 60,000 | 1,500 | 97.5% | | Average | 96,250 | 1,250 | 98.7% |
Navigation (≤3 steps to any tool)
By Use Case
- Workflow Management: API Reference → CRUD, activate/deactivate
- Execution Monitoring: Smart Features → Preview modes, health metrics
- Bulk Operations: Bulk Ops → Parallel activate/deactivate/export/import
- Discovery: Search → Nodes, templates with fuzzy matching
- Validation: Validation → Multi-layer checking + autofix
By Module
- workflows.ts - CRUD (create, get, list, update, get tags, update tags, execute). Note:
activateWorkflow,deactivateWorkflow,transferWorkflow, anddeleteWorkfloware now top-level toolkit actions exported directly fromn8n-code-toolkitfor ease of use. - executions.ts - List, get, delete, retry, stats
- credentials.ts, tags.ts, variables.ts, users.ts, projects.ts
- audit.ts, source-control.ts
- search-nodes.ts - Fuzzy search with Fuse.js
- search-templates.ts - Template discovery
- get-node-info.ts - Progressive disclosure (4 levels)
- get-template.ts - 3 modes (nodes_only, structure, full)
- validate-workflow.ts - Orchestrator
- validate-node.ts, validate-connections.ts, validate-expressions.ts
- autofix.ts - Automatic error correction with confidence scoring
- smart-execution-viewer.ts - 4 modes (preview/summary/filtered/full)
- smart-workflow-filter.ts - Metadata-only mode (90%+ reduction)
- activate-workflows.ts, deactivate-workflows.ts
- export-workflows.ts, import-workflows.ts (with validation/autofix)
- check-failed-executions.ts - Aggregate by workflow + error type
- workflow-health.ts - Success rate, status (healthy/degraded/unhealthy)
- credential-audit.ts - Usage tracking, unused detection
- instantiate-template.ts - Pure function to build from template with customization (variables, credentials)
Troubleshooting
Issue: "Configuration file not found"
Solution: Ensure .env file exists with N8N_* variables. The toolkit auto-loads environment variables on import.
Issue: API connection refused
Solution: Verify n8n instance is running and URL/port are correct:
curl http://10.0.0.211:5678/api/v1/workflowsIssue: TypeScript errors about missing types
Solution: Ensure you're importing from the main package:
import { createClient, Workflow } from 'n8n-code-toolkit';Issue: Token savings not as expected
Solution: Use progressive disclosure levels and metadata-only modes:
// ❌ Full data (large)
const workflows = await filterWorkflows(client, { tags: ['prod'] });
// ✅ Metadata only (90%+ smaller)
const workflows = await filterWorkflows(client, {
tags: ['prod'],
metadataOnly: true
});Testing
The toolkit includes a comprehensive QA suite that validates functionality against a live n8n instance.
# Run QA suite (requires .env configuration)
npm run test:qaSee QA_REPORT.md for the latest validation results.
API Limitations & Workarounds
The n8n Public API (v1) has specific constraints handled by this toolkit:
- Strict PUT Payload:
updateWorkflowstrictly filters payload to only allowed mutable fields to avoid "additional properties" errors. This toolkit'supdateWorkflownow handles this by constructing a whitelist of properties. - Activation/Deactivation:
activateWorkflowanddeactivateWorkflowrequire specificPOSTrequests with a null body (not an empty object or array). The toolkit's wrappers handle this specific client configuration. - Tag Updates:
PUT /workflows/{id}/tagsexpects an array of tag objects (e.g.,[{ name: "tag1" }]), not just strings or an object wrapper. The toolkit'supdateWorkflowTagshandles this transformation. - Read-Only Tags on Create: You cannot set tags during workflow creation.
- Solution: The toolkit's builders create the workflow first, then apply tags via a separate update.
- List Limits: The API limits list results to 250 items.
- Solution:
filterWorkflowsand other list functions handle pagination automatically.
- Solution:
- Tag Conflicts: Tag creation can be flaky (409 conflicts).
- Solution: Logic includes fallback to existing tags.
- Missing Endpoints: Credentials listing and Node Type discovery are not available via the Public API key.
- Impact: Some monitoring/discovery features run in degraded/fallback mode.
Claude Code Skill
A Claude Code skill is included for AI-assisted development. Install it to give Claude knowledge of all toolkit functions.
# The skill package is at:
skill/n8n-toolkit.skill
# Install by copying to your Claude plugins:
cp skill/n8n-toolkit.skill ~/.claude/skills/Once installed, Claude will automatically know how to use this toolkit when you:
- Mention "n8n workflows" or "n8n automation"
- Work in a project with n8n-code-toolkit installed
- Invoke
/n8n-toolkit
Documentation Links
- API Reference - All 50+ functions with examples
- Migration Guide - MCP to Code mapping
- Setup Guide - Three installation methods
- Examples - Real-world usage scripts
- Claude Skill - Claude Code skill for AI-assisted development
Built for token efficiency | MIT License
