n8n MCP 服务器
模型上下文协议 (MCP) 服务器允许 AI 助手通过自然语言与 n8n 工作流进行交互。
概述
该 MCP 服务器为 AI 助手提供工具和资源,用于管理 n8n 工作流程和执行。它允许助手:
列出、创建、更新和删除工作流
激活和停用工作流程
执行工作流程并监控其状态
访问工作流程信息和执行统计数据
Related MCP server: MCP Server for n8n Integration
安装
先决条件
Node.js 18 或更高版本
已启用 API 访问的 n8n 实例
从 npm 安装
npm install -g n8n-mcp-server从源安装
# 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 .Docker 安装
您还可以使用 Docker 运行服务器:
# Pull the image
docker pull leonardsellem/n8n-mcp-server
# Run the container with your n8n API configuration
docker run -e N8N_API_URL=http://your-n8n:5678/api/v1 \
-e N8N_API_KEY=your_n8n_api_key \
-e N8N_WEBHOOK_USERNAME=username \
-e N8N_WEBHOOK_PASSWORD=password \
leonardsellem/n8n-mcp-server配置
在运行服务器的目录中创建一个.env文件,使用.env.example作为模板:
cp .env.example .env配置以下环境变量:
多变的 | 描述 | 例子 |
| n8n API 的完整 URL,包括 |
|
| 用于使用 n8n 进行身份验证的 API 密钥 |
|
| Webhook 身份验证的用户名(如果使用 Webhook) |
|
| Webhook 身份验证的密码 |
|
| 启用调试日志记录(可选) |
|
生成 n8n API 密钥
在浏览器中打开您的 n8n 实例
前往“设置”>“API”>“API 密钥”
创建具有适当权限的新 API 密钥
将密钥复制到你的
.env文件
用法
运行服务器
从安装目录:
n8n-mcp-server或者如果全局安装:
n8n-mcp-server与人工智能助手集成
构建服务器( npm run build )后,你需要配置你的 AI 助手(例如带有 Claude 扩展的 VS Code 或 Claude 桌面应用)来运行它。这通常需要编辑 JSON 配置文件。
示例配置(例如,在 VS Code
{
"mcpServers": {
// Give your server a unique name
"n8n-local": {
// Use 'node' to execute the built JavaScript file
"command": "node",
// Provide the *absolute path* to the built index.js file
"args": [
"/path/to/your/cloned/n8n-mcp-server/build/index.js"
// On Windows, use double backslashes:
// "C:\\path\\to\\your\\cloned\\n8n-mcp-server\\build\\index.js"
],
// Environment variables needed by the server
"env": {
"N8N_API_URL": "http://your-n8n-instance:5678/api/v1", // Replace with your n8n URL
"N8N_API_KEY": "YOUR_N8N_API_KEY", // Replace with your key
// Add webhook credentials only if you plan to use webhook tools
// "N8N_WEBHOOK_USERNAME": "your_webhook_user",
// "N8N_WEBHOOK_PASSWORD": "your_webhook_password"
},
// Ensure the server is enabled
"disabled": false,
// Default autoApprove settings
"autoApprove": []
}
// ... other servers might be configured here
}
}要点:
将
/path/to/your/cloned/n8n-mcp-server/替换为您克隆和构建存储库的实际绝对路径。使用适合您操作系统的正确路径分隔符(macOS/Linux 使用正斜杠
/,Windows 使用双反斜杠\\)。确保您提供正确的
N8N_API_URL(包括/api/v1)和N8N_API_KEY。需要先构建服务器(
npm run build),然后助手才能运行build/index.js文件。
可用工具
该服务器提供以下工具:
使用 Webhook
此 MCP 服务器支持通过 n8n webhook 执行工作流。使用此功能的步骤如下:
在 n8n 中创建一个由 webhook 触发的工作流。
在您的 webhook 节点上设置基本身份验证。
使用
run_webhook工具来触发工作流,只需传递工作流名称。
例子:
const result = await useRunWebhook({
workflowName: "hello-world", // Will call <n8n-url>/webhook/hello-world
data: {
prompt: "Hello from AI assistant!"
}
});使用N8N_WEBHOOK_USERNAME和N8N_WEBHOOK_PASSWORD环境变量自动处理 webhook 身份验证。
工作流管理
workflow_list:列出所有工作流程workflow_get:获取特定工作流程的详细信息workflow_create:创建一个新的工作流程workflow_update:更新现有工作流程workflow_delete:删除工作流程workflow_activate:激活工作流程workflow_deactivate:停用工作流程
执行管理
execution_run:通过 API 执行工作流程run_webhook:通过 webhook 执行工作流execution_get:获取特定执行的详细信息execution_list:列出工作流程的执行execution_stop:停止正在运行的执行
资源
服务器提供以下资源:
n8n://workflows/list:所有工作流程的列表n8n://workflow/{id}:特定工作流的详细信息n8n://executions/{workflowId}:工作流的执行列表n8n://execution/{id}:特定执行的详细信息
发展
建筑
npm run build以开发模式运行
npm run dev测试
npm test代码检查
npm run lint执照
麻省理工学院