mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-01-31 06:52:04 +00:00
- Added OperationSimilarityService for validating operations with "Did you mean...?" suggestions - Added ResourceSimilarityService for validating resources with plural/singular detection - Implements Levenshtein distance algorithm for typo detection - Pattern matching for common operation/resource mistakes - 5-minute cache with automatic cleanup to prevent memory leaks - Confidence scoring (30% minimum threshold) for suggestion quality - Resource-aware operation filtering for contextual suggestions - Safe JSON parsing with ValidationServiceError for proper error handling - Type guards for safe property access - Performance optimizations with early termination - Comprehensive test coverage (37 new tests) - Integration tested with n8n-mcp-tester agent Example use cases: - "listFiles" → suggests "search" for Google Drive - "files" → suggests singular "file" - "flie" → suggests "file" (typo correction) - "downlod" → suggests "download" 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
/**
|
|
* Custom error class for validation service failures
|
|
*/
|
|
export class ValidationServiceError extends Error {
|
|
constructor(
|
|
message: string,
|
|
public readonly nodeType?: string,
|
|
public readonly property?: string,
|
|
public readonly cause?: Error
|
|
) {
|
|
super(message);
|
|
this.name = 'ValidationServiceError';
|
|
|
|
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, ValidationServiceError);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create error for JSON parsing failure
|
|
*/
|
|
static jsonParseError(nodeType: string, cause: Error): ValidationServiceError {
|
|
return new ValidationServiceError(
|
|
`Failed to parse JSON data for node ${nodeType}`,
|
|
nodeType,
|
|
undefined,
|
|
cause
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create error for node not found
|
|
*/
|
|
static nodeNotFound(nodeType: string): ValidationServiceError {
|
|
return new ValidationServiceError(
|
|
`Node type ${nodeType} not found in repository`,
|
|
nodeType
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create error for critical data extraction failure
|
|
*/
|
|
static dataExtractionError(nodeType: string, dataType: string, cause?: Error): ValidationServiceError {
|
|
return new ValidationServiceError(
|
|
`Failed to extract ${dataType} for node ${nodeType}`,
|
|
nodeType,
|
|
dataType,
|
|
cause
|
|
);
|
|
}
|
|
} |