This commit adds a new MCP tool, run_webhook, which allows executing n8n workflows via webhooks instead of using the API directly. This implementation: 1. Creates a new RunWebhookHandler class that: - Takes a workflowName parameter and automatically prepends "webhook/" to create the full path - Uses basic authentication from environment variables - Makes HTTP requests to the webhook endpoints and returns the responses 2. Adds new environment variables: - N8N_WEBHOOK_USERNAME: Username for webhook basic authentication - N8N_WEBHOOK_PASSWORD: Password for webhook basic authentication 3. Updates server configuration and handlers to register and expose the new tool 4. Adds comprehensive documentation in: - execution-tools.md with examples and schema - README.md with configuration and usage information This provides a simpler alternative to the API-based workflow execution, allowing Claude to trigger n8n webhooks directly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
181 lines
3.9 KiB
Markdown
181 lines
3.9 KiB
Markdown
# n8n MCP Server
|
|
|
|
A Model Context Protocol (MCP) server that allows AI assistants to interact with n8n workflows through natural language.
|
|
|
|
## Overview
|
|
|
|
This MCP server provides tools and resources for AI assistants to manage n8n workflows and executions. It allows assistants to:
|
|
|
|
- List, create, update, and delete workflows
|
|
- Activate and deactivate workflows
|
|
- Execute workflows and monitor their status
|
|
- Access workflow information and execution statistics
|
|
|
|
## Installation
|
|
|
|
### Prerequisites
|
|
|
|
- Node.js 18 or later
|
|
- n8n instance with API access enabled
|
|
|
|
### Install from npm
|
|
|
|
```bash
|
|
npm install -g n8n-mcp-server
|
|
```
|
|
|
|
### Install from source
|
|
|
|
```bash
|
|
# Clone the repository
|
|
git clone https://github.com/leonardsellem/n8n-mcp-server.git
|
|
cd n8n-mcp-server
|
|
|
|
# Install dependencies
|
|
npm install
|
|
|
|
# Build the project
|
|
npm run build
|
|
|
|
# Optional: Install globally
|
|
npm install -g .
|
|
```
|
|
|
|
## Configuration
|
|
|
|
Create a `.env` file in the directory where you'll run the server, using `.env.example` as a template:
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
Configure the following environment variables:
|
|
|
|
| Variable | Description | Example |
|
|
|----------|-------------|---------|
|
|
| `N8N_API_URL` | URL of the n8n API | `http://localhost:5678/api/v1` |
|
|
| `N8N_API_KEY` | API key for authenticating with n8n | `n8n_api_...` |
|
|
| `N8N_WEBHOOK_USERNAME` | Username for webhook authentication | `username` |
|
|
| `N8N_WEBHOOK_PASSWORD` | Password for webhook authentication | `password` |
|
|
| `DEBUG` | Enable debug logging (optional) | `true` or `false` |
|
|
|
|
### Generating an n8n API Key
|
|
|
|
1. Open your n8n instance in a browser
|
|
2. Go to Settings > API > API Keys
|
|
3. Create a new API key with appropriate permissions
|
|
4. Copy the key to your `.env` file
|
|
|
|
## Usage
|
|
|
|
### Running the Server
|
|
|
|
From the installation directory:
|
|
|
|
```bash
|
|
n8n-mcp-server
|
|
```
|
|
|
|
Or if installed globally:
|
|
|
|
```bash
|
|
n8n-mcp-server
|
|
```
|
|
|
|
### Integrating with AI Assistants
|
|
|
|
To use this MCP server with AI assistants, you need to register it with your AI assistant platform. The exact method depends on the platform you're using.
|
|
|
|
For example, with the MCP installer:
|
|
|
|
```bash
|
|
npx @anaisbetts/mcp-installer
|
|
```
|
|
|
|
Then register the server:
|
|
|
|
```
|
|
install_local_mcp_server path/to/n8n-mcp-server
|
|
```
|
|
|
|
## Available Tools
|
|
|
|
The server provides the following tools:
|
|
|
|
### Using Webhooks
|
|
|
|
This MCP server supports executing workflows through n8n webhooks. To use this functionality:
|
|
|
|
1. Create a webhook-triggered workflow in n8n.
|
|
2. Set up Basic Authentication on your webhook node.
|
|
3. Use the `run_webhook` tool to trigger the workflow, passing just the workflow name.
|
|
|
|
Example:
|
|
```javascript
|
|
const result = await useRunWebhook({
|
|
workflowName: "hello-world", // Will call <n8n-url>/webhook/hello-world
|
|
data: {
|
|
prompt: "Hello from AI assistant!"
|
|
}
|
|
});
|
|
```
|
|
|
|
The webhook authentication is handled automatically using the `N8N_WEBHOOK_USERNAME` and `N8N_WEBHOOK_PASSWORD` environment variables.
|
|
|
|
### Workflow Management
|
|
|
|
- `workflow_list`: List all workflows
|
|
- `workflow_get`: Get details of a specific workflow
|
|
- `workflow_create`: Create a new workflow
|
|
- `workflow_update`: Update an existing workflow
|
|
- `workflow_delete`: Delete a workflow
|
|
- `workflow_activate`: Activate a workflow
|
|
- `workflow_deactivate`: Deactivate a workflow
|
|
|
|
### Execution Management
|
|
|
|
- `execution_run`: Execute a workflow via the API
|
|
- `run_webhook`: Execute a workflow via a webhook
|
|
- `execution_get`: Get details of a specific execution
|
|
- `execution_list`: List executions for a workflow
|
|
- `execution_stop`: Stop a running execution
|
|
|
|
## Resources
|
|
|
|
The server provides the following resources:
|
|
|
|
- `n8n://workflows/list`: List of all workflows
|
|
- `n8n://workflow/{id}`: Details of a specific workflow
|
|
- `n8n://executions/{workflowId}`: List of executions for a workflow
|
|
- `n8n://execution/{id}`: Details of a specific execution
|
|
|
|
## Development
|
|
|
|
### Building
|
|
|
|
```bash
|
|
npm run build
|
|
```
|
|
|
|
### Running in Development Mode
|
|
|
|
```bash
|
|
npm run dev
|
|
```
|
|
|
|
### Testing
|
|
|
|
```bash
|
|
npm test
|
|
```
|
|
|
|
### Linting
|
|
|
|
```bash
|
|
npm run lint
|
|
```
|
|
|
|
## License
|
|
|
|
MIT
|