diff --git a/CHANGELOG.md b/CHANGELOG.md index 94aa450..08f60ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,188 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.16.0] - 2025-10-06 + +### Added + +- **🎉 Issue #272 Phase 1: Connection Operations UX Improvements** + + **New: `rewireConnection` Operation** + - Intuitive operation for changing connection target from one node to another + - Syntax: `{type: "rewireConnection", source: "Node", from: "OldTarget", to: "NewTarget"}` + - Internally uses remove + add pattern but with clearer semantics + - Supports smart parameters (branch, case) for multi-output nodes + - Validates all nodes exist before making changes + - 8 comprehensive unit tests covering all scenarios + + **New: Smart Parameters for Multi-Output Nodes** + - **branch parameter for IF nodes**: Use `branch: "true"` or `branch: "false"` instead of `sourceIndex: 0/1` + - **case parameter for Switch nodes**: Use `case: 0`, `case: 1`, etc. instead of `sourceIndex` + - Semantic, intuitive syntax that matches node behavior + - Explicit sourceIndex overrides smart parameters if both provided + - Works with both `addConnection` and `rewireConnection` operations + - 8 comprehensive unit tests + 11 integration tests against real n8n API + +### Changed + +- **⚠️ BREAKING: Removed `updateConnection` operation** + - Operation removed completely (type definition, implementation, validation, tests) + - Migration: Use `rewireConnection` or `removeConnection` + `addConnection` instead + - Reason: Confusing operation that was error-prone and rarely needed + - All tests updated (137 tests passing) + +### Fixed + +- **🐛 CRITICAL: Issue #275, #136 - TypeError in getNodeTypeAlternatives (57.4% of production errors)** + - **Impact**: Eliminated 323 out of 563 production errors, helping 127 users (76.5% of affected users) + - **Resolves Issue #136**: "Partial Workflow Updates fail with 'Cannot convert undefined or null to object'" - defensive type guards prevent these crashes + - **Root Cause**: `getNodeTypeAlternatives()` called string methods without validating nodeType parameter + - **Fix**: Added defense-in-depth protection: + - **Layer 1**: Type guard in `getNodeTypeAlternatives()` returns empty array for invalid inputs + - **Layer 2**: Enhanced `validateToolParamsBasic()` to catch empty strings + - **Affected Tools**: `get_node_essentials` (208 errors → 0), `get_node_info` (115 errors → 0), `get_node_documentation` (17 errors → 0) + - **Testing**: 21 comprehensive unit tests, verified with n8n-mcp-tester agent + - **Commit**: f139d38 + +- **Critical Bug: Smart Parameter Implementation** + - **Bug #1**: `branch` parameter initially mapped to `sourceOutput` instead of `sourceIndex` + - **Impact**: IF node connections went to wrong output (expected `IF.main[0]`, got `IF.true`) + - **Root Cause**: Misunderstood n8n's IF node connection structure + - **Fix**: Changed to correctly map `branch="true"` → `sourceIndex=0`, `branch="false"` → `sourceIndex=1` + - **Discovered by**: n8n-mcp-tester agent testing against real n8n API + - **Commit**: a7bfa73 + +- **Critical Bug: Zod Schema Stripping Parameters** + - **Bug #2**: `branch`, `case`, `from`, `to` parameters stripped by Zod validation + - **Impact**: Parameters never reached diff engine, smart parameters silently failed + - **Root Cause**: Parameters not defined in Zod schema in handlers-workflow-diff.ts + - **Fix**: Added missing parameters to schema + - **Discovered by**: n8n-mcp-tester agent + - **Commit**: aeaba3b + +- **TypeScript Compilation**: Added missing type annotations in workflow diff tests (Commit: 653f395) + +### Improved + +- **Integration Testing**: Created comprehensive integration tests against real n8n API + - 11 tests covering IF nodes, Switch nodes, and rewireConnection + - Tests validate actual n8n workflow structure, not in-memory objects + - Would have caught both smart parameter bugs that unit tests missed + - File: `tests/integration/n8n-api/workflows/smart-parameters.test.ts` + - **Commit**: 34bafe2 + +- **Documentation**: Updated MCP tool documentation + - Removed `updateConnection` references + - Added `rewireConnection` with 4 examples + - Added smart parameters section with IF and Switch examples + - Updated best practices and pitfalls + - Removed version references (AI agents see current state) + - Files: `src/mcp/tool-docs/workflow_management/n8n-update-partial-workflow.ts`, `docs/workflow-diff-examples.md` + - **Commit**: f78f53e + +### Test Coverage + +- **Total Tests**: 169 tests passing (158 unit + 11 integration) +- **Coverage**: 90.98% statements, 89.86% branches, 93.02% functions +- **Quality**: Integration tests against real n8n API prevent regression +- **New Tests**: + - 21 tests for TypeError prevention (Issue #275) + - 8 tests for rewireConnection operation + - 8 tests for smart parameters + - 11 integration tests against real n8n API + +### Technical Details + +**TypeError Prevention (Issue #275):** +```typescript +// Layer 1: Defensive utility function +export function getNodeTypeAlternatives(nodeType: string): string[] { + // Return empty array for invalid inputs instead of crashing + if (!nodeType || typeof nodeType !== 'string' || nodeType.trim() === '') { + return []; + } + // ... rest of function +} + +// Layer 2: Enhanced validation +if (param === '') { + errors.push(`String parameters cannot be empty. Parameter '${key}' has value: ""`); +} +``` + +**Smart Parameters Resolution:** +```typescript +// Resolve branch parameter for IF nodes +if (operation.branch !== undefined && operation.sourceIndex === undefined) { + if (sourceNode?.type === 'n8n-nodes-base.if') { + sourceIndex = operation.branch === 'true' ? 0 : 1; + // sourceOutput remains 'main' + } +} + +// Resolve case parameter for Switch nodes +if (operation.case !== undefined && operation.sourceIndex === undefined) { + sourceIndex = operation.case; +} +``` + +**Real n8n IF Node Structure:** +```json +"IF": { + "main": [ + [/* true branch connections, index 0 */], + [/* false branch connections, index 1 */] + ] +} +``` + +### Migration Guide + +**Before (v2.15.7):** +```typescript +// Old way: updateConnection (REMOVED) +{type: "updateConnection", source: "Webhook", target: "Handler", updates: {...}} + +// Old way: Multi-output nodes (still works) +{type: "addConnection", source: "IF", target: "Success", sourceIndex: 0} +``` + +**After (v2.16.0):** +```typescript +// New way: rewireConnection +{type: "rewireConnection", source: "Webhook", from: "OldHandler", to: "NewHandler"} + +// New way: Smart parameters (recommended) +{type: "addConnection", source: "IF", target: "Success", branch: "true"} +{type: "addConnection", source: "IF", target: "Error", branch: "false"} +{type: "addConnection", source: "Switch", target: "Handler", case: 0} +``` + +### Impact Summary + +**Production Error Reduction:** +- Issue #275 fix: -323 errors (-57.4% of total production errors) +- Helps 127 users (76.5% of users experiencing errors) + +**UX Improvements:** +- Semantic parameters make multi-output node connections intuitive +- `rewireConnection` provides clear intent for connection changes +- Integration tests ensure production reliability + +**Breaking Changes:** +- `updateConnection` removed (use `rewireConnection` or manual remove+add) + +### References + +- **Issue #272**: Connection operations improvements (Phase 0 + Phase 1) +- **Issue #204**: Differential update failures on Windows +- **Issue #275**: TypeError in getNodeTypeAlternatives +- **Issue #136**: Partial Workflow Updates fail with "Cannot convert undefined or null to object" (resolved by defensive type guards) +- **Commits**: + - Phase 0: cfe3c5e, 653f395, 2a85000 + - Phase 1: f9194ee, ee125c5, a7bfa73, aeaba3b, 34bafe2, c6e0e52, f78f53e + - Issue #275/#136: f139d38 + ## [2.15.7] - 2025-10-05 ### Fixed diff --git a/package.json b/package.json index 6d7f85a..83f488f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "n8n-mcp", - "version": "2.15.7", + "version": "2.16.0", "description": "Integration between n8n workflow automation and Model Context Protocol (MCP)", "main": "dist/index.js", "bin": { diff --git a/package.runtime.json b/package.runtime.json index 94d9707..00cd728 100644 --- a/package.runtime.json +++ b/package.runtime.json @@ -1,6 +1,6 @@ { "name": "n8n-mcp-runtime", - "version": "2.15.7", + "version": "2.16.0", "description": "n8n MCP Server Runtime Dependencies Only", "private": true, "dependencies": {