← 返回
未分类 Key

N8n Mcp

Operate n8n workflow automation platform via MCP (Model Context Protocol). Use when: (1) Creating, updating, or managing n8n workflows, (2) Executing or test...
通过 MCP(模型上下文协议)操作 n8n 工作流自动化平台。适用于:(1)创建、更新或管理n8n 工作流,(2)执行或测试...
itian932 itian932 来源
未分类 clawhub v1.1.0 2 版本 100000 Key: 需要
★ 2
Stars
📥 452
下载
💾 0
安装
2
版本
#latest

概述

n8n MCP Integration

Connect to n8n's official MCP server to programmatically build, execute, and manage workflows.

Version Support

  • n8n version: 2.16.1+
  • MCP protocol: 2024-11-05
  • Server name: n8n MCP Server v1.1.0

Configuration

MCP Server Setup

In n8n UI:

  1. Go to Settings → n8n API
  2. Create an API key for REST API access
  3. Create an MCP token for MCP server access

Connection Config

{
  "mcpServers": {
    "n8n-mcp": {
      "type": "http",
      "url": "http://localhost:5678/mcp-server/http",
      "headers": {
        "Authorization": "Bearer <MCP_TOKEN>"
      }
    }
  }
}

Environment Variables

export N8N_MCP_URL="http://localhost:5678/mcp-server/http"
export N8N_MCP_TOKEN="<your-mcp-token>"

Available Tools (25)

Workflow Management

ToolDescription
-------------------
search_workflowsSearch workflows with filters (query, projectId, limit)
get_workflow_detailsGet workflow details including trigger info
publish_workflowActivate workflow for production execution
unpublish_workflowDeactivate workflow
archive_workflowArchive a workflow
update_workflowUpdate workflow from validated SDK code

Workflow Execution

ToolDescription
-------------------
execute_workflowExecute workflow by ID, returns execution ID immediately
get_executionGet execution details and results
test_workflowTest workflow with pin data (bypass external services)
prepare_test_pin_dataGenerate test pin data schemas for workflow

Workflow Creation (SDK)

ToolDescription
-------------------
get_sdk_referenceGet SDK docs, patterns, expressions, functions
search_nodesSearch n8n nodes by service/type
get_node_typesGet TypeScript type definitions for nodes
get_suggested_nodesGet curated node recommendations by category
validate_workflowValidate workflow code before creating
create_workflow_from_codeCreate workflow from validated SDK code

Data Tables

ToolDescription
-------------------
search_data_tablesSearch data tables by name/project
create_data_tableCreate new data table with columns
rename_data_tableRename an existing data table
add_data_table_columnAdd column to data table
delete_data_table_columnDelete column from data table
rename_data_table_columnRename a column
add_data_table_rowsInsert rows into data table (max 1000/call)

Projects & Folders

ToolDescription
-------------------
search_projectsSearch projects by name/type
search_foldersSearch folders within a project

Tool Parameters Reference

search_workflows

{
  "query": "string (optional) - Filter by name or description",
  "projectId": "string (optional) - Filter by project ID",
  "limit": "integer (optional, max 200) - Limit results"
}

execute_workflow

{
  "workflowId": "string (required) - The workflow ID to execute",
  "executionMode": "string (optional) - 'manual' for current version, 'production' for published version",
  "inputs": "object (optional) - Inputs for chat/form/webhook workflows"
}

get_execution

{
  "workflowId": "string (required)",
  "executionId": "string (required)",
  "includeData": "boolean (optional) - Include node execution data",
  "nodeNames": "array (optional) - Filter data by node names",
  "truncateData": "integer (optional) - Limit data items per node"
}

test_workflow

{
  "workflowId": "string (required)",
  "pinData": "object (required) - Pin data for nodes. Keys are node names, values are arrays of items wrapped in 'json': [{\"json\": {\"id\": \"123\"}}]",
  "triggerNodeName": "string (optional) - For multi-trigger workflows"
}

create_workflow_from_code

{
  "code": "string (required) - Validated SDK workflow code",
  "name": "string (optional) - Workflow name",
  "description": "string (optional, max 255 chars)",
  "projectId": "string (optional) - Project ID",
  "folderId": "string (optional) - Folder ID (requires projectId)"
}

search_nodes

{
  "queries": "array (required) - Search queries: service names, trigger types, or utility nodes"
}

get_node_types

{
  "nodeIds": "array (required) - Node IDs or objects with discriminators: [{\"nodeId\": \"...\", \"resource\": \"...\", \"operation\": \"...\"}]"
}

get_suggested_nodes

{
  "categories": "array (required) - Categories: chatbot, notification, scheduling, data_transformation, data_persistence, data_extraction, document_processing, form_input, content_generation, triage, scraping_and_research"
}

get_sdk_reference

{
  "section": "string (optional) - 'patterns', 'expressions', 'functions', 'rules', 'import', 'guidelines', 'design', or 'all' (default)"
}

create_data_table

