mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-07 14:03:08 +00:00
fix: improve node type suggestions for all test cases
- Enhanced substring matching for short search terms (http, sheet) - Boosted pattern match scores for short searches (45 points) - Added name similarity boost for substring matches - Fixed cross-package suggestions (nodes-base.openai → nodes-langchain.openAi) - Increased confidence for deprecated package prefixes to 95% - Added debug and test summary scripts All 16 test cases now pass with 100% accuracy: ✅ Case variations (HttpRequest, Webhook, etc.) - 95% confidence ✅ Missing prefixes (slack, googleSheets, etc.) - 90% confidence ✅ Common typos (htpRequest, webook, etc.) - 80% confidence ✅ Short partials (http, sheet) - 52-60% confidence ✅ Cross-package (nodes-base.openai) - 90% confidence ✅ Deprecated prefixes (n8n-nodes-base) - 95% confidence
This commit is contained in:
@@ -62,8 +62,8 @@ export class NodeSimilarityService {
|
||||
|
||||
// Old versions or deprecated names
|
||||
patterns.set('deprecated', [
|
||||
{ pattern: /^n8n-nodes-base\./i, suggestion: '', confidence: 0.85, reason: 'Full package name used instead of short form' },
|
||||
{ pattern: /^@n8n\/n8n-nodes-langchain\./i, suggestion: '', confidence: 0.85, reason: 'Full package name used instead of short form' },
|
||||
{ pattern: /^n8n-nodes-base\./i, suggestion: '', confidence: 0.95, reason: 'Full package name used instead of short form' },
|
||||
{ pattern: /^@n8n\/n8n-nodes-langchain\./i, suggestion: '', confidence: 0.95, reason: 'Full package name used instead of short form' },
|
||||
]);
|
||||
|
||||
// Common typos
|
||||
@@ -78,6 +78,7 @@ export class NodeSimilarityService {
|
||||
// AI/LangChain specific
|
||||
patterns.set('ai_nodes', [
|
||||
{ pattern: /^openai$/i, suggestion: 'nodes-langchain.openAi', confidence: 0.85, reason: 'AI node - incorrect package' },
|
||||
{ pattern: /^nodes-base\.openai$/i, suggestion: 'nodes-langchain.openAi', confidence: 0.9, reason: 'Wrong package - OpenAI is in LangChain package' },
|
||||
{ pattern: /^chatOpenAI$/i, suggestion: 'nodes-langchain.lmChatOpenAi', confidence: 0.85, reason: 'LangChain node naming convention' },
|
||||
{ pattern: /^vectorStore$/i, suggestion: 'nodes-langchain.vectorStoreInMemory', confidence: 0.7, reason: 'Generic vector store reference' },
|
||||
]);
|
||||
@@ -186,12 +187,20 @@ export class NodeSimilarityService {
|
||||
const cleanValid = this.normalizeNodeType(node.nodeType);
|
||||
const displayNameClean = this.normalizeNodeType(node.displayName);
|
||||
|
||||
// Special handling for very short search terms (e.g., "http", "sheet")
|
||||
const isShortSearch = invalidType.length <= 5;
|
||||
|
||||
// Name similarity (40% weight)
|
||||
const nameSimilarity = Math.max(
|
||||
let nameSimilarity = Math.max(
|
||||
this.getStringSimilarity(cleanInvalid, cleanValid),
|
||||
this.getStringSimilarity(cleanInvalid, displayNameClean)
|
||||
) * 40;
|
||||
|
||||
// For short searches that are substrings, give a small name similarity boost
|
||||
if (isShortSearch && (cleanValid.includes(cleanInvalid) || displayNameClean.includes(cleanInvalid))) {
|
||||
nameSimilarity = Math.max(nameSimilarity, 10);
|
||||
}
|
||||
|
||||
// Category match (20% weight)
|
||||
let categoryMatch = 0;
|
||||
if (node.category) {
|
||||
@@ -215,7 +224,9 @@ export class NodeSimilarityService {
|
||||
|
||||
// Check if it's a substring match
|
||||
if (cleanValid.includes(cleanInvalid) || displayNameClean.includes(cleanInvalid)) {
|
||||
patternMatch = 25;
|
||||
// Boost score significantly for short searches that are exact substring matches
|
||||
// Short searches need more boost to reach the 50 threshold
|
||||
patternMatch = isShortSearch ? 45 : 25;
|
||||
} else if (this.getEditDistance(cleanInvalid, cleanValid) <= 2) {
|
||||
// Small edit distance indicates likely typo
|
||||
patternMatch = 20;
|
||||
@@ -223,6 +234,11 @@ export class NodeSimilarityService {
|
||||
patternMatch = 18;
|
||||
}
|
||||
|
||||
// For very short searches, also check if the search term appears at the start
|
||||
if (isShortSearch && (cleanValid.startsWith(cleanInvalid) || displayNameClean.startsWith(cleanInvalid))) {
|
||||
patternMatch = Math.max(patternMatch, 40);
|
||||
}
|
||||
|
||||
const totalScore = nameSimilarity + categoryMatch + packageMatch + patternMatch;
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user