n8n-mcp 2.16.0 → 2.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.env.example +34 -0
  2. package/README.md +42 -5
  3. package/data/nodes.db +0 -0
  4. package/dist/http-server-single-session.d.ts.map +1 -1
  5. package/dist/http-server-single-session.js +35 -2
  6. package/dist/http-server-single-session.js.map +1 -1
  7. package/dist/http-server.d.ts.map +1 -1
  8. package/dist/http-server.js +4 -1
  9. package/dist/http-server.js.map +1 -1
  10. package/dist/mcp/handlers-n8n-manager.d.ts.map +1 -1
  11. package/dist/mcp/handlers-n8n-manager.js +2 -0
  12. package/dist/mcp/handlers-n8n-manager.js.map +1 -1
  13. package/dist/mcp/index.js +53 -0
  14. package/dist/mcp/index.js.map +1 -1
  15. package/dist/mcp/server.d.ts.map +1 -1
  16. package/dist/mcp/server.js +1 -2
  17. package/dist/mcp/server.js.map +1 -1
  18. package/dist/mcp/tool-docs/discovery/list-ai-tools.d.ts.map +1 -1
  19. package/dist/mcp/tool-docs/discovery/list-ai-tools.js +15 -11
  20. package/dist/mcp/tool-docs/discovery/list-ai-tools.js.map +1 -1
  21. package/dist/mcp/tool-docs/guides/ai-agents-guide.d.ts +3 -0
  22. package/dist/mcp/tool-docs/guides/ai-agents-guide.d.ts.map +1 -0
  23. package/dist/mcp/tool-docs/guides/ai-agents-guide.js +740 -0
  24. package/dist/mcp/tool-docs/guides/ai-agents-guide.js.map +1 -0
  25. package/dist/mcp/tool-docs/guides/index.d.ts +2 -0
  26. package/dist/mcp/tool-docs/guides/index.d.ts.map +1 -0
  27. package/dist/mcp/tool-docs/guides/index.js +6 -0
  28. package/dist/mcp/tool-docs/guides/index.js.map +1 -0
  29. package/dist/mcp/tool-docs/index.d.ts.map +1 -1
  30. package/dist/mcp/tool-docs/index.js +2 -0
  31. package/dist/mcp/tool-docs/index.js.map +1 -1
  32. package/dist/mcp/tool-docs/workflow_management/n8n-update-partial-workflow.d.ts.map +1 -1
  33. package/dist/mcp/tool-docs/workflow_management/n8n-update-partial-workflow.js +55 -5
  34. package/dist/mcp/tool-docs/workflow_management/n8n-update-partial-workflow.js.map +1 -1
  35. package/dist/scripts/seed-canonical-ai-examples.d.ts +4 -0
  36. package/dist/scripts/seed-canonical-ai-examples.d.ts.map +1 -0
  37. package/dist/scripts/seed-canonical-ai-examples.js +121 -0
  38. package/dist/scripts/seed-canonical-ai-examples.js.map +1 -0
  39. package/dist/services/ai-node-validator.d.ts +12 -0
  40. package/dist/services/ai-node-validator.d.ts.map +1 -0
  41. package/dist/services/ai-node-validator.js +429 -0
  42. package/dist/services/ai-node-validator.js.map +1 -0
  43. package/dist/services/ai-tool-validators.d.ts +58 -0
  44. package/dist/services/ai-tool-validators.d.ts.map +1 -0
  45. package/dist/services/ai-tool-validators.js +438 -0
  46. package/dist/services/ai-tool-validators.js.map +1 -0
  47. package/dist/services/n8n-api-client.d.ts.map +1 -1
  48. package/dist/services/n8n-api-client.js +38 -0
  49. package/dist/services/n8n-api-client.js.map +1 -1
  50. package/dist/services/universal-expression-validator.d.ts.map +1 -1
  51. package/dist/services/universal-expression-validator.js.map +1 -1
  52. package/dist/services/workflow-validator.d.ts.map +1 -1
  53. package/dist/services/workflow-validator.js +32 -4
  54. package/dist/services/workflow-validator.js.map +1 -1
  55. package/dist/telemetry/config-manager.d.ts +4 -0
  56. package/dist/telemetry/config-manager.d.ts.map +1 -1
  57. package/dist/telemetry/config-manager.js +78 -0
  58. package/dist/telemetry/config-manager.js.map +1 -1
  59. package/dist/utils/auth.d.ts +1 -0
  60. package/dist/utils/auth.d.ts.map +1 -1
  61. package/dist/utils/auth.js +17 -1
  62. package/dist/utils/auth.js.map +1 -1
  63. package/dist/utils/enhanced-documentation-fetcher.d.ts.map +1 -1
  64. package/dist/utils/enhanced-documentation-fetcher.js +66 -10
  65. package/dist/utils/enhanced-documentation-fetcher.js.map +1 -1
  66. package/dist/utils/ssrf-protection.d.ts +7 -0
  67. package/dist/utils/ssrf-protection.d.ts.map +1 -0
  68. package/dist/utils/ssrf-protection.js +118 -0
  69. package/dist/utils/ssrf-protection.js.map +1 -0
  70. package/package.json +2 -1
