Skip to main content
Glama

n8n-MCP

by 88-888
README.mdβ€’10.1 kB
# AI Validation Integration Tests Comprehensive integration tests for AI workflow validation introduced in v2.17.0. ## Overview These tests validate ALL AI validation operations against a REAL n8n instance. They verify: - AI Agent validation rules - Chat Trigger validation constraints - Basic LLM Chain validation requirements - AI Tool sub-node validation (HTTP Request, Code, Vector Store, Workflow, Calculator) - End-to-end workflow validation - Multi-error detection - Node type normalization (bug fix validation) ## Test Files ### 1. `helpers.ts` Utility functions for creating AI workflow components: - `createAIAgentNode()` - AI Agent with configurable options - `createChatTriggerNode()` - Chat Trigger with streaming modes - `createBasicLLMChainNode()` - Basic LLM Chain - `createLanguageModelNode()` - OpenAI/Anthropic models - `createHTTPRequestToolNode()` - HTTP Request Tool - `createCodeToolNode()` - Code Tool - `createVectorStoreToolNode()` - Vector Store Tool - `createWorkflowToolNode()` - Workflow Tool - `createCalculatorToolNode()` - Calculator Tool - `createMemoryNode()` - Buffer Window Memory - `createRespondNode()` - Respond to Webhook - `createAIConnection()` - AI connection helper (reversed for langchain) - `createMainConnection()` - Standard n8n connection - `mergeConnections()` - Merge multiple connection objects - `createAIWorkflow()` - Complete workflow builder ### 2. `ai-agent-validation.test.ts` (7 tests) Tests AI Agent validation: - βœ… Detects missing language model (MISSING_LANGUAGE_MODEL error) - βœ… Validates AI Agent with language model connected - βœ… Detects tool connections correctly (no false warnings) - βœ… Validates streaming mode constraints (Chat Trigger) - βœ… Validates AI Agent own streamResponse setting - βœ… Detects multiple memory connections (error) - βœ… Validates complete AI workflow (all components) ### 3. `chat-trigger-validation.test.ts` (5 tests) Tests Chat Trigger validation: - βœ… Detects streaming to non-AI-Agent (STREAMING_WRONG_TARGET error) - βœ… Detects missing connections (MISSING_CONNECTIONS error) - βœ… Validates valid streaming setup - βœ… Validates lastNode mode with AI Agent - βœ… Detects streaming agent with output connection ### 4. `llm-chain-validation.test.ts` (6 tests) Tests Basic LLM Chain validation: - βœ… Detects missing language model (MISSING_LANGUAGE_MODEL error) - βœ… Detects missing prompt text (MISSING_PROMPT_TEXT error) - βœ… Validates complete LLM Chain - βœ… Validates LLM Chain with memory - βœ… Detects multiple language models (error - no fallback support) - βœ… Detects tools connection (TOOLS_NOT_SUPPORTED error) ### 5. `ai-tool-validation.test.ts` (9 tests) Tests AI Tool validation: **HTTP Request Tool:** - βœ… Detects missing toolDescription (MISSING_TOOL_DESCRIPTION) - βœ… Detects missing URL (MISSING_URL) - βœ… Validates valid HTTP Request Tool **Code Tool:** - βœ… Detects missing code (MISSING_CODE) - βœ… Validates valid Code Tool **Vector Store Tool:** - βœ… Detects missing toolDescription - βœ… Validates valid Vector Store Tool **Workflow Tool:** - βœ… Detects missing workflowId (MISSING_WORKFLOW_ID) - βœ… Validates valid Workflow Tool **Calculator Tool:** - βœ… Validates Calculator Tool (no configuration needed) ### 6. `e2e-validation.test.ts` (5 tests) End-to-end validation tests: - βœ… Validates and creates complex AI workflow (7 nodes, all components) - βœ… Detects multiple validation errors (5+ errors in one workflow) - βœ… Validates streaming workflow without main output - βœ… Validates non-streaming workflow with main output - βœ… Tests node type normalization (v2.17.0 bug fix validation) ## Running Tests ### Run All AI Validation Tests ```bash npm test -- tests/integration/ai-validation --run ``` ### Run Specific Test Suite ```bash npm test -- tests/integration/ai-validation/ai-agent-validation.test.ts --run npm test -- tests/integration/ai-validation/chat-trigger-validation.test.ts --run npm test -- tests/integration/ai-validation/llm-chain-validation.test.ts --run npm test -- tests/integration/ai-validation/ai-tool-validation.test.ts --run npm test -- tests/integration/ai-validation/e2e-validation.test.ts --run ``` ### Prerequisites 1. **n8n Instance**: Real n8n instance required (not mocked) 2. **Environment Variables**: ```env N8N_API_URL=http://localhost:5678 N8N_API_KEY=your-api-key TEST_CLEANUP=true # Auto-cleanup test workflows (default: true) ``` 3. **Build**: Run `npm run build` before testing ## Test Infrastructure ### Cleanup - All tests use `TestContext` for automatic workflow cleanup - Workflows are tagged with `mcp-integration-test` and `ai-validation` - Cleanup runs in `afterEach` hooks - Orphaned workflow cleanup runs in `afterAll` (non-CI only) ### Workflow Naming - All test workflows use timestamps: `[MCP-TEST] Description 1696723200000` - Prevents name collisions - Easy identification in n8n UI ### Connection Patterns - **Main connections**: Standard n8n flow (A β†’ B) - **AI connections**: Reversed flow (Language Model β†’ AI Agent) - Uses helper functions to ensure correct connection structure ## Key Validation Checks ### AI Agent - Language model connections (1 or 2 for fallback) - Output parser configuration - Prompt type validation (auto vs define) - System message recommendations - Streaming mode constraints (CRITICAL) - Memory connections (0-1 max) - Tool connections - maxIterations validation ### Chat Trigger - responseMode validation (streaming vs lastNode) - Streaming requires AI Agent target - AI Agent in streaming mode: NO main output allowed ### Basic LLM Chain - Exactly 1 language model (no fallback) - Memory connections (0-1 max) - No tools support (error if connected) - Prompt configuration validation ### AI Tools - HTTP Request Tool: requires toolDescription + URL - Code Tool: requires jsCode - Vector Store Tool: requires toolDescription + vector store connection - Workflow Tool: requires workflowId - Calculator Tool: no configuration required ## Validation Error Codes Tests verify these error codes are correctly detected: - `MISSING_LANGUAGE_MODEL` - No language model connected - `MISSING_TOOL_DESCRIPTION` - Tool missing description - `MISSING_URL` - HTTP tool missing URL - `MISSING_CODE` - Code tool missing code - `MISSING_WORKFLOW_ID` - Workflow tool missing ID - `MISSING_PROMPT_TEXT` - Prompt type=define but no text - `MISSING_CONNECTIONS` - Chat Trigger has no output - `STREAMING_WITH_MAIN_OUTPUT` - AI Agent in streaming mode with main output - `STREAMING_WRONG_TARGET` - Chat Trigger streaming to non-AI-Agent - `STREAMING_AGENT_HAS_OUTPUT` - Streaming agent has output connection - `MULTIPLE_LANGUAGE_MODELS` - LLM Chain with multiple models - `MULTIPLE_MEMORY_CONNECTIONS` - Multiple memory connected - `TOOLS_NOT_SUPPORTED` - Basic LLM Chain with tools - `TOO_MANY_LANGUAGE_MODELS` - AI Agent with 3+ models - `FALLBACK_MISSING_SECOND_MODEL` - needsFallback=true but 1 model - `MULTIPLE_OUTPUT_PARSERS` - Multiple output parsers ## Bug Fix Validation ### v2.17.0 Node Type Normalization Test 5 in `e2e-validation.test.ts` validates the fix for node type normalization: - Creates AI Agent + OpenAI Model + HTTP Request Tool - Connects tool via ai_tool connection - Verifies NO false "no tools connected" warning - Validates workflow is valid This test would have caught the bug where: ```typescript // BUG: Incorrect comparison sourceNode.type === 'nodes-langchain.chatTrigger' // ❌ Never matches // FIX: Use normalizer NodeTypeNormalizer.normalizeToFullForm(sourceNode.type) === 'nodes-langchain.chatTrigger' // βœ… Works ``` ## Success Criteria All tests should: - βœ… Create workflows in real n8n - βœ… Validate using actual MCP tools (handleValidateWorkflow) - βœ… Verify validation results match expected outcomes - βœ… Clean up after themselves (no orphaned workflows) - βœ… Run in under 30 seconds each - βœ… Be deterministic (no flakiness) ## Test Coverage Total: **32 tests** covering: - **7 AI Agent tests** - Complete AI Agent validation logic - **5 Chat Trigger tests** - Streaming mode and connection validation - **6 Basic LLM Chain tests** - LLM Chain constraints and requirements - **9 AI Tool tests** - All AI tool sub-node types - **5 E2E tests** - Complex workflows and multi-error detection ## Coverage Summary ### Validation Features Tested - βœ… Language model connections (required, fallback) - βœ… Output parser configuration - βœ… Prompt type validation - βœ… System message checks - βœ… Streaming mode constraints - βœ… Memory connections (single) - βœ… Tool connections - βœ… maxIterations validation - βœ… Chat Trigger modes (streaming, lastNode) - βœ… Tool description requirements - βœ… Tool-specific parameters (URL, code, workflowId) - βœ… Multi-error detection - βœ… Node type normalization - βœ… Connection validation (missing, invalid) ### Edge Cases Tested - βœ… Empty/missing required fields - βœ… Invalid configurations - βœ… Multiple connections (when not allowed) - βœ… Streaming with main output (forbidden) - βœ… Tool connections to non-agent nodes - βœ… Fallback model configuration - βœ… Complex workflows with all components ## Recommendations ### Additional Tests (Future) 1. **Performance tests** - Validate large AI workflows (20+ nodes) 2. **Credential validation** - Test with invalid/missing credentials 3. **Expression validation** - Test n8n expressions in AI node parameters 4. **Cross-version tests** - Test different node typeVersions 5. **Concurrent validation** - Test multiple workflows in parallel ### Test Maintenance - Update tests when new AI nodes are added - Add tests for new validation rules - Keep helpers.ts updated with new node types - Verify error codes match specification ## Notes - Tests create real workflows in n8n (not mocked) - Each test is independent (no shared state) - Workflows are automatically cleaned up - Tests use actual MCP validation handlers - All AI connection types are tested - Streaming mode validation is comprehensive - Node type normalization is validated

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/88-888/n8n-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server