mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-01-30 06:22:04 +00:00
* 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>
312 lines
12 KiB
TypeScript
312 lines
12 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
import { N8NDocumentationMCPServer } from '../../../src/mcp/server';
|
|
import { n8nDocumentationToolsFinal } from '../../../src/mcp/tools';
|
|
import { n8nManagementTools } from '../../../src/mcp/tools-n8n-manager';
|
|
|
|
// 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');
|
|
|
|
/**
|
|
* Test wrapper class that exposes private methods for unit testing.
|
|
* This pattern is preferred over modifying production code visibility
|
|
* or using reflection-based testing utilities.
|
|
*/
|
|
class TestableN8NMCPServer extends N8NDocumentationMCPServer {
|
|
/**
|
|
* Expose getDisabledTools() for testing environment variable parsing.
|
|
* @returns Set of disabled tool names from DISABLED_TOOLS env var
|
|
*/
|
|
public testGetDisabledTools(): Set<string> {
|
|
return (this as any).getDisabledTools();
|
|
}
|
|
|
|
/**
|
|
* Expose executeTool() for testing the defense-in-depth guard.
|
|
* @param name - Tool name to execute
|
|
* @param args - Tool arguments
|
|
* @returns Tool execution result
|
|
*/
|
|
public async testExecuteTool(name: string, args: any): Promise<any> {
|
|
return (this as any).executeTool(name, args);
|
|
}
|
|
}
|
|
|
|
describe('Disabled Tools Feature (Issue #410)', () => {
|
|
let server: TestableN8NMCPServer;
|
|
|
|
beforeEach(() => {
|
|
// Set environment variable to use in-memory database
|
|
process.env.NODE_DB_PATH = ':memory:';
|
|
});
|
|
|
|
afterEach(() => {
|
|
delete process.env.NODE_DB_PATH;
|
|
delete process.env.DISABLED_TOOLS;
|
|
});
|
|
|
|
describe('getDisabledTools() - Environment Variable Parsing', () => {
|
|
it('should return empty set when DISABLED_TOOLS is not set', () => {
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(0);
|
|
});
|
|
|
|
it('should return empty set when DISABLED_TOOLS is empty string', () => {
|
|
process.env.DISABLED_TOOLS = '';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(0);
|
|
});
|
|
|
|
it('should parse single disabled tool correctly', () => {
|
|
process.env.DISABLED_TOOLS = 'n8n_diagnostic';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(1);
|
|
expect(disabledTools.has('n8n_diagnostic')).toBe(true);
|
|
});
|
|
|
|
it('should parse multiple disabled tools correctly', () => {
|
|
process.env.DISABLED_TOOLS = 'n8n_diagnostic,n8n_health_check,search_nodes';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(3);
|
|
expect(disabledTools.has('n8n_diagnostic')).toBe(true);
|
|
expect(disabledTools.has('n8n_health_check')).toBe(true);
|
|
expect(disabledTools.has('search_nodes')).toBe(true);
|
|
});
|
|
|
|
it('should trim whitespace from tool names', () => {
|
|
process.env.DISABLED_TOOLS = ' n8n_diagnostic , n8n_health_check ';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(2);
|
|
expect(disabledTools.has('n8n_diagnostic')).toBe(true);
|
|
expect(disabledTools.has('n8n_health_check')).toBe(true);
|
|
});
|
|
|
|
it('should filter out empty entries from comma-separated list', () => {
|
|
process.env.DISABLED_TOOLS = 'n8n_diagnostic,,n8n_health_check,,,search_nodes';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(3);
|
|
expect(disabledTools.has('n8n_diagnostic')).toBe(true);
|
|
expect(disabledTools.has('n8n_health_check')).toBe(true);
|
|
expect(disabledTools.has('search_nodes')).toBe(true);
|
|
});
|
|
|
|
it('should handle single comma correctly', () => {
|
|
process.env.DISABLED_TOOLS = ',';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(0);
|
|
});
|
|
|
|
it('should handle multiple commas without values', () => {
|
|
process.env.DISABLED_TOOLS = ',,,';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('executeTool() - Disabled Tool Guard', () => {
|
|
it('should throw error when calling disabled tool', async () => {
|
|
process.env.DISABLED_TOOLS = 'tools_documentation';
|
|
server = new TestableN8NMCPServer();
|
|
|
|
await expect(async () => {
|
|
await server.testExecuteTool('tools_documentation', {});
|
|
}).rejects.toThrow("Tool 'tools_documentation' is disabled via DISABLED_TOOLS environment variable");
|
|
});
|
|
|
|
it('should allow calling enabled tool when others are disabled', async () => {
|
|
process.env.DISABLED_TOOLS = 'n8n_diagnostic,n8n_health_check';
|
|
server = new TestableN8NMCPServer();
|
|
|
|
// This should not throw - tools_documentation is not disabled
|
|
// The tool execution may fail for other reasons (like missing data),
|
|
// but it should NOT fail due to being disabled
|
|
try {
|
|
await server.testExecuteTool('tools_documentation', {});
|
|
} catch (error: any) {
|
|
// Ensure the error is NOT about the tool being disabled
|
|
expect(error.message).not.toContain('disabled via DISABLED_TOOLS');
|
|
}
|
|
});
|
|
|
|
it('should throw error for all disabled tools in list', async () => {
|
|
process.env.DISABLED_TOOLS = 'tool1,tool2,tool3';
|
|
server = new TestableN8NMCPServer();
|
|
|
|
for (const toolName of ['tool1', 'tool2', 'tool3']) {
|
|
await expect(async () => {
|
|
await server.testExecuteTool(toolName, {});
|
|
}).rejects.toThrow(`Tool '${toolName}' is disabled via DISABLED_TOOLS environment variable`);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Tool Filtering - Documentation Tools', () => {
|
|
it('should filter disabled documentation tools from list', () => {
|
|
// Find a documentation tool to disable
|
|
const docTool = n8nDocumentationToolsFinal[0];
|
|
if (!docTool) {
|
|
throw new Error('No documentation tools available for testing');
|
|
}
|
|
|
|
process.env.DISABLED_TOOLS = docTool.name;
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.has(docTool.name)).toBe(true);
|
|
expect(disabledTools.size).toBe(1);
|
|
});
|
|
|
|
it('should filter multiple disabled documentation tools', () => {
|
|
const tool1 = n8nDocumentationToolsFinal[0];
|
|
const tool2 = n8nDocumentationToolsFinal[1];
|
|
|
|
if (!tool1 || !tool2) {
|
|
throw new Error('Not enough documentation tools available for testing');
|
|
}
|
|
|
|
process.env.DISABLED_TOOLS = `${tool1.name},${tool2.name}`;
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.has(tool1.name)).toBe(true);
|
|
expect(disabledTools.has(tool2.name)).toBe(true);
|
|
expect(disabledTools.size).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe('Tool Filtering - Management Tools', () => {
|
|
it('should filter disabled management tools from list', () => {
|
|
// Find a management tool to disable
|
|
const mgmtTool = n8nManagementTools[0];
|
|
if (!mgmtTool) {
|
|
throw new Error('No management tools available for testing');
|
|
}
|
|
|
|
process.env.DISABLED_TOOLS = mgmtTool.name;
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.has(mgmtTool.name)).toBe(true);
|
|
expect(disabledTools.size).toBe(1);
|
|
});
|
|
|
|
it('should filter multiple disabled management tools', () => {
|
|
const tool1 = n8nManagementTools[0];
|
|
const tool2 = n8nManagementTools[1];
|
|
|
|
if (!tool1 || !tool2) {
|
|
throw new Error('Not enough management tools available for testing');
|
|
}
|
|
|
|
process.env.DISABLED_TOOLS = `${tool1.name},${tool2.name}`;
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.has(tool1.name)).toBe(true);
|
|
expect(disabledTools.has(tool2.name)).toBe(true);
|
|
expect(disabledTools.size).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe('Tool Filtering - Mixed Tools', () => {
|
|
it('should filter disabled tools from both documentation and management lists', () => {
|
|
const docTool = n8nDocumentationToolsFinal[0];
|
|
const mgmtTool = n8nManagementTools[0];
|
|
|
|
if (!docTool || !mgmtTool) {
|
|
throw new Error('Tools not available for testing');
|
|
}
|
|
|
|
process.env.DISABLED_TOOLS = `${docTool.name},${mgmtTool.name}`;
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.has(docTool.name)).toBe(true);
|
|
expect(disabledTools.has(mgmtTool.name)).toBe(true);
|
|
expect(disabledTools.size).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe('Invalid Tool Names', () => {
|
|
it('should gracefully handle non-existent tool names', () => {
|
|
process.env.DISABLED_TOOLS = 'non_existent_tool,another_fake_tool';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
// Should still parse and store them, even if they don't exist
|
|
expect(disabledTools.size).toBe(2);
|
|
expect(disabledTools.has('non_existent_tool')).toBe(true);
|
|
expect(disabledTools.has('another_fake_tool')).toBe(true);
|
|
});
|
|
|
|
it('should handle special characters in tool names', () => {
|
|
process.env.DISABLED_TOOLS = 'tool-with-dashes,tool_with_underscores,tool.with.dots';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.size).toBe(3);
|
|
expect(disabledTools.has('tool-with-dashes')).toBe(true);
|
|
expect(disabledTools.has('tool_with_underscores')).toBe(true);
|
|
expect(disabledTools.has('tool.with.dots')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('Real-World Use Cases', () => {
|
|
it('should support multi-tenant deployment use case - disable diagnostic tools', () => {
|
|
process.env.DISABLED_TOOLS = 'n8n_diagnostic,n8n_health_check';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.has('n8n_diagnostic')).toBe(true);
|
|
expect(disabledTools.has('n8n_health_check')).toBe(true);
|
|
expect(disabledTools.size).toBe(2);
|
|
});
|
|
|
|
it('should support security hardening use case - disable management tools', () => {
|
|
// Disable potentially dangerous management tools
|
|
const dangerousTools = [
|
|
'n8n_delete_workflow',
|
|
'n8n_update_full_workflow'
|
|
];
|
|
|
|
process.env.DISABLED_TOOLS = dangerousTools.join(',');
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
dangerousTools.forEach(tool => {
|
|
expect(disabledTools.has(tool)).toBe(true);
|
|
});
|
|
expect(disabledTools.size).toBe(dangerousTools.length);
|
|
});
|
|
|
|
it('should support feature flag use case - disable experimental tools', () => {
|
|
// Example: Disable experimental or beta features
|
|
process.env.DISABLED_TOOLS = 'experimental_tool_1,beta_feature';
|
|
server = new TestableN8NMCPServer();
|
|
const disabledTools = server.testGetDisabledTools();
|
|
|
|
expect(disabledTools.has('experimental_tool_1')).toBe(true);
|
|
expect(disabledTools.has('beta_feature')).toBe(true);
|
|
expect(disabledTools.size).toBe(2);
|
|
});
|
|
});
|
|
});
|