{
  "projectId": "string (required)",
  "name": "string (required) - Unique table name",
  "columns": "array (required) - Column definitions: [{\"name\": \"...\", \"type\": \"...\"}]"
}

add_data_table_rows

{
  "dataTableId": "string (required)",
  "projectId": "string (required)",
  "rows": "array (required, max 1000) - Row objects: [{\"column1\": \"value1\", \"column2\": \"value2\"}]"
}

Usage Patterns

1. Creating a Workflow (Recommended Flow)

# Step 1: Get SDK reference
curl -X POST -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_sdk_reference","arguments":{"section":"all"}}}' \
  "$N8N_MCP_URL"

# Step 2: Get suggested nodes for your use case
curl -X POST ... -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_suggested_nodes","arguments":{"categories":["notification","scheduling"]}}}'

# Step 3: Search specific nodes
curl -X POST ... -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search_nodes","arguments":{"queries":["schedule trigger","slack","set"]}}}'

# Step 4: Get node types (CRITICAL - don't guess parameter names)
curl -X POST ... -d '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"get_node_types","arguments":{"nodeIds":["n8n-nodes-base.scheduleTrigger","n8n-nodes-base.slack"]}}}'

# Step 5: Validate workflow code
curl -X POST ... -d '{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"validate_workflow","arguments":{"code":"..."}}}'

# Step 6: Create workflow
curl -X POST ... -d '{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"create_workflow_from_code","arguments":{"code":"...","name":"My Workflow","description":"..."}}}'

2. Executing and Monitoring a Workflow

# Execute workflow
curl -X POST ... -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"execute_workflow","arguments":{"workflowId":"xxx"}}}'

# Get execution result (with data)
curl -X POST ... -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_execution","arguments":{"workflowId":"xxx","executionId":"yyy","includeData":true}}}'

3. Testing a Workflow (Before Publishing)

# Prepare test pin data
curl -X POST ... -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"prepare_test_pin_data","arguments":{"workflowId":"xxx"}}}'

# Test with pin data (pinData format is CRITICAL)
curl -X POST ... -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"test_workflow","arguments":{"workflowId":"xxx","pinData":{"NodeName":[{"json":{"field":"value"}}]}}}}'

4. Working with Data Tables

# Search data tables
curl -X POST ... -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search_data_tables","arguments":{"query":"users"}}}'

# Add rows to data table
curl -X POST ... -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"add_data_table_rows","arguments":{"dataTableId":"xxx","projectId":"yyy","rows":[{"name":"John","email":"john@example.com"}]}}}'

SDK Workflow Example

import { workflow, trigger, node } from 'n8n-workflow-sdk';

export default workflow({
  name: 'Daily Slack Notification',
  description: 'Send daily summary to Slack',
  nodes: [
    trigger.schedule({
      name: 'Schedule',
      rule: { interval: [{ field: 'hours', hoursInterval: 24 }] }
    }),
    node.set({
      name: 'Prepare Message',
      values: { text: 'Daily report ready!' }
    }),
    node.slack({
      name: 'Send to Slack',
      resource: 'message',
      operation: 'send',
      channel: '#general',
      text: '={{ $node["Prepare Message"].json.text }}'
    })
  ],
  connections: [
    { from: 'Schedule', to: 'Prepare Message' },
    { from: 'Prepare Message', to: 'Send to Slack' }
  ]
});

MCP Protocol Notes

  • Transport: HTTP with SSE (Server-Sent Events)
  • Content-Type: application/json
  • Accept: application/json, text/event-stream (required)
  • Auth: Bearer token in Authorization header

Common Errors

ErrorSolution
-----------------
"Not Acceptable"Add Accept: application/json, text/event-stream header
"Unauthorized"Check MCP token is valid
"Not found"Verify MCP server URL is correct
Invalid workflowAlways call validate_workflow before create_workflow_from_code
Wrong pinData formatWrap items in json: [{"json": {...}}] not [{}]

Best Practices

  1. Always get SDK reference first - Call get_sdk_reference before building workflows
  2. Use get_node_types - Never guess parameter names; get exact types from the API
  3. Validate before creating - Always call validate_workflow before create_workflow_from_code
  4. Test before publishing - Use test_workflow with pin data to verify workflow logic
  5. Use suggested nodes - Call get_suggested_nodes for curated recommendations by category
  6. Correct pinData format - Items must be wrapped in json property: [{"json": {...}}]

References

版本历史

共 2 个版本

  • v1.1.0 当前
    2026-05-09 16:46 安全 安全
  • v1.0.1
    2026-05-07 06:23 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

design-media

Multi Edge Tts Cn

itian932
Edge-TTS 在线语音合成 skill。基于微软 Edge TTS 引擎,生成速度快(1-2秒),支持多种音色和输出格式。同时支持飞书(OGG/Opus)和企业微信(AMR)。默认音色 xiaoxiao_lively。需联网。
★ 1 📥 427
ai-agent

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,094 📥 820,749
ai-agent

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,390 📥 321,732