Files
n8n-mcp/tests/unit/mcp/parameter-validation.test.ts
Romuald Członkowski 9050967cd6 Release v2.24.0: Unified get_node Tool with Code Review Fixes (#437)
* feat(tools): unify node information retrieval with get_node tool

Implements v2.24.0 featuring a unified node information tool that consolidates
get_node_info and get_node_essentials functionality while adding version history
and type structure metadata capabilities.

Key Features:
- Unified get_node tool with progressive detail levels (minimal/standard/full)
- Version history access (versions, compare, breaking changes, migrations)
- Type structure metadata integration from v2.23.0
- Token-efficient defaults optimized for AI agents
- Backward-compatible via private method preservation

Breaking Changes:
- Removed get_node_info tool (replaced by get_node with detail='full')
- Removed get_node_essentials tool (replaced by get_node with detail='standard')
- Tool count: 40 → 39 tools

Implementation:
- src/mcp/tools.ts: Added unified get_node tool definition
- src/mcp/server.ts: Implemented getNode() with 7 mode-specific methods
- Type structure integration via TypeStructureService.getStructure()
- Updated documentation in CHANGELOG.md and README.md
- Version bumped to 2.24.0

Token Costs:
- minimal: ~200 tokens (basic metadata)
- standard: ~1000-2000 tokens (essential properties, default)
- full: ~3000-8000 tokens (complete information)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en

Co-Authored-By: Claude <noreply@anthropic.com>

* docs: update tools-documentation.ts to reference unified get_node tool

Updated all references from deprecated get_node_essentials and get_node_info
to the new unified get_node tool with appropriate detail levels.

Changes:
- Standard Workflow Pattern: Updated to show get_node with detail levels
- Configuration Tools: Replaced two separate tool descriptions with unified get_node
- Performance Characteristics: Updated to reference get_node detail levels
- Usage Notes: Updated recommendation to use get_node with detail='standard'

This completes the v2.24.0 unified get_node tool implementation.
All 13/13 test scenarios passed in n8n-mcp-tester agent validation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Conceived by Romuald Członkowski - www.aiadvisors.pl/en

* test: update tests to reference unified get_node tool

Updated test files to replace references to deprecated get_node_info and
get_node_essentials tools with the new unified get_node tool.

Changes:
- tests/unit/mcp/tools.test.ts: Updated get_node tests and removed references
  to get_node_essentials in toolsWithExamples array and categories object
- tests/unit/mcp/parameter-validation.test.ts: Updated all get_node_info
  references to get_node throughout the test suite

Test results: Successfully reduced test failures from 11 to 3 non-critical failures:
- 1 description length test (expected for unified tool with comprehensive docs)
- 1 database initialization issue (test infrastructure, not related to changes)
- 1 timeout issue (unrelated to changes)

All get_node_info → get_node migration tests now pass successfully.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Conceived by Romuald Członkowski - www.aiadvisors.pl/en

* fix: implement all code review fixes for v2.24.0 unified get_node tool

Comprehensive improvements addressing all critical, high-priority, and code quality issues identified in code review.

## Critical Fixes (Phase 1)
- Add missing getNode mock in parameter-validation tests
- Shorten tool description from 670 to 288 characters (under 300 limit)

## High Priority Fixes (Phase 2)
- Add null safety check in enrichPropertyWithTypeInfo (prevent crashes on null properties)
- Add nodeType context to all error messages in handleVersionMode (better debugging)
- Optimize version summary fetch (conditional on detail level, skip for minimal mode)
- Add comprehensive parameter validation for detail and mode with clear error messages

## Code Quality Improvements (Phase 3)
- Refactor property enrichment with new enrichPropertiesWithTypeInfo helper (eliminate duplication)
- Add TypeScript interfaces for all return types (replace any with proper union types)
- Implement version data caching with 24-hour TTL (improve performance)
- Enhance JSDoc documentation with detailed parameter explanations

## New TypeScript Interfaces
- VersionSummary: Version metadata structure
- NodeMinimalInfo: ~200 token response for minimal detail
- NodeStandardInfo: ~1-2K token response for standard detail
- NodeFullInfo: ~3-8K token response for full detail
- VersionHistoryInfo: Version history response
- VersionComparisonInfo: Version comparison response
- NodeInfoResponse: Union type for all possible responses

## Testing
- All 130 test files passed (3778 tests, 42 skipped)
- Build successful with no TypeScript errors
- Proper test mocking for unified get_node tool

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: update integration tests to use unified get_node tool

Replace all references to deprecated get_node_info and get_node_essentials
with the new unified get_node tool in integration tests.

## Changes
- Replace get_node_info → get_node in 6 integration test files
- Replace get_node_essentials → get_node in 2 integration test files
- All tool calls now use unified interface

## Files Updated
- tests/integration/mcp-protocol/error-handling.test.ts
- tests/integration/mcp-protocol/performance.test.ts
- tests/integration/mcp-protocol/session-management.test.ts
- tests/integration/mcp-protocol/tool-invocation.test.ts
- tests/integration/mcp-protocol/protocol-compliance.test.ts
- tests/integration/telemetry/mcp-telemetry.test.ts

This fixes CI test failures caused by calling removed tools.

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en

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

Co-Authored-By: Claude <noreply@anthropic.com>

* test: add comprehensive tests for unified get_node tool

Add 81 comprehensive unit tests for the unified get_node tool to improve
code coverage of the v2.24.0 implementation.

## Test Coverage

### Parameter Validation (6 tests)
- Invalid detail/mode validation with clear error messages
- All valid parameter combinations
- Default values and node type normalization

### Info Mode Tests (21 tests)
- Minimal detail: Basic metadata only, no version info (~200 tokens)
- Standard detail: Essentials with version info (~1-2K tokens)
- Full detail: Complete info with version info (~3-8K tokens)
- includeTypeInfo and includeExamples parameter handling

### Version Mode Tests (24 tests)
- versions: Version history and details
- compare: Version comparison with proper error handling
- breaking: Breaking changes with upgradeSafe flags
- migrations: Auto-migratable changes detection

### Helper Methods (18 tests)
- enrichPropertyWithTypeInfo: Null safety, type handling, structure hints
- enrichPropertiesWithTypeInfo: Array handling, mixed properties
- getVersionSummary: Caching with 24-hour TTL

### Error Handling (3 tests)
- Repository initialization checks
- NodeType context in error messages
- Invalid mode/detail handling

### Integration Tests (8 tests)
- Mode routing logic
- Cache effectiveness across calls
- Type safety validation
- Edge cases (empty data, alternatives, long names)

## Results
- 81 tests passing
- 100% coverage of new get_node methods
- All parameter combinations tested
- All error conditions covered

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: update integration test assertions for unified get_node tool

Updated integration tests to match the new unified get_node response structure:
- error-handling.test.ts: Added detail='full' parameter for large payload test
- tool-invocation.test.ts: Updated property assertions for standard/full detail levels
- Fixed duplicate describe block and comparison logic

Conceived by Romuald Członkowski - www.aiadvisors.pl/en

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

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: correct property names in integration test for standard detail

Updated test to check for requiredProperties and commonProperties
instead of essentialProperties to match actual get_node response structure.

Conceived by Romuald Członkowski - www.aiadvisors.pl/en

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

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-24 17:06:21 +01:00

555 lines
24 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { N8NDocumentationMCPServer } from '../../../src/mcp/server';
// Mock the database and dependencies
vi.mock('../../../src/database/database-adapter');
vi.mock('../../../src/database/node-repository');
vi.mock('../../../src/templates/template-service');
vi.mock('../../../src/utils/logger');
class TestableN8NMCPServer extends N8NDocumentationMCPServer {
// Expose the private validateToolParams method for testing
public testValidateToolParams(toolName: string, args: any, requiredParams: string[]): void {
return (this as any).validateToolParams(toolName, args, requiredParams);
}
// Expose the private executeTool method for testing
public async testExecuteTool(name: string, args: any): Promise<any> {
return (this as any).executeTool(name, args);
}
}
describe('Parameter Validation', () => {
let server: TestableN8NMCPServer;
beforeEach(() => {
// Set environment variable to use in-memory database
process.env.NODE_DB_PATH = ':memory:';
server = new TestableN8NMCPServer();
});
afterEach(() => {
delete process.env.NODE_DB_PATH;
});
describe('validateToolParams', () => {
describe('Basic Parameter Validation', () => {
it('should pass validation when all required parameters are provided', () => {
const args = { nodeType: 'nodes-base.httpRequest', config: {} };
expect(() => {
server.testValidateToolParams('test_tool', args, ['nodeType', 'config']);
}).not.toThrow();
});
it('should throw error when required parameter is missing', () => {
const args = { config: {} };
expect(() => {
server.testValidateToolParams('test_tool', args, ['nodeType', 'config']);
}).toThrow('Missing required parameters for test_tool: nodeType');
});
it('should throw error when multiple required parameters are missing', () => {
const args = {};
expect(() => {
server.testValidateToolParams('test_tool', args, ['nodeType', 'config', 'query']);
}).toThrow('Missing required parameters for test_tool: nodeType, config, query');
});
it('should throw error when required parameter is undefined', () => {
const args = { nodeType: undefined, config: {} };
expect(() => {
server.testValidateToolParams('test_tool', args, ['nodeType', 'config']);
}).toThrow('Missing required parameters for test_tool: nodeType');
});
it('should throw error when required parameter is null', () => {
const args = { nodeType: null, config: {} };
expect(() => {
server.testValidateToolParams('test_tool', args, ['nodeType', 'config']);
}).toThrow('Missing required parameters for test_tool: nodeType');
});
it('should reject when required parameter is empty string (Issue #275 fix)', () => {
const args = { query: '', limit: 10 };
expect(() => {
server.testValidateToolParams('test_tool', args, ['query']);
}).toThrow('String parameters cannot be empty');
});
it('should pass when required parameter is zero', () => {
const args = { limit: 0, query: 'test' };
expect(() => {
server.testValidateToolParams('test_tool', args, ['limit']);
}).not.toThrow();
});
it('should pass when required parameter is false', () => {
const args = { includeData: false, id: '123' };
expect(() => {
server.testValidateToolParams('test_tool', args, ['includeData']);
}).not.toThrow();
});
});
describe('Edge Cases', () => {
it('should handle empty args object', () => {
expect(() => {
server.testValidateToolParams('test_tool', {}, ['param1']);
}).toThrow('Missing required parameters for test_tool: param1');
});
it('should handle null args', () => {
expect(() => {
server.testValidateToolParams('test_tool', null, ['param1']);
}).toThrow();
});
it('should handle undefined args', () => {
expect(() => {
server.testValidateToolParams('test_tool', undefined, ['param1']);
}).toThrow();
});
it('should pass when no required parameters are specified', () => {
const args = { optionalParam: 'value' };
expect(() => {
server.testValidateToolParams('test_tool', args, []);
}).not.toThrow();
});
it('should handle special characters in parameter names', () => {
const args = { 'param-with-dash': 'value', 'param_with_underscore': 'value' };
expect(() => {
server.testValidateToolParams('test_tool', args, ['param-with-dash', 'param_with_underscore']);
}).not.toThrow();
});
});
});
describe('Tool-Specific Parameter Validation', () => {
// Mock the actual tool methods to avoid database calls
beforeEach(() => {
// Mock all the tool methods that would be called
vi.spyOn(server as any, 'getNode').mockResolvedValue({ mockResult: true });
vi.spyOn(server as any, 'searchNodes').mockResolvedValue({ results: [] });
vi.spyOn(server as any, 'getNodeDocumentation').mockResolvedValue({ docs: 'test' });
vi.spyOn(server as any, 'searchNodeProperties').mockResolvedValue({ properties: [] });
// Note: getNodeForTask removed in v2.15.0
vi.spyOn(server as any, 'validateNodeConfig').mockResolvedValue({ valid: true });
vi.spyOn(server as any, 'validateNodeMinimal').mockResolvedValue({ missing: [] });
vi.spyOn(server as any, 'getPropertyDependencies').mockResolvedValue({ dependencies: {} });
vi.spyOn(server as any, 'getNodeAsToolInfo').mockResolvedValue({ toolInfo: true });
vi.spyOn(server as any, 'listNodeTemplates').mockResolvedValue({ templates: [] });
vi.spyOn(server as any, 'getTemplate').mockResolvedValue({ template: {} });
vi.spyOn(server as any, 'searchTemplates').mockResolvedValue({ templates: [] });
vi.spyOn(server as any, 'getTemplatesForTask').mockResolvedValue({ templates: [] });
vi.spyOn(server as any, 'validateWorkflow').mockResolvedValue({ valid: true });
vi.spyOn(server as any, 'validateWorkflowConnections').mockResolvedValue({ valid: true });
vi.spyOn(server as any, 'validateWorkflowExpressions').mockResolvedValue({ valid: true });
});
describe('get_node', () => {
it('should require nodeType parameter', async () => {
await expect(server.testExecuteTool('get_node', {}))
.rejects.toThrow('Missing required parameters for get_node: nodeType');
});
it('should succeed with valid nodeType', async () => {
const result = await server.testExecuteTool('get_node', {
nodeType: 'nodes-base.httpRequest'
});
expect(result).toEqual({ mockResult: true });
});
});
describe('search_nodes', () => {
it('should require query parameter', async () => {
await expect(server.testExecuteTool('search_nodes', {}))
.rejects.toThrow('search_nodes: Validation failed:\n • query: query is required');
});
it('should succeed with valid query', async () => {
const result = await server.testExecuteTool('search_nodes', {
query: 'http'
});
expect(result).toEqual({ results: [] });
});
it('should handle optional limit parameter', async () => {
const result = await server.testExecuteTool('search_nodes', {
query: 'http',
limit: 10
});
expect(result).toEqual({ results: [] });
});
it('should reject invalid limit value', async () => {
await expect(server.testExecuteTool('search_nodes', {
query: 'http',
limit: 'invalid'
})).rejects.toThrow('search_nodes: Validation failed:\n • limit: limit must be a number, got string');
});
});
describe('validate_node_operation', () => {
it('should require nodeType and config parameters', async () => {
await expect(server.testExecuteTool('validate_node_operation', {}))
.rejects.toThrow('validate_node_operation: Validation failed:\n • nodeType: nodeType is required\n • config: config is required');
});
it('should require nodeType parameter when config is provided', async () => {
await expect(server.testExecuteTool('validate_node_operation', { config: {} }))
.rejects.toThrow('validate_node_operation: Validation failed:\n • nodeType: nodeType is required');
});
it('should require config parameter when nodeType is provided', async () => {
await expect(server.testExecuteTool('validate_node_operation', { nodeType: 'nodes-base.httpRequest' }))
.rejects.toThrow('validate_node_operation: Validation failed:\n • config: config is required');
});
it('should succeed with valid parameters', async () => {
const result = await server.testExecuteTool('validate_node_operation', {
nodeType: 'nodes-base.httpRequest',
config: { method: 'GET', url: 'https://api.example.com' }
});
expect(result).toEqual({ valid: true });
});
});
describe('search_node_properties', () => {
it('should require nodeType and query parameters', async () => {
await expect(server.testExecuteTool('search_node_properties', {}))
.rejects.toThrow('Missing required parameters for search_node_properties: nodeType, query');
});
it('should succeed with valid parameters', async () => {
const result = await server.testExecuteTool('search_node_properties', {
nodeType: 'nodes-base.httpRequest',
query: 'auth'
});
expect(result).toEqual({ properties: [] });
});
it('should handle optional maxResults parameter', async () => {
const result = await server.testExecuteTool('search_node_properties', {
nodeType: 'nodes-base.httpRequest',
query: 'auth',
maxResults: 5
});
expect(result).toEqual({ properties: [] });
});
});
describe('list_node_templates', () => {
it('should require nodeTypes parameter', async () => {
await expect(server.testExecuteTool('list_node_templates', {}))
.rejects.toThrow('list_node_templates: Validation failed:\n • nodeTypes: nodeTypes is required');
});
it('should succeed with valid nodeTypes array', async () => {
const result = await server.testExecuteTool('list_node_templates', {
nodeTypes: ['nodes-base.httpRequest', 'nodes-base.slack']
});
expect(result).toEqual({ templates: [] });
});
});
describe('get_template', () => {
it('should require templateId parameter', async () => {
await expect(server.testExecuteTool('get_template', {}))
.rejects.toThrow('Missing required parameters for get_template: templateId');
});
it('should succeed with valid templateId', async () => {
const result = await server.testExecuteTool('get_template', {
templateId: 123
});
expect(result).toEqual({ template: {} });
});
});
});
describe('Numeric Parameter Conversion', () => {
beforeEach(() => {
vi.spyOn(server as any, 'searchNodes').mockResolvedValue({ results: [] });
vi.spyOn(server as any, 'searchNodeProperties').mockResolvedValue({ properties: [] });
vi.spyOn(server as any, 'listNodeTemplates').mockResolvedValue({ templates: [] });
vi.spyOn(server as any, 'getTemplate').mockResolvedValue({ template: {} });
});
describe('limit parameter conversion', () => {
it('should reject string limit values', async () => {
await expect(server.testExecuteTool('search_nodes', {
query: 'test',
limit: '15'
})).rejects.toThrow('search_nodes: Validation failed:\n • limit: limit must be a number, got string');
});
it('should reject invalid string limit values', async () => {
await expect(server.testExecuteTool('search_nodes', {
query: 'test',
limit: 'invalid'
})).rejects.toThrow('search_nodes: Validation failed:\n • limit: limit must be a number, got string');
});
it('should use default when limit is undefined', async () => {
const mockSearchNodes = vi.spyOn(server as any, 'searchNodes');
await server.testExecuteTool('search_nodes', {
query: 'test'
});
expect(mockSearchNodes).toHaveBeenCalledWith('test', 20, { mode: undefined });
});
it('should reject zero as limit due to minimum constraint', async () => {
await expect(server.testExecuteTool('search_nodes', {
query: 'test',
limit: 0
})).rejects.toThrow('search_nodes: Validation failed:\n • limit: limit must be at least 1, got 0');
});
});
describe('maxResults parameter conversion', () => {
it('should convert string numbers to numbers', async () => {
const mockSearchNodeProperties = vi.spyOn(server as any, 'searchNodeProperties');
await server.testExecuteTool('search_node_properties', {
nodeType: 'nodes-base.httpRequest',
query: 'auth',
maxResults: '5'
});
expect(mockSearchNodeProperties).toHaveBeenCalledWith('nodes-base.httpRequest', 'auth', 5);
});
it('should use default when maxResults is invalid', async () => {
const mockSearchNodeProperties = vi.spyOn(server as any, 'searchNodeProperties');
await server.testExecuteTool('search_node_properties', {
nodeType: 'nodes-base.httpRequest',
query: 'auth',
maxResults: 'invalid'
});
expect(mockSearchNodeProperties).toHaveBeenCalledWith('nodes-base.httpRequest', 'auth', 20);
});
});
describe('templateLimit parameter conversion', () => {
it('should reject string limit values', async () => {
await expect(server.testExecuteTool('list_node_templates', {
nodeTypes: ['nodes-base.httpRequest'],
limit: '5'
})).rejects.toThrow('list_node_templates: Validation failed:\n • limit: limit must be a number, got string');
});
it('should reject invalid string limit values', async () => {
await expect(server.testExecuteTool('list_node_templates', {
nodeTypes: ['nodes-base.httpRequest'],
limit: 'invalid'
})).rejects.toThrow('list_node_templates: Validation failed:\n • limit: limit must be a number, got string');
});
});
describe('templateId parameter handling', () => {
it('should pass through numeric templateId', async () => {
const mockGetTemplate = vi.spyOn(server as any, 'getTemplate');
await server.testExecuteTool('get_template', {
templateId: 123
});
expect(mockGetTemplate).toHaveBeenCalledWith(123, 'full');
});
it('should convert string templateId to number', async () => {
const mockGetTemplate = vi.spyOn(server as any, 'getTemplate');
await server.testExecuteTool('get_template', {
templateId: '123'
});
expect(mockGetTemplate).toHaveBeenCalledWith(123, 'full');
});
});
});
describe('Tools with No Required Parameters', () => {
beforeEach(() => {
vi.spyOn(server as any, 'getToolsDocumentation').mockResolvedValue({ docs: 'test' });
vi.spyOn(server as any, 'listNodes').mockResolvedValue({ nodes: [] });
vi.spyOn(server as any, 'listAITools').mockResolvedValue({ tools: [] });
vi.spyOn(server as any, 'getDatabaseStatistics').mockResolvedValue({ stats: {} });
vi.spyOn(server as any, 'listTasks').mockResolvedValue({ tasks: [] });
});
it('should allow tools_documentation with no parameters', async () => {
const result = await server.testExecuteTool('tools_documentation', {});
expect(result).toEqual({ docs: 'test' });
});
it('should allow list_nodes with no parameters', async () => {
const result = await server.testExecuteTool('list_nodes', {});
expect(result).toEqual({ nodes: [] });
});
it('should allow list_ai_tools with no parameters', async () => {
const result = await server.testExecuteTool('list_ai_tools', {});
expect(result).toEqual({ tools: [] });
});
it('should allow get_database_statistics with no parameters', async () => {
const result = await server.testExecuteTool('get_database_statistics', {});
expect(result).toEqual({ stats: {} });
});
it('should allow list_tasks with no parameters', async () => {
const result = await server.testExecuteTool('list_tasks', {});
expect(result).toEqual({ tasks: [] });
});
});
describe('Error Message Quality', () => {
it('should provide clear error messages with tool name', () => {
expect(() => {
server.testValidateToolParams('get_node', {}, ['nodeType']);
}).toThrow('Missing required parameters for get_node: nodeType. Please provide the required parameters to use this tool.');
});
it('should list all missing parameters', () => {
expect(() => {
server.testValidateToolParams('validate_node_operation', { profile: 'strict' }, ['nodeType', 'config']);
}).toThrow('validate_node_operation: Validation failed:\n • nodeType: nodeType is required\n • config: config is required');
});
it('should include helpful guidance', () => {
try {
server.testValidateToolParams('test_tool', {}, ['param1', 'param2']);
} catch (error: any) {
expect(error.message).toContain('Please provide the required parameters to use this tool');
}
});
});
describe('MCP Error Response Handling', () => {
it('should convert validation errors to MCP error responses rather than throwing exceptions', async () => {
// This test simulates what happens at the MCP level when a tool validation fails
// The server should catch the validation error and return it as an MCP error response
// Directly test the executeTool method to ensure it throws appropriately
// The MCP server's request handler should catch these and convert to error responses
await expect(server.testExecuteTool('get_node', {}))
.rejects.toThrow('Missing required parameters for get_node: nodeType');
await expect(server.testExecuteTool('search_nodes', {}))
.rejects.toThrow('search_nodes: Validation failed:\n • query: query is required');
await expect(server.testExecuteTool('validate_node_operation', { nodeType: 'test' }))
.rejects.toThrow('validate_node_operation: Validation failed:\n • config: config is required');
});
it('should handle edge cases in parameter validation gracefully', async () => {
// Test with null args (should be handled by args = args || {})
await expect(server.testExecuteTool('get_node', null))
.rejects.toThrow('Missing required parameters');
// Test with undefined args
await expect(server.testExecuteTool('get_node', undefined))
.rejects.toThrow('Missing required parameters');
});
it('should provide consistent error format across all tools', async () => {
// Tools using legacy validation
const legacyValidationTools = [
{ name: 'get_node', args: {}, expected: 'Missing required parameters for get_node: nodeType' },
{ name: 'get_node_documentation', args: {}, expected: 'Missing required parameters for get_node_documentation: nodeType' },
{ name: 'search_node_properties', args: {}, expected: 'Missing required parameters for search_node_properties: nodeType, query' },
// Note: get_node_for_task removed in v2.15.0
{ name: 'get_property_dependencies', args: {}, expected: 'Missing required parameters for get_property_dependencies: nodeType' },
{ name: 'get_node_as_tool_info', args: {}, expected: 'Missing required parameters for get_node_as_tool_info: nodeType' },
{ name: 'get_template', args: {}, expected: 'Missing required parameters for get_template: templateId' },
];
for (const tool of legacyValidationTools) {
await expect(server.testExecuteTool(tool.name, tool.args))
.rejects.toThrow(tool.expected);
}
// Tools using new schema validation
const schemaValidationTools = [
{ name: 'search_nodes', args: {}, expected: 'search_nodes: Validation failed:\n • query: query is required' },
{ name: 'validate_node_operation', args: {}, expected: 'validate_node_operation: Validation failed:\n • nodeType: nodeType is required\n • config: config is required' },
{ name: 'validate_node_minimal', args: {}, expected: 'validate_node_minimal: Validation failed:\n • nodeType: nodeType is required\n • config: config is required' },
{ name: 'list_node_templates', args: {}, expected: 'list_node_templates: Validation failed:\n • nodeTypes: nodeTypes is required' },
];
for (const tool of schemaValidationTools) {
await expect(server.testExecuteTool(tool.name, tool.args))
.rejects.toThrow(tool.expected);
}
});
it('should validate n8n management tools parameters', async () => {
// Mock the n8n handlers to avoid actual API calls
const mockHandlers = [
'handleCreateWorkflow',
'handleGetWorkflow',
'handleGetWorkflowDetails',
'handleGetWorkflowStructure',
'handleGetWorkflowMinimal',
'handleUpdateWorkflow',
'handleDeleteWorkflow',
'handleValidateWorkflow',
'handleTriggerWebhookWorkflow',
'handleGetExecution',
'handleDeleteExecution'
];
for (const handler of mockHandlers) {
vi.doMock('../../../src/mcp/handlers-n8n-manager', () => ({
[handler]: vi.fn().mockResolvedValue({ success: true })
}));
}
vi.doMock('../../../src/mcp/handlers-workflow-diff', () => ({
handleUpdatePartialWorkflow: vi.fn().mockResolvedValue({ success: true })
}));
const n8nToolsWithRequiredParams = [
{ name: 'n8n_create_workflow', args: {}, expected: 'n8n_create_workflow: Validation failed:\n • name: name is required\n • nodes: nodes is required\n • connections: connections is required' },
{ name: 'n8n_get_workflow', args: {}, expected: 'n8n_get_workflow: Validation failed:\n • id: id is required' },
{ name: 'n8n_get_workflow_details', args: {}, expected: 'n8n_get_workflow_details: Validation failed:\n • id: id is required' },
{ name: 'n8n_get_workflow_structure', args: {}, expected: 'n8n_get_workflow_structure: Validation failed:\n • id: id is required' },
{ name: 'n8n_get_workflow_minimal', args: {}, expected: 'n8n_get_workflow_minimal: Validation failed:\n • id: id is required' },
{ name: 'n8n_update_full_workflow', args: {}, expected: 'n8n_update_full_workflow: Validation failed:\n • id: id is required' },
{ name: 'n8n_delete_workflow', args: {}, expected: 'n8n_delete_workflow: Validation failed:\n • id: id is required' },
{ name: 'n8n_validate_workflow', args: {}, expected: 'n8n_validate_workflow: Validation failed:\n • id: id is required' },
{ name: 'n8n_get_execution', args: {}, expected: 'n8n_get_execution: Validation failed:\n • id: id is required' },
{ name: 'n8n_delete_execution', args: {}, expected: 'n8n_delete_execution: Validation failed:\n • id: id is required' },
];
// n8n_update_partial_workflow and n8n_trigger_webhook_workflow use legacy validation
await expect(server.testExecuteTool('n8n_update_partial_workflow', {}))
.rejects.toThrow('Missing required parameters for n8n_update_partial_workflow: id, operations');
await expect(server.testExecuteTool('n8n_trigger_webhook_workflow', {}))
.rejects.toThrow('Missing required parameters for n8n_trigger_webhook_workflow: webhookUrl');
for (const tool of n8nToolsWithRequiredParams) {
await expect(server.testExecuteTool(tool.name, tool.args))
.rejects.toThrow(tool.expected);
}
});
});
});