Major features implemented: - SQLite storage service with FTS5 for fast node search - Database rebuild mechanism for bulk node extraction - MCP tools: search_nodes, extract_all_nodes, get_node_statistics - Production Docker deployment with persistent storage - Management scripts for database operations - Comprehensive test suite for all functionality Database capabilities: - Stores node source code and metadata - Full-text search by node name or content - No versioning (stores latest only as per requirements) - Supports complete database rebuilds - ~4.5MB database with 500+ nodes indexed Production features: - Automated deployment script - Docker Compose production configuration - Database initialization on first run - Volume persistence for data - Management utilities for operations Documentation: - Updated README with complete instructions - Production deployment guide - Clear troubleshooting section - API reference for all new tools 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
10 KiB
n8n-MCP Integration
Complete integration between n8n workflow automation and Model Context Protocol (MCP), enabling bidirectional communication between n8n workflows and AI assistants.
Overview
This project provides two main components:
- MCP Server: Allows AI assistants (like Claude) to interact with n8n workflows, execute them, and explore n8n nodes
- n8n Custom Node: Enables n8n workflows to connect to and use MCP servers
Important: The MCP server uses stdio transport and is designed to be invoked by AI assistants like Claude Desktop. It's not a standalone HTTP server but rather a tool that AI assistants can call directly.
Features
- Bidirectional Integration: n8n workflows can call MCP tools, and MCP servers can execute n8n workflows
- Node Source Extraction: Extract and search source code from any n8n node, including AI Agent nodes
- SQLite Database: Full-text search for n8n node documentation and source code (500+ nodes indexed)
- Production Ready: Docker-based deployment with persistent storage
- Comprehensive MCP Tools: 12+ tools for workflow management, node exploration, and database search
- Custom n8n Node: Connect to any MCP server from n8n workflows
- Auto-indexing: Automatically builds a searchable database of all n8n nodes on first run
Prerequisites
- Node.js 18+
- Docker and Docker Compose (for production deployment)
- n8n instance with API access enabled
- (Optional) Claude Desktop for MCP integration
Quick Start
Installation
# Clone the repository
git clone https://github.com/yourusername/n8n-mcp.git
cd n8n-mcp
# Install dependencies
npm install
# Copy environment template
cp .env.example .env
# Edit .env with your n8n credentials
# Build the project
npm run build
# Initialize the database
npm run db:init
# (Optional) Rebuild database with all nodes
npm run db:rebuild
Development
# Run tests
npm test
# Start development server
npm run dev
# Type checking
npm run typecheck
Production Deployment
# Use the automated deployment script
./scripts/deploy-production.sh
# Or manually with Docker Compose
docker compose -f docker-compose.prod.yml up -d
See Production Deployment Guide for detailed instructions.
Configuration
Environment variables (.env file):
# n8n Configuration
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=your-password
N8N_HOST=localhost
N8N_API_KEY=your-api-key
# Database
NODE_DB_PATH=/app/data/nodes.db
# 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
Workflow Management
execute_workflow- Execute an n8n workflow by IDlist_workflows- List all workflows with filtering optionsget_workflow- Get detailed workflow informationcreate_workflow- Create new workflows programmaticallyupdate_workflow- Update existing workflowsdelete_workflow- Delete workflowsget_executions- Get workflow execution historyget_execution_data- Get detailed execution data
Node Exploration & Search
list_available_nodes- List all available n8n nodesget_node_source_code- Extract source code of any n8n nodesearch_nodes- Search nodes by name or content using full-text searchextract_all_nodes- Extract and index all nodes to databaseget_node_statistics- Get database statistics (total nodes, packages, etc.)
Using the n8n MCP Node
- Install the node in n8n:
# Copy to n8n custom nodes directory cp -r dist/n8n/* ~/.n8n/custom/ # Or use the install script ./scripts/install-n8n-node.sh - 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
Components
- MCP Server (
src/mcp/): Exposes n8n operations as MCP tools - n8n Custom Node (
src/n8n/): Allows n8n to connect to MCP servers - SQLite Storage (
src/services/): Persistent storage with full-text search - Bridge Layer (
src/utils/): Converts between n8n and MCP formats
Database Management
The SQLite database stores n8n node documentation and source code with full-text search capabilities:
# Initialize empty database
npm run db:init
# Rebuild the entire database (indexes all nodes)
npm run db:rebuild
# In production
./scripts/manage-production.sh rebuild-db
# View statistics
./scripts/manage-production.sh db-stats
Search Examples
// Search for nodes by name
await mcp.callTool('search_nodes', { query: 'webhook' })
// Search in specific package
await mcp.callTool('search_nodes', {
query: 'http',
packageName: 'n8n-nodes-base'
})
// Get database statistics
await mcp.callTool('get_node_statistics', {})
Testing
Run All Tests
npm test
Test Specific Features
# Test node extraction
node tests/test-mcp-extraction.js
# Test database search
node tests/test-sqlite-search.js
# Test AI Agent extraction
./scripts/test-ai-agent-extraction.sh
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-nodes-base.Webhook)includeCredentials(boolean, optional): Include credential type definitions if available
search_nodes
Search nodes using full-text search in the SQLite database.
Parameters:
query(string, optional): Search term for node names/descriptionspackageName(string, optional): Filter by package namenodeType(string, optional): Filter by node type patternhasCredentials(boolean, optional): Filter nodes with credentialslimit(number, optional): Limit results (default: 20)
extract_all_nodes
Extract and index all available nodes to the database.
Parameters:
packageFilter(string, optional): Filter by package namelimit(number, optional): Limit number of nodes to extract
get_node_statistics
Get database statistics including total nodes, packages, and size.
No parameters required.
list_available_nodes
List all available n8n nodes in the system.
Parameters:
category(string, optional): Filter by categorysearch(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
Management
Use the management script for production operations:
# Check status
./scripts/manage-production.sh status
# View logs
./scripts/manage-production.sh logs
# Create backup
./scripts/manage-production.sh backup
# Update services
./scripts/manage-production.sh update
Troubleshooting
Common Issues
-
MCP server keeps restarting in Docker
- This is expected behavior. The MCP server uses stdio transport and waits for input from AI assistants.
- For testing, use the development mode or invoke through Claude Desktop.
-
Database not found
- Run
npm run db:initto create the database - Run
npm run db:rebuildto populate with all nodes
- Run
-
n8n API connection failed
- Verify n8n is running and accessible
- Check API key in
.envfile - Ensure n8n API is enabled in settings
-
Node extraction fails
- Ensure Docker volume mounts are correct
- Check read permissions on node_modules directory
Documentation
Security
- Token-based authentication for n8n API
- Read-only access to node source files
- Isolated Docker containers
- Persistent volume encryption (optional)
Project Structure
n8n-mcp/
├── src/
│ ├── mcp/ # MCP server implementation
│ ├── n8n/ # n8n custom node
│ ├── services/ # SQLite storage service
│ ├── utils/ # Utilities and helpers
│ └── scripts/ # Database management scripts
├── tests/ # Test suite
├── docs/ # Documentation
├── scripts/ # Deployment and management scripts
└── data/ # SQLite database (created on init)
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Ensure all tests pass
- Submit a pull request
License
ISC License
Support
- GitHub Issues: Report bugs or request features
- n8n Community: n8n.io/community
- MCP Documentation: modelcontextprotocol.io