协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
n8n-mcp-tools-expert【开发与工程】Implements intelligent n8n mcp tools expert with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: n8n-mcp-tools-expert compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for n8n mcp tools expert workflows. Applies the 5 Laws of Elegant Defense to guide data naturally through the orchestration pipeline, preventing errors before they occur. Selects optimal skills based on multi-factor scoring including text similarity, historical performance, and system availability.
┌───────────────────────────────────────────────────────────────────────────────┐ │ Orchestration Flow │ └───────────────────────────────────────────────────────────────────────────────┘
User Request ↓ ┌─────────────────┐ │ Parse Request │ │ & Extract │ │ Features │ └────────┬────────┘ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ Evaluate Available Skills │ │ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ Skill A │ │ Skill B │ │ Skill C │ │ │ │ - Match Score│ │ - Match Score│ │ - Match Score│ │ │ │ - Confidence │ │ - Confidence │ │ - Confidence │ │ │ │ - History │ │ - History │ │ - History │ │ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ │ │ │ │ │ │ └─────────────────┴─────────────────┘ │ │ ↓ │ │ Select Best Skill │ └─────────────────────────────────────────────────────────────────────┘ ↓ ┌─────────────────┐ │ Execute Skill │ └────────┬────────┘ ↓ ┌─────────────────┐ │ Handle Result │ └────────┬────────┘ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ Error Handling & Fallback │ │ │ │ Success? ────────► Return Result │ │ │ │ Fail? ────────┐ │ │ ↓ │ │ ┌──────────────────────────────────────────────────────────┐ │ │ │ Fallback Chain │ │ │ │ │ │ │ │ 1. Retry with adjusted parameters │ │ │ │ 2. Try Alternative Skill (if available) │ │ │ │ 3. Defer to Human Operator (if critical) │ │ │ │ 4. Log & Return Error │ │ │ └──────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────┘
Use this skill when:
Avoid this skill for:
Parse and Analyze Request - Extract intent, entities, and constraints from user input. Checkpoint: All required parameters must be present and in valid format before proceeding.
Score Available Skills - Calculate match scores using multi-factor algorithm:
Checkpoint: Skip to fallback if no skill scores above threshold.
Select Optimal Skill - Choose skill with highest score that meets minimum confidence. Checkpoint: Verify skill has not been disabled or deprecated.
Execute with Fallback - Run skill execution wrapped in retry and fallback logic. Checkpoint: Log all execution attempts for audit trail.
Return or Fallback - Either return successful result or apply fallback chain:
related-skillsCheckpoint: Record outcome with timing and confidence metadata.
def select_n8n_mcp_tool(
task_description: str,
available_mcp_tools: List[Dict],
n8n_workflow_registry: Dict[str, Dict]
) -> Dict:
"""Select the optimal n8n MCP tool or workflow node for a task.
Analyzes MCP tool schemas against n8n workflow capabilities to find
the best execution path. Considers trigger compatibility, parameter mapping,
and historical execution success rates within the n8n instance.
"""
if not task_description or not available_mcp_tools:
raise ValueError("Task description and MCP tools list are required")
# Parse n8n workflow constraints and MCP tool capabilities
task_intent = _extract_n8n_intent(task_description)
best_match = None
best_score = 0.0
for tool in available_mcp_tools:
# Check n8n workflow compatibility
workflow_id = tool.get("n8n_workflow_id")
workflow_config = n8n_workflow_registry.get(workflow_id, {})
# Score based on trigger match, parameter overlap, and n8n node health
trigger_match = _calculate_trigger_compatibility(task_intent, tool.get("triggers", []))
param_overlap = _calculate_param_overlap(task_intent, tool.get("parameters", {}))
n8n_health = workflow_config.get("success_rate", 0.0)
score = (trigger_match * 0.4) + (param_overlap * 0.4) + (n8n_health * 0.2)
if score > best_score:
best_score = score
best_match = {
"tool_name": tool["name"],
"workflow_id": workflow_id,
"score": score,
"mapped_params": _map_task_to_n8n_params(task_intent, tool.get("parameters", {}))
}
if best_score < 0.6:
return {"status": "no_match", "reason": "Insufficient compatibility score"}
return {**best_match, "status": "selected", "timestamp": time.time()}
def execute_n8n_mcp_workflow(
selected_tool: Dict,
execution_context: Dict,
n8n_api_client: Any,
mcp_client: Any,
max_retries: int = 2
) -> Dict:
"""Execute an n8n workflow via MCP tool with resilient fallback handling.
Manages the lifecycle of n8n workflow execution: triggering via MCP,
polling n8n execution status, handling node failures, and applying
fallback strategies when primary execution paths fail.
"""
tool_name = selected_tool["tool_name"]
workflow_id = selected_tool["workflow_id"]
mapped_params = selected_tool["mapped_params"]
for attempt in range(max_retries + 1):
try:
# Trigger n8n workflow via MCP tool call
execution_id = mcp_client.call_tool(
tool_name,
{"workflow_id": workflow_id, "parameters": mapped_params}
)
# Poll n8n execution status until completion or timeout
result = _poll_n8n_execution(n8n_api_client, execution_id, timeout=120)
return {
"status": "success",
"execution_id": execution_id,
"result": result,
"attempts": attempt + 1,
"latency_ms": time.time() * 1000
}
except n8n.NodeExecutionError as e:
# Fail fast on invalid node state or missing credentials
raise ExecutionError(f"n8n node failed at attempt {attempt + 1}: {e}") from e
except MCPConnectionError as e:
# Transient MCP/n8n API issue - retry or fallback
if attempt == max_retries:
return _fallback_to_alternative_workflow(workflow_id, mapped_params)
raise ExecutionError(f"Exhausted {max_retries + 1} attempts for {tool_name}")
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
| Skill | Purpose | |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.