mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 05:23:08 +00:00
* 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>
534 lines
17 KiB
TypeScript
534 lines
17 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
import { TestableN8NMCPServer } from './test-helpers';
|
|
|
|
describe('MCP Error Handling', () => {
|
|
let mcpServer: TestableN8NMCPServer;
|
|
let client: Client;
|
|
|
|
beforeEach(async () => {
|
|
mcpServer = new TestableN8NMCPServer();
|
|
await mcpServer.initialize();
|
|
|
|
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
|
|
await mcpServer.connectToTransport(serverTransport);
|
|
|
|
client = new Client({
|
|
name: 'test-client',
|
|
version: '1.0.0'
|
|
}, {
|
|
capabilities: {}
|
|
});
|
|
|
|
await client.connect(clientTransport);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await client.close();
|
|
await mcpServer.close();
|
|
});
|
|
|
|
describe('JSON-RPC Error Codes', () => {
|
|
it('should handle invalid request (parse error)', async () => {
|
|
// The MCP SDK handles parsing, so we test with invalid method instead
|
|
try {
|
|
await (client as any).request({
|
|
method: '', // Empty method
|
|
params: {}
|
|
});
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
}
|
|
});
|
|
|
|
it('should handle method not found', async () => {
|
|
try {
|
|
await (client as any).request({
|
|
method: 'nonexistent/method',
|
|
params: {}
|
|
});
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error.message).toContain('not found');
|
|
}
|
|
});
|
|
|
|
it('should handle invalid params', async () => {
|
|
try {
|
|
// Missing required parameter
|
|
await client.callTool({ name: 'get_node', arguments: {} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
// The error now properly validates required parameters
|
|
expect(error.message).toContain("Missing required parameters");
|
|
}
|
|
});
|
|
|
|
it('should handle internal errors gracefully', async () => {
|
|
try {
|
|
// Invalid node type format should cause internal processing error
|
|
await client.callTool({ name: 'get_node', arguments: {
|
|
nodeType: 'completely-invalid-format-$$$$'
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error.message).toContain('not found');
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Tool-Specific Errors', () => {
|
|
describe('Node Discovery Errors', () => {
|
|
it('should handle invalid category filter', async () => {
|
|
const response = await client.callTool({ name: 'list_nodes', arguments: {
|
|
category: 'invalid_category'
|
|
} });
|
|
|
|
// Should return empty array, not error
|
|
const result = JSON.parse((response as any).content[0].text);
|
|
expect(result).toHaveProperty('nodes');
|
|
expect(Array.isArray(result.nodes)).toBe(true);
|
|
expect(result.nodes).toHaveLength(0);
|
|
});
|
|
|
|
it('should handle invalid search mode', async () => {
|
|
try {
|
|
await client.callTool({ name: 'search_nodes', arguments: {
|
|
query: 'test',
|
|
mode: 'INVALID_MODE' as any
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
}
|
|
});
|
|
|
|
it('should handle empty search query', async () => {
|
|
try {
|
|
await client.callTool({ name: 'search_nodes', arguments: {
|
|
query: ''
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error.message).toContain("search_nodes: Validation failed:");
|
|
expect(error.message).toContain("query: query cannot be empty");
|
|
}
|
|
});
|
|
|
|
it('should handle non-existent node types', async () => {
|
|
try {
|
|
await client.callTool({ name: 'get_node', arguments: {
|
|
nodeType: 'nodes-base.thisDoesNotExist'
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error.message).toContain('not found');
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Validation Errors', () => {
|
|
it('should handle invalid validation profile', async () => {
|
|
try {
|
|
await client.callTool({ name: 'validate_node_operation', arguments: {
|
|
nodeType: 'nodes-base.httpRequest',
|
|
config: { method: 'GET', url: 'https://api.example.com' },
|
|
profile: 'invalid_profile' as any
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
}
|
|
});
|
|
|
|
it('should handle malformed workflow structure', async () => {
|
|
try {
|
|
await client.callTool({ name: 'validate_workflow', arguments: {
|
|
workflow: {
|
|
// Missing required 'nodes' array
|
|
connections: {}
|
|
}
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
expect(error.message).toContain("validate_workflow: Validation failed:");
|
|
expect(error.message).toContain("workflow.nodes: workflow.nodes is required");
|
|
}
|
|
});
|
|
|
|
it('should handle circular workflow references', async () => {
|
|
const workflow = {
|
|
nodes: [
|
|
{
|
|
id: '1',
|
|
name: 'Node1',
|
|
type: 'nodes-base.noOp',
|
|
typeVersion: 1,
|
|
position: [0, 0],
|
|
parameters: {}
|
|
},
|
|
{
|
|
id: '2',
|
|
name: 'Node2',
|
|
type: 'nodes-base.noOp',
|
|
typeVersion: 1,
|
|
position: [250, 0],
|
|
parameters: {}
|
|
}
|
|
],
|
|
connections: {
|
|
'Node1': {
|
|
'main': [[{ node: 'Node2', type: 'main', index: 0 }]]
|
|
},
|
|
'Node2': {
|
|
'main': [[{ node: 'Node1', type: 'main', index: 0 }]]
|
|
}
|
|
}
|
|
};
|
|
|
|
const response = await client.callTool({ name: 'validate_workflow', arguments: {
|
|
workflow
|
|
} });
|
|
|
|
const validation = JSON.parse((response as any).content[0].text);
|
|
expect(validation.warnings).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Documentation Errors', () => {
|
|
it('should handle non-existent documentation topics', async () => {
|
|
const response = await client.callTool({ name: 'tools_documentation', arguments: {
|
|
topic: 'completely_fake_tool'
|
|
} });
|
|
|
|
expect((response as any).content[0].text).toContain('not found');
|
|
});
|
|
|
|
it('should handle invalid depth parameter', async () => {
|
|
try {
|
|
await client.callTool({ name: 'tools_documentation', arguments: {
|
|
depth: 'invalid_depth' as any
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Large Payload Handling', () => {
|
|
it('should handle large node info requests', async () => {
|
|
// HTTP Request node has extensive properties
|
|
const response = await client.callTool({ name: 'get_node', arguments: {
|
|
nodeType: 'nodes-base.httpRequest',
|
|
detail: 'full'
|
|
} });
|
|
|
|
expect((response as any).content[0].text.length).toBeGreaterThan(10000);
|
|
|
|
// Should be valid JSON
|
|
const nodeInfo = JSON.parse((response as any).content[0].text);
|
|
expect(nodeInfo).toHaveProperty('nodeType');
|
|
expect(nodeInfo).toHaveProperty('displayName');
|
|
});
|
|
|
|
it('should handle large workflow validation', async () => {
|
|
// Create a large workflow
|
|
const nodes = [];
|
|
const connections: any = {};
|
|
|
|
for (let i = 0; i < 50; i++) {
|
|
const nodeName = `Node${i}`;
|
|
nodes.push({
|
|
id: String(i),
|
|
name: nodeName,
|
|
type: 'nodes-base.noOp',
|
|
typeVersion: 1,
|
|
position: [i * 100, 0],
|
|
parameters: {}
|
|
});
|
|
|
|
if (i > 0) {
|
|
const prevNode = `Node${i - 1}`;
|
|
connections[prevNode] = {
|
|
'main': [[{ node: nodeName, type: 'main', index: 0 }]]
|
|
};
|
|
}
|
|
}
|
|
|
|
const response = await client.callTool({ name: 'validate_workflow', arguments: {
|
|
workflow: { nodes, connections }
|
|
} });
|
|
|
|
const validation = JSON.parse((response as any).content[0].text);
|
|
expect(validation).toHaveProperty('valid');
|
|
});
|
|
|
|
it('should handle many concurrent requests', async () => {
|
|
const requestCount = 50;
|
|
const promises = [];
|
|
|
|
for (let i = 0; i < requestCount; i++) {
|
|
promises.push(
|
|
client.callTool({ name: 'list_nodes', arguments: {
|
|
limit: 1,
|
|
category: i % 2 === 0 ? 'trigger' : 'transform'
|
|
} })
|
|
);
|
|
}
|
|
|
|
const responses = await Promise.all(promises);
|
|
expect(responses).toHaveLength(requestCount);
|
|
});
|
|
});
|
|
|
|
describe('Invalid JSON Handling', () => {
|
|
it('should handle invalid JSON in tool parameters', async () => {
|
|
try {
|
|
// Config should be an object, not a string
|
|
await client.callTool({ name: 'validate_node_operation', arguments: {
|
|
nodeType: 'nodes-base.httpRequest',
|
|
config: 'invalid json string' as any
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
}
|
|
});
|
|
|
|
it('should handle malformed workflow JSON', async () => {
|
|
try {
|
|
await client.callTool({ name: 'validate_workflow', arguments: {
|
|
workflow: 'not a valid workflow object' as any
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Timeout Scenarios', () => {
|
|
it('should handle rapid sequential requests', async () => {
|
|
const start = Date.now();
|
|
|
|
for (let i = 0; i < 20; i++) {
|
|
await client.callTool({ name: 'get_database_statistics', arguments: {} });
|
|
}
|
|
|
|
const duration = Date.now() - start;
|
|
|
|
// Should complete reasonably quickly (under 5 seconds)
|
|
expect(duration).toBeLessThan(5000);
|
|
});
|
|
|
|
it('should handle long-running operations', async () => {
|
|
// Search with complex query that requires more processing
|
|
const response = await client.callTool({ name: 'search_nodes', arguments: {
|
|
query: 'a b c d e f g h i j k l m n o p q r s t u v w x y z',
|
|
mode: 'AND'
|
|
} });
|
|
|
|
expect(response).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Memory Pressure', () => {
|
|
it('should handle multiple large responses', async () => {
|
|
const promises = [];
|
|
|
|
// Request multiple large node infos
|
|
const largeNodes = [
|
|
'nodes-base.httpRequest',
|
|
'nodes-base.postgres',
|
|
'nodes-base.googleSheets',
|
|
'nodes-base.slack',
|
|
'nodes-base.gmail'
|
|
];
|
|
|
|
for (const nodeType of largeNodes) {
|
|
promises.push(
|
|
client.callTool({ name: 'get_node', arguments: { nodeType } })
|
|
.catch(() => null) // Some might not exist
|
|
);
|
|
}
|
|
|
|
const responses = await Promise.all(promises);
|
|
const validResponses = responses.filter(r => r !== null);
|
|
|
|
expect(validResponses.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should handle workflow with many nodes', async () => {
|
|
const nodeCount = 100;
|
|
const nodes = [];
|
|
|
|
for (let i = 0; i < nodeCount; i++) {
|
|
nodes.push({
|
|
id: String(i),
|
|
name: `Node${i}`,
|
|
type: 'nodes-base.noOp',
|
|
typeVersion: 1,
|
|
position: [i * 50, Math.floor(i / 10) * 100],
|
|
parameters: {
|
|
// Add some data to increase memory usage
|
|
data: `This is some test data for node ${i}`.repeat(10)
|
|
}
|
|
});
|
|
}
|
|
|
|
const response = await client.callTool({ name: 'validate_workflow', arguments: {
|
|
workflow: {
|
|
nodes,
|
|
connections: {}
|
|
}
|
|
} });
|
|
|
|
const validation = JSON.parse((response as any).content[0].text);
|
|
expect(validation).toHaveProperty('valid');
|
|
});
|
|
});
|
|
|
|
describe('Error Recovery', () => {
|
|
it('should continue working after errors', async () => {
|
|
// Cause an error
|
|
try {
|
|
await client.callTool({ name: 'get_node', arguments: {
|
|
nodeType: 'invalid'
|
|
} });
|
|
} catch (error) {
|
|
// Expected
|
|
}
|
|
|
|
// Should still work
|
|
const response = await client.callTool({ name: 'list_nodes', arguments: { limit: 1 } });
|
|
expect(response).toBeDefined();
|
|
});
|
|
|
|
it('should handle mixed success and failure', async () => {
|
|
const promises = [
|
|
client.callTool({ name: 'list_nodes', arguments: { limit: 5 } }),
|
|
client.callTool({ name: 'get_node', arguments: { nodeType: 'invalid' } }).catch(e => ({ error: e })),
|
|
client.callTool({ name: 'get_database_statistics', arguments: {} }),
|
|
client.callTool({ name: 'search_nodes', arguments: { query: '' } }).catch(e => ({ error: e })),
|
|
client.callTool({ name: 'list_ai_tools', arguments: {} })
|
|
];
|
|
|
|
const results = await Promise.all(promises);
|
|
|
|
// Some should succeed, some should fail
|
|
const successes = results.filter(r => !('error' in r));
|
|
const failures = results.filter(r => 'error' in r);
|
|
|
|
expect(successes.length).toBeGreaterThan(0);
|
|
expect(failures.length).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('Edge Cases', () => {
|
|
it('should handle empty responses gracefully', async () => {
|
|
const response = await client.callTool({ name: 'list_nodes', arguments: {
|
|
category: 'nonexistent_category'
|
|
} });
|
|
|
|
const result = JSON.parse((response as any).content[0].text);
|
|
expect(result).toHaveProperty('nodes');
|
|
expect(Array.isArray(result.nodes)).toBe(true);
|
|
expect(result.nodes).toHaveLength(0);
|
|
});
|
|
|
|
it('should handle special characters in parameters', async () => {
|
|
const response = await client.callTool({ name: 'search_nodes', arguments: {
|
|
query: 'test!@#$%^&*()_+-=[]{}|;\':",./<>?'
|
|
} });
|
|
|
|
// Should return results or empty array, not error
|
|
const result = JSON.parse((response as any).content[0].text);
|
|
expect(result).toHaveProperty('results');
|
|
expect(Array.isArray(result.results)).toBe(true);
|
|
});
|
|
|
|
it('should handle unicode in parameters', async () => {
|
|
const response = await client.callTool({ name: 'search_nodes', arguments: {
|
|
query: 'test 测试 тест परीक्षण'
|
|
} });
|
|
|
|
const result = JSON.parse((response as any).content[0].text);
|
|
expect(result).toHaveProperty('results');
|
|
expect(Array.isArray(result.results)).toBe(true);
|
|
});
|
|
|
|
it('should handle null and undefined gracefully', async () => {
|
|
// Most tools should handle missing optional params
|
|
const response = await client.callTool({ name: 'list_nodes', arguments: {
|
|
limit: undefined as any,
|
|
category: null as any
|
|
} });
|
|
|
|
const result = JSON.parse((response as any).content[0].text);
|
|
expect(result).toHaveProperty('nodes');
|
|
expect(Array.isArray(result.nodes)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('Error Message Quality', () => {
|
|
it('should provide helpful error messages', async () => {
|
|
try {
|
|
// Use a truly invalid node type
|
|
await client.callTool({ name: 'get_node', arguments: {
|
|
nodeType: 'invalid-node-type-that-does-not-exist'
|
|
} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error.message).toBeDefined();
|
|
expect(error.message.length).toBeGreaterThan(10);
|
|
// Should mention the issue
|
|
expect(error.message.toLowerCase()).toMatch(/not found|invalid|missing/);
|
|
}
|
|
});
|
|
|
|
it('should indicate missing required parameters', async () => {
|
|
try {
|
|
await client.callTool({ name: 'search_nodes', arguments: {} });
|
|
expect.fail('Should have thrown an error');
|
|
} catch (error: any) {
|
|
expect(error).toBeDefined();
|
|
// The error now properly validates required parameters
|
|
expect(error.message).toContain("search_nodes: Validation failed:");
|
|
expect(error.message).toContain("query: query is required");
|
|
}
|
|
});
|
|
|
|
it('should provide context for validation errors', async () => {
|
|
const response = await client.callTool({ name: 'validate_node_operation', arguments: {
|
|
nodeType: 'nodes-base.httpRequest',
|
|
config: {
|
|
// Missing required fields
|
|
method: 'INVALID_METHOD'
|
|
}
|
|
} });
|
|
|
|
const validation = JSON.parse((response as any).content[0].text);
|
|
expect(validation.valid).toBe(false);
|
|
expect(validation.errors).toBeDefined();
|
|
expect(Array.isArray(validation.errors)).toBe(true);
|
|
expect(validation.errors.length).toBeGreaterThan(0);
|
|
if (validation.errors.length > 0) {
|
|
expect(validation.errors[0].message).toBeDefined();
|
|
// Field property might not exist on all error types
|
|
if (validation.errors[0].field !== undefined) {
|
|
expect(validation.errors[0].field).toBeDefined();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}); |