@@ -0,0 +1,740 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.aiAgentsGuide = void 0;
4
+ exports.aiAgentsGuide = {
5
+ name: 'ai_agents_guide',
6
+ category: 'guides',
7
+ essentials: {
8
+ description: 'Comprehensive guide to building AI Agent workflows in n8n. Covers architecture, connections, tools, validation, and best practices for production AI systems.',
9
+ keyParameters: [],
10
+ example: 'Use tools_documentation({topic: "ai_agents_guide"}) to access this guide',
11
+ performance: 'N/A - Documentation only',
12
+ tips: [
13
+ 'Start with Chat Trigger → AI Agent → Language Model pattern',
14
+ 'Always connect language model BEFORE enabling AI Agent',
15
+ 'Use proper toolDescription for all AI tools (15+ characters)',
16
+ 'Validate workflows with n8n_validate_workflow before deployment',
17
+ 'Use includeExamples=true when searching for AI nodes',
18
+ 'Check FINAL_AI_VALIDATION_SPEC.md for detailed requirements'
19
+ ]
20
+ },
21
+ full: {
22
+ description: `# Complete Guide to AI Agents in n8n
23
+
24
+ This comprehensive guide covers everything you need to build production-ready AI Agent workflows in n8n.
25
+
26
+ ## Table of Contents
27
+ 1. [AI Agent Architecture](#architecture)
28
+ 2. [Essential Connection Types](#connections)
29
+ 3. [Building Your First AI Agent](#first-agent)
30
+ 4. [AI Tools Deep Dive](#tools)
31
+ 5. [Advanced Patterns](#advanced)
32
+ 6. [Validation & Best Practices](#validation)
33
+ 7. [Troubleshooting](#troubleshooting)
34
+
35
+ ---
36
+
37
+ ## 1. AI Agent Architecture {#architecture}
38
+
39
+ ### Core Components
40
+
41
+ An n8n AI Agent workflow typically consists of:
42
+
43
+ 1. **Chat Trigger**: Entry point for user interactions
44
+ - Webhook-based or manual trigger
45
+ - Supports streaming responses (responseMode)
46
+ - Passes user message to AI Agent
47
+
48
+ 2. **AI Agent**: The orchestrator
49
+ - Manages conversation flow
50
+ - Decides when to use tools
51
+ - Iterates until task is complete
52
+ - Supports fallback models (v2.1+)
53
+
54
+ 3. **Language Model**: The AI brain
55
+ - OpenAI GPT-4, Claude, Gemini, etc.
56
+ - Connected via ai_languageModel port
57
+ - Can have primary + fallback for reliability
58
+
59
+ 4. **Tools**: AI Agent's capabilities
60
+ - HTTP Request, Code, Vector Store, etc.
61
+ - Connected via ai_tool port
62
+ - Each tool needs clear toolDescription
63
+
64
+ 5. **Optional Components**:
65
+ - Memory (conversation history)
66
+ - Output Parser (structured responses)
67
+ - Vector Store (knowledge retrieval)
68
+
69
+ ### Connection Flow
70
+
71
+ **CRITICAL**: AI connections flow TO the consumer (reversed from standard n8n):
72
+
73
+ \`\`\`
74
+ Standard n8n: [Source] --main--> [Target]
75
+ AI pattern: [Language Model] --ai_languageModel--> [AI Agent]
76
+ [HTTP Tool] --ai_tool--> [AI Agent]
77
+ \`\`\`
78
+
79
+ This is why you use \`sourceOutput: "ai_languageModel"\` when connecting components.
80
+
81
+ ---
82
+
83
+ ## 2. Essential Connection Types {#connections}
84
+
85
+ ### The 8 AI Connection Types
86
+
87
+ 1. **ai_languageModel**
88
+ - FROM: OpenAI Chat Model, Anthropic, Google Gemini, etc.
89
+ - TO: AI Agent, Basic LLM Chain
90
+ - REQUIRED: Every AI Agent needs 1-2 language models
91
+ - Example: \`{type: "addConnection", source: "OpenAI", target: "AI Agent", sourceOutput: "ai_languageModel"}\`
92
+
93
+ 2. **ai_tool**
94
+ - FROM: Any tool node (HTTP Request Tool, Code Tool, etc.)
95
+ - TO: AI Agent
96
+ - REQUIRED: At least 1 tool recommended
97
+ - Example: \`{type: "addConnection", source: "HTTP Request Tool", target: "AI Agent", sourceOutput: "ai_tool"}\`
98
+
99
+ 3. **ai_memory**
100
+ - FROM: Window Buffer Memory, Conversation Summary, etc.
101
+ - TO: AI Agent
102
+ - OPTIONAL: 0-1 memory system
103
+ - Enables conversation history tracking
104
+
105
+ 4. **ai_outputParser**
106
+ - FROM: Structured Output Parser, JSON Parser, etc.
107
+ - TO: AI Agent
108
+ - OPTIONAL: For structured responses
109
+ - Must set hasOutputParser=true on AI Agent
110
+
111
+ 5. **ai_embedding**
112
+ - FROM: Embeddings OpenAI, Embeddings Google, etc.
113
+ - TO: Vector Store (Pinecone, In-Memory, etc.)
114
+ - REQUIRED: For vector-based retrieval
115
+
116
+ 6. **ai_vectorStore**
117
+ - FROM: Vector Store node
118
+ - TO: Vector Store Tool
119
+ - REQUIRED: For retrieval-augmented generation (RAG)
120
+
121
+ 7. **ai_document**
122
+ - FROM: Document Loader, Default Data Loader
123
+ - TO: Vector Store
124
+ - REQUIRED: Provides data for vector storage
125
+
126
+ 8. **ai_textSplitter**
127
+ - FROM: Text Splitter nodes
128
+ - TO: Document processing chains
129
+ - OPTIONAL: Chunk large documents
130
+
131
+ ### Connection Examples
132
+
133
+ \`\`\`typescript
134
+ // Basic AI Agent setup
135
+ n8n_update_partial_workflow({
136
+ id: "workflow_id",
137
+ operations: [
138
+ // Connect language model (REQUIRED)
139
+ {
140
+ type: "addConnection",
141
+ source: "OpenAI Chat Model",
142
+ target: "AI Agent",
143
+ sourceOutput: "ai_languageModel"
144
+ },
145
+ // Connect tools
146
+ {
147
+ type: "addConnection",
148
+ source: "HTTP Request Tool",
149
+ target: "AI Agent",
150
+ sourceOutput: "ai_tool"
151
+ },
152
+ {
153
+ type: "addConnection",
154
+ source: "Code Tool",
155
+ target: "AI Agent",
156
+ sourceOutput: "ai_tool"
157
+ },
158
+ // Add memory (optional)
159
+ {
160
+ type: "addConnection",
161
+ source: "Window Buffer Memory",
162
+ target: "AI Agent",
163
+ sourceOutput: "ai_memory"
164
+ }
165
+ ]
166
+ })
167
+ \`\`\`
168
+
169
+ ---
170
+
171
+ ## 3. Building Your First AI Agent {#first-agent}
172
+
173
+ ### Step-by-Step Tutorial
174
+
175
+ #### Step 1: Create Chat Trigger
176
+
177
+ Use \`n8n_create_workflow\` or manually create a workflow with:
178
+
179
+ \`\`\`typescript
180
+ {
181
+ name: "My First AI Agent",
182
+ nodes: [
183
+ {
184
+ id: "chat_trigger",
185
+ name: "Chat Trigger",
186
+ type: "@n8n/n8n-nodes-langchain.chatTrigger",
187
+ position: [100, 100],
188
+ parameters: {
189
+ options: {
190
+ responseMode: "lastNode" // or "streaming" for real-time
191
+ }
192
+ }
193
+ }
194
+ ],
195
+ connections: {}
196
+ }
197
+ \`\`\`
198
+
199
+ #### Step 2: Add Language Model
200
+
201
+ \`\`\`typescript
202
+ n8n_update_partial_workflow({
203
+ id: "workflow_id",
204
+ operations: [
205
+ {
206
+ type: "addNode",
207
+ node: {
208
+ name: "OpenAI Chat Model",
209
+ type: "@n8n/n8n-nodes-langchain.lmChatOpenAi",
210
+ position: [300, 50],
211
+ parameters: {
212
+ model: "gpt-4",
213
+ temperature: 0.7
214
+ }
215
+ }
216
+ }
217
+ ]
218
+ })
219
+ \`\`\`
220
+
221
+ #### Step 3: Add AI Agent
222
+
223
+ \`\`\`typescript
224
+ n8n_update_partial_workflow({
225
+ id: "workflow_id",
226
+ operations: [
227
+ {
228
+ type: "addNode",
229
+ node: {
230
+ name: "AI Agent",
231
+ type: "@n8n/n8n-nodes-langchain.agent",
232
+ position: [300, 150],
233
+ parameters: {
234
+ promptType: "auto",
235
+ systemMessage: "You are a helpful assistant. Be concise and accurate."
236
+ }
237
+ }
238
+ }
239
+ ]
240
+ })
241
+ \`\`\`
242
+
243
+ #### Step 4: Connect Components
244
+
245
+ \`\`\`typescript
246
+ n8n_update_partial_workflow({
247
+ id: "workflow_id",
248
+ operations: [
249
+ // Chat Trigger → AI Agent (main connection)
250
+ {
251
+ type: "addConnection",
252
+ source: "Chat Trigger",
253
+ target: "AI Agent"
254
+ },
255
+ // Language Model → AI Agent (AI connection)
256
+ {
257
+ type: "addConnection",
258
+ source: "OpenAI Chat Model",
259
+ target: "AI Agent",
260
+ sourceOutput: "ai_languageModel"
261
+ }
262
+ ]
263
+ })
264
+ \`\`\`
265
+
266
+ #### Step 5: Validate
267
+
268
+ \`\`\`typescript
269
+ n8n_validate_workflow({id: "workflow_id"})
270
+ \`\`\`
271
+
272
+ ---
273
+
274
+ ## 4. AI Tools Deep Dive {#tools}
275
+
276
+ ### Tool Types and When to Use Them
277
+
278
+ #### 1. HTTP Request Tool
279
+ **Use when**: AI needs to call external APIs
280
+
281
+ **Critical Requirements**:
282
+ - \`toolDescription\`: Clear, 15+ character description
283
+ - \`url\`: API endpoint (can include placeholders)
284
+ - \`placeholderDefinitions\`: Define all {placeholders}
285
+ - Proper authentication if needed
286
+
287
+ **Example**:
288
+ \`\`\`typescript
289
+ {
290
+ type: "addNode",
291
+ node: {
292
+ name: "GitHub Issues Tool",
293
+ type: "@n8n/n8n-nodes-langchain.toolHttpRequest",
294
+ position: [500, 100],
295
+ parameters: {
296
+ method: "POST",
297
+ url: "https://api.github.com/repos/{owner}/{repo}/issues",
298
+ toolDescription: "Create GitHub issues. Requires owner (username), repo (repository name), title, and body.",
299
+ placeholderDefinitions: {
300
+ values: [
301
+ {name: "owner", description: "Repository owner username"},
302
+ {name: "repo", description: "Repository name"},
303
+ {name: "title", description: "Issue title"},
304
+ {name: "body", description: "Issue description"}
305
+ ]
306
+ },
307
+ sendBody: true,
308
+ jsonBody: "={{ { title: $json.title, body: $json.body } }}"
309
+ }
310
+ }
311
+ }
312
+ \`\`\`
313
+
314
+ #### 2. Code Tool
315
+ **Use when**: AI needs to run custom logic
316
+
317
+ **Critical Requirements**:
318
+ - \`name\`: Function name (alphanumeric + underscore)
319
+ - \`description\`: 10+ character explanation
320
+ - \`code\`: JavaScript or Python code
321
+ - \`inputSchema\`: Define expected inputs (recommended)
322
+
323
+ **Example**:
324
+ \`\`\`typescript
325
+ {
326
+ type: "addNode",
327
+ node: {
328
+ name: "Calculate Shipping",
329
+ type: "@n8n/n8n-nodes-langchain.toolCode",
330
+ position: [500, 200],
331
+ parameters: {
332
+ name: "calculate_shipping",
333
+ description: "Calculate shipping cost based on weight (kg) and distance (km)",
334
+ language: "javaScript",
335
+ code: "const cost = 5 + ($input.weight * 2) + ($input.distance * 0.1); return { cost };",
336
+ specifyInputSchema: true,
337
+ inputSchema: "{ \\"type\\": \\"object\\", \\"properties\\": { \\"weight\\": { \\"type\\": \\"number\\" }, \\"distance\\": { \\"type\\": \\"number\\" } } }"
338
+ }
339
+ }
340
+ }
341
+ \`\`\`
342
+
343
+ #### 3. Vector Store Tool
344
+ **Use when**: AI needs to search knowledge base
345
+
346
+ **Setup**: Requires Vector Store + Embeddings + Documents
347
+
348
+ **Example**:
349
+ \`\`\`typescript
350
+ // Step 1: Create Vector Store with embeddings and documents
351
+ n8n_update_partial_workflow({
352
+ operations: [
353
+ {type: "addConnection", source: "Embeddings OpenAI", target: "Pinecone", sourceOutput: "ai_embedding"},
354
+ {type: "addConnection", source: "Document Loader", target: "Pinecone", sourceOutput: "ai_document"}
355
+ ]
356
+ })
357
+
358
+ // Step 2: Connect Vector Store to Vector Store Tool
359
+ n8n_update_partial_workflow({
360
+ operations: [
361
+ {type: "addConnection", source: "Pinecone", target: "Vector Store Tool", sourceOutput: "ai_vectorStore"}
362
+ ]
363
+ })
364
+
365
+ // Step 3: Connect tool to AI Agent
366
+ n8n_update_partial_workflow({
367
+ operations: [
368
+ {type: "addConnection", source: "Vector Store Tool", target: "AI Agent", sourceOutput: "ai_tool"}
369
+ ]
370
+ })
371
+ \`\`\`
372
+
373
+ #### 4. AI Agent Tool (Sub-Agents)
374
+ **Use when**: Need specialized expertise
375
+
376
+ **Example**: Research specialist sub-agent
377
+ \`\`\`typescript
378
+ {
379
+ type: "addNode",
380
+ node: {
381
+ name: "Research Specialist",
382
+ type: "@n8n/n8n-nodes-langchain.agentTool",
383
+ position: [500, 300],
384
+ parameters: {
385
+ name: "research_specialist",
386
+ description: "Expert researcher that searches multiple sources and synthesizes information. Use for detailed research tasks.",
387
+ systemMessage: "You are a research specialist. Search thoroughly, cite sources, and provide comprehensive analysis."
388
+ }
389
+ }
390
+ }
391
+ \`\`\`
392
+
393
+ #### 5. MCP Client Tool
394
+ **Use when**: Need to use Model Context Protocol servers
395
+
396
+ **Example**: Filesystem access
397
+ \`\`\`typescript
398
+ {
399
+ type: "addNode",
400
+ node: {
401
+ name: "Filesystem Tool",
402
+ type: "@n8n/n8n-nodes-langchain.mcpClientTool",
403
+ position: [500, 400],
404
+ parameters: {
405
+ description: "Access file system to read files, list directories, and search content",
406
+ mcpServer: {
407
+ transport: "stdio",
408
+ command: "npx",
409
+ args: ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"]
410
+ },
411
+ tool: "read_file"
412
+ }
413
+ }
414
+ }
415
+ \`\`\`
416
+
417
+ ---
418
+
419
+ ## 5. Advanced Patterns {#advanced}
420
+
421
+ ### Pattern 1: Streaming Responses
422
+
423
+ For real-time user experience:
424
+
425
+ \`\`\`typescript
426
+ // Set Chat Trigger to streaming mode
427
+ {
428
+ parameters: {
429
+ options: {
430
+ responseMode: "streaming"
431
+ }
432
+ }
433
+ }
434
+
435
+ // CRITICAL: AI Agent must NOT have main output connections in streaming mode
436
+ // Responses stream back through Chat Trigger automatically
437
+ \`\`\`
438
+
439
+ **Validation will fail if**:
440
+ - Chat Trigger has streaming but target is not AI Agent
441
+ - AI Agent in streaming mode has main output connections
442
+
443
+ ### Pattern 2: Fallback Language Models
444
+
445
+ For production reliability (requires AI Agent v2.1+):
446
+
447
+ \`\`\`typescript
448
+ n8n_update_partial_workflow({
449
+ operations: [
450
+ // Primary model
451
+ {
452
+ type: "addConnection",
453
+ source: "OpenAI GPT-4",
454
+ target: "AI Agent",
455
+ sourceOutput: "ai_languageModel",
456
+ targetIndex: 0
457
+ },
458
+ // Fallback model
459
+ {
460
+ type: "addConnection",
461
+ source: "Anthropic Claude",
462
+ target: "AI Agent",
463
+ sourceOutput: "ai_languageModel",
464
+ targetIndex: 1
465
+ }
466
+ ]
467
+ })
468
+
469
+ // Enable fallback on AI Agent
470
+ {
471
+ type: "updateNode",
472
+ nodeName: "AI Agent",
473
+ updates: {
474
+ "parameters.needsFallback": true
475
+ }
476
+ }
477
+ \`\`\`
478
+
479
+ ### Pattern 3: RAG (Retrieval-Augmented Generation)
480
+
481
+ Complete knowledge base setup:
482
+
483
+ \`\`\`typescript
484
+ // 1. Load documents
485
+ {type: "addConnection", source: "PDF Loader", target: "Text Splitter", sourceOutput: "ai_document"}
486
+
487
+ // 2. Split and embed
488
+ {type: "addConnection", source: "Text Splitter", target: "Vector Store"}
489
+ {type: "addConnection", source: "Embeddings", target: "Vector Store", sourceOutput: "ai_embedding"}
490
+
491
+ // 3. Create search tool
492
+ {type: "addConnection", source: "Vector Store", target: "Vector Store Tool", sourceOutput: "ai_vectorStore"}
493
+
494
+ // 4. Give tool to agent
495
+ {type: "addConnection", source: "Vector Store Tool", target: "AI Agent", sourceOutput: "ai_tool"}
496
+ \`\`\`
497
+
498
+ ### Pattern 4: Multi-Agent Systems
499
+
500
+ Specialized sub-agents for complex tasks:
501
+
502
+ \`\`\`typescript
503
+ // Create sub-agents with specific expertise
504
+ [
505
+ {name: "research_agent", description: "Deep research specialist"},
506
+ {name: "data_analyst", description: "Data analysis expert"},
507
+ {name: "writer_agent", description: "Content writing specialist"}
508
+ ].forEach(agent => {
509
+ // Add as AI Agent Tool to main coordinator agent
510
+ {
511
+ type: "addConnection",
512
+ source: agent.name,
513
+ target: "Coordinator Agent",
514
+ sourceOutput: "ai_tool"
515
+ }
516
+ })
517
+ \`\`\`
518
+
519
+ ---
520
+
521
+ ## 6. Validation & Best Practices {#validation}
522
+
523
+ ### Always Validate Before Deployment
524
+
525
+ \`\`\`typescript
526
+ const result = n8n_validate_workflow({id: "workflow_id"})
527
+
528
+ if (!result.valid) {
529
+ console.log("Errors:", result.errors)
530
+ console.log("Warnings:", result.warnings)
531
+ console.log("Suggestions:", result.suggestions)
532
+ }
533
+ \`\`\`
534
+
535
+ ### Common Validation Errors
536
+
537
+ 1. **MISSING_LANGUAGE_MODEL**
538
+ - Problem: AI Agent has no ai_languageModel connection
539
+ - Fix: Connect a language model before creating AI Agent
540
+
541
+ 2. **MISSING_TOOL_DESCRIPTION**
542
+ - Problem: HTTP Request Tool has no toolDescription
543
+ - Fix: Add clear description (15+ characters)
544
+
545
+ 3. **STREAMING_WITH_MAIN_OUTPUT**
546
+ - Problem: AI Agent in streaming mode has outgoing main connections
547
+ - Fix: Remove main connections when using streaming
548
+
549
+ 4. **FALLBACK_MISSING_SECOND_MODEL**
550
+ - Problem: needsFallback=true but only 1 language model
551
+ - Fix: Add second language model or disable needsFallback
552
+
553
+ ### Best Practices Checklist
554
+
555
+ ✅ **Before Creating AI Agent**:
556
+ - [ ] Language model is connected first
557
+ - [ ] At least one tool is prepared (or will be added)
558
+ - [ ] System message is thoughtful and specific
559
+
560
+ ✅ **For Each Tool**:
561
+ - [ ] Has toolDescription/description (15+ characters)
562
+ - [ ] toolDescription explains WHEN to use the tool
563
+ - [ ] All required parameters are configured
564
+ - [ ] Credentials are set up if needed
565
+
566
+ ✅ **For Production**:
567
+ - [ ] Workflow validated with n8n_validate_workflow
568
+ - [ ] Tested with real user queries
569
+ - [ ] Fallback model configured for reliability
570
+ - [ ] Error handling in place
571
+ - [ ] maxIterations set appropriately (default 10, max 50)
572
+
573
+ ---
574
+
575
+ ## 7. Troubleshooting {#troubleshooting}
576
+
577
+ ### Problem: "AI Agent has no language model"
578
+
579
+ **Cause**: Connection created AFTER AI Agent or using wrong sourceOutput
580
+
581
+ **Solution**:
582
+ \`\`\`typescript
583
+ n8n_update_partial_workflow({
584
+ operations: [
585
+ {
586
+ type: "addConnection",
587
+ source: "OpenAI Chat Model",
588
+ target: "AI Agent",
589
+ sourceOutput: "ai_languageModel" // ← CRITICAL
590
+ }
591
+ ]
592
+ })
593
+ \`\`\`
594
+
595
+ ### Problem: "Tool has no description"
596
+
597
+ **Cause**: HTTP Request Tool or Code Tool missing toolDescription/description
598
+
599
+ **Solution**:
600
+ \`\`\`typescript
601
+ {
602
+ type: "updateNode",
603
+ nodeName: "HTTP Request Tool",
604
+ updates: {
605
+ "parameters.toolDescription": "Call weather API to get current conditions for a city"
606
+ }
607
+ }
608
+ \`\`\`
609
+
610
+ ### Problem: "Streaming mode not working"
611
+
612
+ **Causes**:
613
+ 1. Chat Trigger not set to streaming
614
+ 2. AI Agent has main output connections
615
+ 3. Target of Chat Trigger is not AI Agent
616
+
617
+ **Solution**:
618
+ \`\`\`typescript
619
+ // 1. Set Chat Trigger to streaming
620
+ {
621
+ type: "updateNode",
622
+ nodeName: "Chat Trigger",
623
+ updates: {
624
+ "parameters.options.responseMode": "streaming"
625
+ }
626
+ }
627
+
628
+ // 2. Remove AI Agent main outputs
629
+ {
630
+ type: "removeConnection",
631
+ source: "AI Agent",
632
+ target: "Any Output Node"
633
+ }
634
+ \`\`\`
635
+
636
+ ### Problem: "Agent keeps looping"
637
+
638
+ **Cause**: Tool not returning proper response or agent stuck in reasoning loop
639
+
640
+ **Solutions**:
641
+ 1. Set maxIterations lower: \`"parameters.maxIterations": 5\`
642
+ 2. Improve tool descriptions to be more specific
643
+ 3. Add system message guidance: "Use tools efficiently, don't repeat actions"
644
+
645
+ ---
646
+
647
+ ## Quick Reference
648
+
649
+ ### Essential Tools
650
+
651
+ | Tool | Purpose | Key Parameters |
652
+ |------|---------|----------------|
653
+ | HTTP Request Tool | API calls | toolDescription, url, placeholders |
654
+ | Code Tool | Custom logic | name, description, code, inputSchema |
655
+ | Vector Store Tool | Knowledge search | description, topK |
656
+ | AI Agent Tool | Sub-agents | name, description, systemMessage |
657
+ | MCP Client Tool | MCP protocol | description, mcpServer, tool |
658
+
659
+ ### Connection Quick Codes
660
+
661
+ \`\`\`typescript
662
+ // Language Model → AI Agent
663
+ sourceOutput: "ai_languageModel"
664
+
665
+ // Tool → AI Agent
666
+ sourceOutput: "ai_tool"
667
+
668
+ // Memory → AI Agent
669
+ sourceOutput: "ai_memory"
670
+
671
+ // Parser → AI Agent
672
+ sourceOutput: "ai_outputParser"
673
+
674
+ // Embeddings → Vector Store
675
+ sourceOutput: "ai_embedding"
676
+
677
+ // Vector Store → Vector Store Tool
678
+ sourceOutput: "ai_vectorStore"
679
+ \`\`\`
680
+
681
+ ### Validation Command
682
+
683
+ \`\`\`typescript
684
+ n8n_validate_workflow({id: "workflow_id"})
685
+ \`\`\`
686
+
687
+ ---
688
+
689
+ ## Related Resources
690
+
691
+ - **FINAL_AI_VALIDATION_SPEC.md**: Complete validation rules
692
+ - **n8n_update_partial_workflow**: Workflow modification tool
693
+ - **search_nodes({query: "AI", includeExamples: true})**: Find AI nodes with examples
694
+ - **get_node_essentials({nodeType: "...", includeExamples: true})**: Node details with examples
695
+
696
+ ---
697
+
698
+ *This guide is part of the n8n-mcp documentation system. For questions or issues, refer to the validation spec or use tools_documentation() for specific topics.*`,
699
+ parameters: {},
700
+ returns: 'Complete AI Agents guide with architecture, patterns, validation, and troubleshooting',
701
+ examples: [
702
+ 'tools_documentation({topic: "ai_agents_guide"}) - Full guide',
703
+ 'tools_documentation({topic: "ai_agents_guide", depth: "essentials"}) - Quick reference',
704
+ 'When user asks about AI Agents, Chat Trigger, or building AI workflows → Point to this guide'
705
+ ],
706
+ useCases: [
707
+ 'Learning AI Agent architecture in n8n',
708
+ 'Understanding AI connection types and patterns',
709
+ 'Building first AI Agent workflow step-by-step',
710
+ 'Implementing advanced patterns (streaming, fallback, RAG, multi-agent)',
711
+ 'Troubleshooting AI workflow issues',
712
+ 'Validating AI workflows before deployment',
713
+ 'Quick reference for connection types and tools'
714
+ ],
715
+ performance: 'N/A - Static documentation',
716
+ bestPractices: [
717
+ 'Reference this guide when users ask about AI Agents',
718
+ 'Point to specific sections based on user needs',
719
+ 'Combine with search_nodes(includeExamples=true) for working examples',
720
+ 'Validate workflows after following guide instructions',
721
+ 'Use FINAL_AI_VALIDATION_SPEC.md for detailed requirements'
722
+ ],
723
+ pitfalls: [
724
+ 'This is a guide, not an executable tool',
725
+ 'Always validate workflows after making changes',
726
+ 'AI connections require sourceOutput parameter',
727
+ 'Streaming mode has specific constraints',
728
+ 'Some features require specific AI Agent versions (v2.1+ for fallback)'
729
+ ],
730
+ relatedTools: [
731
+ 'n8n_create_workflow',
732
+ 'n8n_update_partial_workflow',
733
+ 'n8n_validate_workflow',
734
+ 'search_nodes',
735
+ 'get_node_essentials',
736
+ 'list_ai_tools'
737
+ ]
738
+ }
739
+ };
740
+ //# sourceMappingURL=ai-agents-guide.js.map