- Updated CLAUDE.md with complete project state and capabilities - Enhanced README.md with node extraction features and examples - Added CHANGELOG.md to track version history - Documented new MCP tools and resources for node source extraction - Added special features section highlighting AI Agent capabilities 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6.6 KiB
6.6 KiB
n8n-mcp
Integration between n8n workflow automation and Model Context Protocol (MCP). This project provides:
- An MCP server that exposes n8n workflows and operations to AI assistants
- A custom n8n node for connecting to MCP servers from within workflows
Features
- MCP Server: Expose n8n workflows as tools, resources, and prompts for AI assistants
- n8n Node: Connect to any MCP server from n8n workflows
- Bidirectional Integration: Use AI capabilities in n8n and n8n automation in AI contexts
- Node Source Extraction: Extract source code from any n8n node, including AI Agent nodes
- Authentication: Secure token-based authentication
- Flexible Transport: Support for WebSocket and stdio connections
Quick Start
Prerequisites
- Node.js 18+
- n8n instance with API access enabled
- MCP-compatible AI assistant (Claude, etc.)
Installation
# Clone the repository
git clone https://github.com/czlonkowski/n8n-mcp.git
cd n8n-mcp
# Install dependencies
npm install
# Copy environment configuration
cp .env.example .env
# Configure your n8n API credentials
# Edit .env with your n8n instance details
Running the MCP Server
# Build the project
npm run build
# Start the MCP server
npm start
For development:
npm run dev
Configuration
Environment Variables
Create a .env file based on .env.example:
# MCP Server Configuration
MCP_SERVER_PORT=3000
MCP_SERVER_HOST=localhost
# n8n Configuration
N8N_API_URL=http://localhost:5678
N8N_API_KEY=your-n8n-api-key
# Authentication
MCP_AUTH_TOKEN=your-secure-token
# Logging
LOG_LEVEL=info
Usage
Using the MCP Server with Claude
Add the server to your Claude configuration:
{
"mcpServers": {
"n8n": {
"command": "node",
"args": ["/path/to/n8n-mcp/dist/index.js"],
"env": {
"N8N_API_URL": "http://localhost:5678",
"N8N_API_KEY": "your-api-key"
}
}
}
}
Available MCP Tools
execute_workflow- Execute an n8n workflow by IDlist_workflows- List all available workflowsget_workflow- Get details of a specific workflowcreate_workflow- Create a new workflowupdate_workflow- Update an existing workflowdelete_workflow- Delete a workflowget_executions- Get workflow execution historyget_execution_data- Get detailed execution dataget_node_source_code- Extract source code of any n8n nodelist_available_nodes- List all available n8n nodes
Using the n8n MCP Node
- Copy the node files to your n8n custom nodes directory
- Restart n8n
- The MCP node will appear in the nodes panel
- Configure with your MCP server credentials
- Select operations: Call Tool, List Tools, Read Resource, etc.
Example n8n Workflow
{
"name": "MCP AI Assistant",
"nodes": [
{
"name": "MCP",
"type": "mcp",
"parameters": {
"operation": "callTool",
"toolName": "generate_text",
"toolArguments": "{\"prompt\": \"Write a summary\"}"
}
}
]
}
Architecture
Project Structure
n8n-mcp/
├── src/
│ ├── mcp/ # MCP server implementation
│ ├── n8n/ # n8n node implementation
│ ├── utils/ # Shared utilities
│ └── types/ # TypeScript type definitions
├── tests/ # Test files
└── dist/ # Compiled output
Key Components
- MCP Server: Handles MCP protocol requests and translates to n8n API calls
- n8n API Client: Manages communication with n8n instance
- Bridge Layer: Converts between n8n and MCP data formats
- Authentication: Validates tokens and manages access control
Development
Running Tests
npm test
Building
npm run build
Type Checking
npm run typecheck
API Reference
MCP Tools
execute_workflow
Execute an n8n workflow by ID.
Parameters:
workflowId(string, required): The workflow IDdata(object, optional): Input data for the workflow
list_workflows
List all available workflows.
Parameters:
active(boolean, optional): Filter by active statustags(array, optional): Filter by tags
get_node_source_code
Extract source code of any n8n node.
Parameters:
nodeType(string, required): The node type identifier (e.g.,@n8n/n8n-nodes-langchain.Agent)includeCredentials(boolean, optional): Include credential type definitions if available
list_available_nodes
List all available n8n nodes in the system.
Parameters:
category(string, optional): Filter by category (e.g., AI, Data Transformation)search(string, optional): Search term to filter nodes
MCP Resources
workflow://active- List of active workflowsworkflow://all- List of all workflowsexecution://recent- Recent execution historycredentials://types- Available credential typesnodes://available- Available n8n nodesnodes://source/{nodeType}- Source code of specific n8n node
MCP Prompts
create_workflow_prompt- Generate workflow creation promptsdebug_workflow_prompt- Debug workflow issuesoptimize_workflow_prompt- Optimize workflow performanceexplain_workflow_prompt- Explain workflow functionality
Troubleshooting
Common Issues
- Connection refused: Ensure n8n is running and API is enabled
- Authentication failed: Check your API key in .env
- Workflow not found: Verify workflow ID exists in n8n
- MCP connection failed: Check server is running and accessible
Debug Mode
Enable debug logging:
LOG_LEVEL=debug
Special Features
AI Agent Node Extraction
The MCP server can extract source code from n8n nodes, particularly useful for AI Agent nodes:
# Test AI Agent extraction
./scripts/test-ai-agent-extraction.sh
# Or use the standalone test
node tests/test-mcp-extraction.js
This feature allows AI assistants to:
- Understand n8n node implementations
- Generate compatible code
- Debug workflow issues
- Create custom variations
Docker Volumes for Node Access
When running in Docker, mount n8n's node_modules for source extraction:
volumes:
- n8n_modules:/usr/local/lib/node_modules/n8n/node_modules:ro
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
ISC License - see LICENSE file for details
Support
- Issues: https://github.com/czlonkowski/n8n-mcp/issues
- n8n Documentation: https://docs.n8n.io
- MCP Specification: https://modelcontextprotocol.io