Files
n8n-mcp/tests/integration/mcp-protocol/protocol-compliance.test.ts
Romuald Członkowski ff69e4ccca feat: Tool Consolidation - Reduce MCP Tools by 38% (v2.26.0) (#439)
* feat: Remove 9 low-value tools and consolidate n8n_health_check (v2.25.0)

Telemetry-driven tool cleanup to improve API clarity:

**Removed Tools (9):**
- list_nodes - Use search_nodes instead
- list_ai_tools - Use search_nodes with isAITool filter
- list_tasks - Low usage (0.02%)
- get_database_statistics - Use n8n_health_check
- list_templates - Use search_templates or get_templates_for_task
- get_node_as_tool_info - Documented in get_node
- validate_workflow_connections - Use validate_workflow
- validate_workflow_expressions - Use validate_workflow
- n8n_list_available_tools - Use n8n_health_check
- n8n_diagnostic - Merged into n8n_health_check

**Consolidated Tool:**
- n8n_health_check now supports mode='diagnostic' for detailed troubleshooting

**Tool Count:**
- Before: 38 tools
- After: 31 tools (18% reduction)

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

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

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

* fix: cleanup stale references and update tests after tool removal

- Remove handleListAvailableTools dead code from handlers-n8n-manager.ts
- Update error messages to reference n8n_health_check(mode="diagnostic") instead of n8n_diagnostic
- Update tool counts in diagnostic messages (14 doc tools, 31 total)
- Fix error-handling.test.ts to use valid tools (search_nodes, tools_documentation)
- Remove obsolete list-tools.test.ts integration tests
- Remove unused ListToolsResponse type from response-types.ts
- Update tools.ts QUICK REFERENCE to remove list_nodes references
- Update tools-documentation.ts to remove references to removed tools
- Update tool-docs files to remove stale relatedTools references
- Fix tools.test.ts to not test removed tools (list_nodes, list_ai_tools, etc.)
- Fix parameter-validation.test.ts to not test removed tools
- Update handlers-n8n-manager.test.ts error message expectations

All 399 MCP unit tests now pass.

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: update integration tests to use valid tools after v2.25.0 removal

Replaced all references to removed tools in integration tests:
- list_nodes -> search_nodes
- get_database_statistics -> tools_documentation
- list_ai_tools -> search_nodes/tools_documentation
- list_tasks -> tools_documentation
- get_node_as_tool_info -> removed test section

Updated test files:
- tests/integration/mcp-protocol/basic-connection.test.ts
- tests/integration/mcp-protocol/performance.test.ts
- tests/integration/mcp-protocol/session-management.test.ts
- tests/integration/mcp-protocol/test-helpers.ts
- tests/integration/mcp-protocol/tool-invocation.test.ts
- tests/integration/telemetry/mcp-telemetry.test.ts
- tests/unit/mcp/disabled-tools.test.ts
- tests/unit/mcp/tools-documentation.test.ts

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>

* feat: Tool consolidation v2.26.0 - reduce tools by 38% (31 → 19)

Major consolidation of MCP tools using mode-based parameters for better
AI agent ergonomics:

Node Tools:
- get_node_documentation → get_node with mode='documentation'
- search_node_properties → get_node with mode='search_properties'
- get_property_dependencies → removed

Validation Tools:
- validate_node_operation + validate_node_minimal → validate_node with mode param

Template Tools:
- list_node_templates → search_templates with searchMode='nodes'
- search_templates_by_metadata → search_templates with searchMode='metadata'
- get_templates_for_task → search_templates with searchMode='task'

Workflow Getters:
- n8n_get_workflow_details/structure/minimal → n8n_get_workflow with mode param

Execution Tools:
- n8n_list/get/delete_execution → n8n_executions with action param

Test updates for all consolidated tools.

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

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

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

* docs: comprehensive README update for v2.26.0 tool consolidation

- Quick Start: Added hosted service (dashboard.n8n-mcp.com) as primary option
- Self-hosting: Renamed options to A (npx), B (Docker), C (Local), D (Railway)
- Removed: "Memory Leak Fix (v2.20.2)" section (outdated)
- Removed: "Known Issues" section (outdated container management)
- Claude Project Setup: Updated all tool references to v2.26.0 consolidated tools
  - validate_node({mode: 'minimal'|'full'}) instead of separate tools
  - search_templates({searchMode: ...}) unified template search
  - get_node({mode: 'docs'|'search_properties'}) for documentation
  - n8n_executions({action: ...}) unified execution management
- Available MCP Tools: Updated to show 19 consolidated tools (7 core + 12 mgmt)
- Recent Updates: Simplified to just link to CHANGELOG.md

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

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

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

* fix: update tool count from 31 to 19 in diagnostic message

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

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

* fix(tests): update tool count expectations for v2.26.0

Update handlers-n8n-manager.test.ts to expect new consolidated
tool counts (7/12/19) after v2.26.0 tool consolidation.

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-25 18:39:00 +01:00

299 lines
10 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 Protocol Compliance', () => {
let mcpServer: TestableN8NMCPServer;
let transport: InMemoryTransport;
let client: Client;
beforeEach(async () => {
mcpServer = new TestableN8NMCPServer();
await mcpServer.initialize();
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
transport = serverTransport;
// Connect MCP server to transport
await mcpServer.connectToTransport(transport);
// Create client
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 2.0 Compliance', () => {
it('should return proper JSON-RPC 2.0 response format', async () => {
const response = await client.listTools();
// Response should have tools array
expect(response).toHaveProperty('tools');
expect(Array.isArray((response as any).tools)).toBe(true);
});
it('should handle request with id correctly', async () => {
const response = await client.listTools();
expect(response).toBeDefined();
expect(typeof response).toBe('object');
});
it('should handle batch requests', async () => {
// Send multiple requests concurrently
const promises = [
client.listTools(),
client.listTools(),
client.listTools()
];
const responses = await Promise.all(promises);
expect(responses).toHaveLength(3);
responses.forEach(response => {
expect(response).toHaveProperty('tools');
});
});
it('should preserve request order in responses', async () => {
const requests = [];
const expectedOrder = [];
// Create requests with different tools to track order
for (let i = 0; i < 5; i++) {
expectedOrder.push(i);
requests.push(
client.callTool({ name: 'tools_documentation', arguments: {} })
.then(() => i)
);
}
const results = await Promise.all(requests);
expect(results).toEqual(expectedOrder);
});
});
describe('Protocol Version Negotiation', () => {
it('should negotiate protocol capabilities', async () => {
const serverInfo = await client.getServerVersion();
expect(serverInfo).toHaveProperty('name');
expect(serverInfo).toHaveProperty('version');
expect(serverInfo!.name).toBe('n8n-documentation-mcp');
});
it('should expose supported capabilities', async () => {
const serverCapabilities = client.getServerCapabilities();
expect(serverCapabilities).toBeDefined();
// Should support tools
expect(serverCapabilities).toHaveProperty('tools');
});
});
describe('Message Format Validation', () => {
it('should reject messages without method', async () => {
// Test by sending raw message through transport
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
const testClient = new Client({ name: 'test', version: '1.0.0' }, {});
await mcpServer.connectToTransport(serverTransport);
await testClient.connect(clientTransport);
try {
// This should fail as MCP SDK validates method
await (testClient as any).request({ method: '', params: {} });
expect.fail('Should have thrown an error');
} catch (error) {
expect(error).toBeDefined();
} finally {
await testClient.close();
}
});
it('should handle missing params gracefully', async () => {
// Most tools should work without params
const response = await client.callTool({ name: 'search_nodes', arguments: { query: 'webhook' } });
expect(response).toBeDefined();
});
it('should validate params schema', async () => {
try {
// Invalid nodeType format (missing prefix)
const response = await client.callTool({ name: 'get_node', arguments: {
nodeType: 'httpRequest' // Should be 'nodes-base.httpRequest'
} });
// Check if the response indicates an error
const text = (response as any).content[0].text;
expect(text).toContain('not found');
} catch (error: any) {
// If it throws, that's also acceptable
expect(error.message).toContain('not found');
}
});
});
describe('Content Types', () => {
it('should handle text content in tool responses', async () => {
const response = await client.callTool({ name: 'tools_documentation', arguments: {} });
expect((response as any).content).toHaveLength(1);
expect((response as any).content[0]).toHaveProperty('type', 'text');
expect((response as any).content[0]).toHaveProperty('text');
expect(typeof (response as any).content[0].text).toBe('string');
});
it('should handle large text responses', async () => {
// Get a large node info response
const response = await client.callTool({ name: 'get_node', arguments: {
nodeType: 'nodes-base.httpRequest'
} });
expect((response as any).content).toHaveLength(1);
expect((response as any).content[0].type).toBe('text');
expect((response as any).content[0].text.length).toBeGreaterThan(1000);
});
it('should handle JSON content properly', async () => {
const response = await client.callTool({ name: 'search_nodes', arguments: {
query: 'webhook',
limit: 5
} });
expect((response as any).content).toHaveLength(1);
const content = JSON.parse((response as any).content[0].text);
expect(content).toHaveProperty('results');
expect(Array.isArray(content.results)).toBe(true);
});
});
describe('Request/Response Correlation', () => {
it('should correlate concurrent requests correctly', async () => {
const requests = [
client.callTool({ name: 'get_node', arguments: { nodeType: 'nodes-base.httpRequest' } }),
client.callTool({ name: 'get_node', arguments: { nodeType: 'nodes-base.webhook' } }),
client.callTool({ name: 'get_node', arguments: { nodeType: 'nodes-base.slack' } })
];
const responses = await Promise.all(requests);
expect((responses[0] as any).content[0].text).toContain('httpRequest');
expect((responses[1] as any).content[0].text).toContain('webhook');
expect((responses[2] as any).content[0].text).toContain('slack');
});
it('should handle interleaved requests', async () => {
const results: string[] = [];
// Start multiple requests with different delays
const p1 = client.callTool({ name: 'tools_documentation', arguments: {} })
.then(() => { results.push('docs'); return 'docs'; });
const p2 = client.callTool({ name: 'search_nodes', arguments: { query: 'webhook', limit: 1 } })
.then(() => { results.push('nodes'); return 'nodes'; });
const p3 = client.callTool({ name: 'search_nodes', arguments: { query: 'http' } })
.then(() => { results.push('search'); return 'search'; });
const resolved = await Promise.all([p1, p2, p3]);
// All should complete
expect(resolved).toHaveLength(3);
expect(results).toHaveLength(3);
});
});
describe('Protocol Extensions', () => {
it('should handle tool-specific extensions', async () => {
// Test tool with complex params (using consolidated validate_node from v2.26.0)
const response = await client.callTool({ name: 'validate_node', arguments: {
nodeType: 'nodes-base.httpRequest',
config: {
method: 'GET',
url: 'https://api.example.com'
},
mode: 'full',
profile: 'runtime'
} });
expect((response as any).content).toHaveLength(1);
expect((response as any).content[0].type).toBe('text');
});
it('should support optional parameters', async () => {
// Call with minimal params
const response1 = await client.callTool({ name: 'search_nodes', arguments: { query: 'webhook' } });
// Call with all params
const response2 = await client.callTool({ name: 'search_nodes', arguments: {
query: 'webhook',
limit: 10,
mode: 'OR'
} });
expect(response1).toBeDefined();
expect(response2).toBeDefined();
});
});
describe('Transport Layer', () => {
it('should handle transport disconnection gracefully', async () => {
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
const testClient = new Client({ name: 'test', version: '1.0.0' }, {});
await mcpServer.connectToTransport(serverTransport);
await testClient.connect(clientTransport);
// Make a request
const response = await testClient.callTool({ name: 'tools_documentation', arguments: {} });
expect(response).toBeDefined();
// Close client
await testClient.close();
// Further requests should fail
try {
await testClient.callTool({ name: 'tools_documentation', arguments: {} });
expect.fail('Should have thrown an error');
} catch (error) {
expect(error).toBeDefined();
}
});
it('should handle multiple sequential connections', async () => {
// Close existing connection
await client.close();
await mcpServer.close();
// Create new connections
for (let i = 0; i < 3; i++) {
const engine = new TestableN8NMCPServer();
await engine.initialize();
const [serverTransport, clientTransport] = InMemoryTransport.createLinkedPair();
await engine.connectToTransport(serverTransport);
const testClient = new Client({ name: 'test', version: '1.0.0' }, {});
await testClient.connect(clientTransport);
const response = await testClient.callTool({ name: 'tools_documentation', arguments: {} });
expect(response).toBeDefined();
await testClient.close();
await engine.close();
}
});
});
});