This commit implements the ability to extract n8n node source code through MCP:
Features:
- New MCP tools: get_node_source_code and list_available_nodes
- NodeSourceExtractor utility for file system access to n8n nodes
- Support for extracting any n8n node including AI Agent from @n8n/n8n-nodes-langchain
- Resource endpoint for accessing node source: nodes://source/{nodeType}
Testing:
- Docker test environment with mounted n8n node_modules
- Multiple test scripts for different scenarios
- Comprehensive test documentation
- Standalone MCP client test demonstrating full extraction flow
The implementation successfully demonstrates:
1. MCP server can access n8n's installed nodes
2. Source code can be extracted and returned to MCP clients
3. Full metadata including package info and file locations
4. Support for credential code extraction when available
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
4.1 KiB
4.1 KiB
AI Agent Node Extraction Test Guide
This document describes how to test the MCP server's ability to extract and provide the AI Agent node source code from n8n.
Test Scenario
An MCP client (like an AI assistant) requests the source code for n8n's AI Agent node, and the MCP server successfully extracts and returns it.
Implementation Overview
1. New MCP Tools Added
get_node_source_code: Extracts source code for any n8n nodelist_available_nodes: Lists all available n8n nodes
2. New Components
NodeSourceExtractor(src/utils/node-source-extractor.ts): Handles file system access to extract node source code- Resource endpoint:
nodes://source/{nodeType}for accessing node code via resources
3. Test Infrastructure
- Docker setup (
docker-compose.test.yml): Mounts n8n's node_modules for source access - Test scripts: Multiple test approaches for different scenarios
Running the Tests
Option 1: Docker-based Test
# Build the project
npm run build
# Run the comprehensive test
./scripts/test-ai-agent-extraction.sh
This script will:
- Build Docker containers
- Start n8n and MCP server
- Check for AI Agent node availability
- Test source code extraction
Option 2: Standalone MCP Test
# Build the project
npm run build
# Ensure n8n is running (locally or in Docker)
docker-compose -f docker-compose.test.yml up -d n8n
# Run the MCP client test
node tests/test-mcp-extraction.js
Option 3: Manual Testing
- Start the environment:
docker-compose -f docker-compose.test.yml up -d
- Use any MCP client to connect and request:
{
"method": "tools/call",
"params": {
"name": "get_node_source_code",
"arguments": {
"nodeType": "@n8n/n8n-nodes-langchain.Agent",
"includeCredentials": true
}
}
}
Expected Results
Successful Extraction Response
{
"nodeType": "@n8n/n8n-nodes-langchain.Agent",
"sourceCode": "/* AI Agent node JavaScript code */",
"location": "/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/dist/nodes/agents/Agent/Agent.node.js",
"credentialCode": "/* Optional credential code */",
"packageInfo": {
"name": "@n8n/n8n-nodes-langchain",
"version": "1.x.x",
"description": "LangChain nodes for n8n"
}
}
How It Works
- MCP Client Request: Client calls
get_node_source_codetool with node type - Server Processing: MCP server receives request and invokes
NodeSourceExtractor - File System Search: Extractor searches known n8n paths for the node file
- Source Extraction: Reads the JavaScript source code and optional credential files
- Response Formation: Returns structured data with source code and metadata
Troubleshooting
Node Not Found
If the AI Agent node is not found:
- Check if langchain nodes are installed:
docker exec n8n-test ls /usr/local/lib/node_modules/n8n/node_modules/@n8n/
- Install langchain nodes:
docker exec n8n-test npm install -g @n8n/n8n-nodes-langchain
Permission Issues
Ensure the MCP container has read access to n8n's node_modules:
volumes:
- n8n_modules:/usr/local/lib/node_modules/n8n/node_modules:ro
Alternative Node Types
You can test with other built-in nodes:
n8n-nodes-base.HttpRequestn8n-nodes-base.Coden8n-nodes-base.If
Success Criteria
The test is successful when:
- ✅ MCP server starts and accepts connections
- ✅ Client can discover the
get_node_source_codetool - ✅ Server locates the AI Agent node in the file system
- ✅ Complete source code is extracted and returned
- ✅ Response includes metadata (location, package info)
Security Considerations
- Source code extraction is read-only
- Access is limited to n8n's node_modules directory
- Authentication token required for MCP server access
- No modification of files is possible
Next Steps
After successful testing:
- Deploy to production environment
- Configure proper authentication
- Set up monitoring for extraction requests
- Document available node types for users