fix: normalize node type prefixes for n8n workflow exports (#71)

- Add centralized normalizeNodeType utility to handle prefix conversion
  - n8n-nodes-base.* → nodes-base.*
  - @n8n/n8n-nodes-langchain.* → nodes-langchain.*
- Update all 9 affected MCP tools to use normalized node types
- AI agents can now use node types directly from n8n workflow exports
- Maintains backward compatibility with existing shortened prefixes
- Add comprehensive test coverage for all affected methods

Fixes #71

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-07-18 11:31:38 +02:00
parent 5dd932c19d
commit f8fa782d7f
6 changed files with 196 additions and 92 deletions

46
src/utils/node-utils.ts Normal file
View File

@@ -0,0 +1,46 @@
/**
* Normalizes node type from n8n export format to database format
*
* Examples:
* - 'n8n-nodes-base.httpRequest' → 'nodes-base.httpRequest'
* - '@n8n/n8n-nodes-langchain.agent' → 'nodes-langchain.agent'
* - 'nodes-base.slack' → 'nodes-base.slack' (unchanged)
*
* @param nodeType The node type to normalize
* @returns The normalized node type
*/
export function normalizeNodeType(nodeType: string): string {
// Handle n8n-nodes-base -> nodes-base
if (nodeType.startsWith('n8n-nodes-base.')) {
return nodeType.replace('n8n-nodes-base.', 'nodes-base.');
}
// Handle @n8n/n8n-nodes-langchain -> nodes-langchain
if (nodeType.startsWith('@n8n/n8n-nodes-langchain.')) {
return nodeType.replace('@n8n/n8n-nodes-langchain.', 'nodes-langchain.');
}
// Return unchanged if already normalized or unknown format
return nodeType;
}
/**
* Gets alternative node type formats to try for lookups
*
* @param nodeType The original node type
* @returns Array of alternative formats to try
*/
export function getNodeTypeAlternatives(nodeType: string): string[] {
const alternatives: string[] = [];
// Add lowercase version
alternatives.push(nodeType.toLowerCase());
// If it's just a bare node name, try with common prefixes
if (!nodeType.includes('.')) {
alternatives.push(`nodes-base.${nodeType}`);
alternatives.push(`nodes-langchain.${nodeType}`);
}
return alternatives;
}