Node-RED AI代理桥接工具

将MCP协议与Node-RED集成的开源工具,支持通过可视化流程构建AI代理,实现工业自动化和物联网场景中的智能决策。

  • by TobiasLante
  • JavaScript
  • 本地部署
  • 14 星标
  • 更新于
在 GitHub 查看 TobiasLante/node-red-contrib-mcp

使用说明

node-red-contrib-mcp

The bridge between Node-RED and AI agents

Install · Quick Start · Nodes · AI Agent · Examples



Multi-phase OEE analysis agent built with MCP tool nodes in Node-RED

主控程序 (模型上下文协议)是Anthropic为将人工智能连接到外部工具和数据而制定的开放标准。 此包将MCP带到Node-RED --全球最受欢迎的工业自动化和物联网低代码平台。

4M+节点RED安装 遇见 10000多台MCP服务器。 直观地构建AI代理。无需代码。


特性

  • 任何MCP服务器 --可流式传输HTTP和SSE,带可选身份验证
  • 任何 LLM -OpenAI、Anthropic、Ollama、vLLM、Azure、Gemini或任何与OpenAI兼容的API
  • AI代理节点 --全代理循环(工具发现→ LLM推理→ 工具执行→ 重复)
  • 零锁定 --Apache-2.0许可证,无云依赖,完全本地运行
  • 生产就绪 --错误处理、状态指示器、可配置超时
  • 节点RED原生 --配置节点、消息传递、调试面板集成

建筑

┌─────────────────────────────────────────────────────────────────┐
│  Node-RED                                                       │
│                                                                 │
│  [inject] → [mcp tool] → [llm call] → [mcp tool] → [debug]   │
│                                                                 │
│  [inject] → [ai agent] → [debug]    ← autonomous agent loop   │
│                                                                 │
└──────────┬──────────────────────────────────────┬───────────────┘
           │                                      │
           ▼                                      ▼
    ┌──────────────┐                      ┌──────────────┐
    │  MCP Server  │                      │   LLM API    │
    │  (any tool)  │                      │  (any model) │
    └──────────────┘                      └──────────────┘

安装

cd ~/.node-red
npm install node-red-contrib-mcp

或搜索 node-red-contrib-mcp 在调色板管理器中:

Menu → 管理调色板→ 安装→ node-red-contrib-mcp


节点

节点 描述
MCP服务器 配置 -MCP服务器连接(URL、传输、API密钥)
llm配置 配置 -LLM提供程序(基本URL、模型、API密钥)
mcp工具 调用任何MCP工具。将参数传递为 msg.payload,配置中的工具名称或 msg.topic
mcp工具 列出MCP服务器上的所有可用工具。非常适合发现和调试
mcp资源 读取MCP服务器公开的资源
llm呼叫 调用任何与OpenAI兼容的LLM。支持系统提示、JSON模式、多回合聊天
AI代理 自主代理 --LLM+MCP工具处于推理循环中,直到得到答案

快速开始

1.调用MCP工具

[inject {"machine": "CNC-001"}] → [mcp tool "get_oee"] → [debug]

2.LLM+MCP管道

[inject] → [mcp tool "get_data"] → [llm call "Summarize this"] → [debug]

3.AI Agent(魔法节点)

[inject "Why did OEE drop on machine 9014?"] → [ai agent] → [debug]

代理人 自主地 发现工具、调用原因,执行它们,并综合最终答案。与ChatGPT或Claude的模式相同,但具有可视性、可审计性和Node-RED。


AI 代理

这 ai agent node运行一个完整的代理推理循环:

User: "Why did OEE drop on machine 9014 last week?"

  ┌─── Agent Loop ──────────────────────────────────────────┐
  │                                                         │
  │  Step 1: LLM sees 91 tools, picks get_oee              │
  │          → calls MCP server → gets OEE data             │
  │                                                         │
  │  Step 2: LLM analyzes, picks get_downtime_events        │
  │          → calls MCP server → gets 3 events             │
  │                                                         │
  │  Step 3: LLM synthesizes final answer                   │
  │                                                         │
  └─────────────────────────────────────────────────────────┘

Agent: "OEE dropped from 85% to 62% due to 3 unplanned stops:
        bearing failure (47min), tool change delay (23min),
        and material shortage (18min)."

  msg.agentLog = [{tool: "get_oee", ...}, {tool: "get_downtime_events", ...}]
  msg.iterations = 3

代理设置

设置 默认值 说明
MCP服务器 -- 工具使用哪个MCP服务器
LLM -- 哪个LLM提供推理
系统提示 -- 代理个性和说明
最大循环次数 10 最大LLM↔ 工具迭代
温度 0.3 LLM创造力(0=专注,1=创造力)

例子

导入此流

复制下面的JSON,然后在Node-RED中: Menu → 导入→ Paste

Example: MCP Tool Call
[
  {
    "id": "mcp-demo-inject",
    "type": "inject",
    "name": "Trigger",
    "props": [{ "p": "payload" }],
    "payload": "{\"machine_id\": \"CNC-001\"}",
    "payloadType": "json",
    "wires": [["mcp-demo-tool"]],
    "x": 150,
    "y": 100
  },
  {
    "id": "mcp-demo-tool",
    "type": "mcp-tool-call",
    "name": "Get OEE",
    "server": "mcp-demo-server",
    "toolName": "get_oee",
    "wires": [["mcp-demo-debug"]],
    "x": 350,
    "y": 100
  },
  {
    "id": "mcp-demo-debug",
    "type": "debug",
    "name": "Result",
    "active": true,
    "x": 550,
    "y": 100
  },
  {
    "id": "mcp-demo-server",
    "type": "mcp-server-config",
    "name": "My MCP Server",
    "url": "http://localhost:8021/mcp",
    "transportType": "http"
  }
]
Example: AI Agent
[
  {
    "id": "agent-demo-inject",
    "type": "inject",
    "name": "Ask question",
    "props": [{ "p": "payload" }],
    "payload": "What is the current OEE of machine CNC-001 and what are the main loss factors?",
    "payloadType": "str",
    "wires": [["agent-demo-agent"]],
    "x": 170,
    "y": 100
  },
  {
    "id": "agent-demo-agent",
    "type": "ai-agent",
    "name": "Factory Agent",
    "server": "agent-demo-mcp",
    "llmConfig": "agent-demo-llm",
    "systemPrompt": "You are a manufacturing AI assistant. Use the available MCP tools to answer questions about factory operations. Be precise and cite specific numbers.",
    "maxIterations": 10,
    "temperature": 0.3,
    "maxTokens": 4096,
    "wires": [["agent-demo-debug"]],
    "x": 400,
    "y": 100
  },
  {
    "id": "agent-demo-debug",
    "type": "debug",
    "name": "Agent Response",
    "active": true,
    "x": 620,
    "y": 100
  },
  {
    "id": "agent-demo-mcp",
    "type": "mcp-server-config",
    "name": "Factory MCP",
    "url": "http://localhost:8024/mcp",
    "transportType": "http"
  },
  {
    "id": "agent-demo-llm",
    "type": "llm-config",
    "name": "OpenAI",
    "baseUrl": "https://api.openai.com/v1",
    "model": "gpt-4o"
  }
]
Example: MQTT → AI Agent → MQTT (IIoT)
[
  {
    "id": "mqtt-in",
    "type": "mqtt in",
    "name": "machine/alerts",
    "topic": "machine/+/alert",
    "broker": "mqtt-broker",
    "wires": [["mqtt-agent"]],
    "x": 150,
    "y": 100
  },
  {
    "id": "mqtt-agent",
    "type": "ai-agent",
    "name": "Alert Agent",
    "server": "mqtt-mcp-server",
    "llmConfig": "mqtt-llm",
    "systemPrompt": "You are an industrial AI agent. When you receive a machine alert, investigate using MCP tools and recommend an action. Be concise.",
    "maxIterations": 5,
    "wires": [["mqtt-out"]],
    "x": 380,
    "y": 100
  },
  {
    "id": "mqtt-out",
    "type": "mqtt out",
    "name": "machine/actions",
    "topic": "machine/actions",
    "broker": "mqtt-broker",
    "x": 600,
    "y": 100
  }
]

MQTT警报进入→ AI代理通过MCP工具进行调查→ 操作通过MQTT发出。


兼容

MCP服务器

使用 任何MCP服务器 支持流式HTTP或SSE传输:

  • OpenShopFloor --111种制造MCP工具(ERP、OEE、QMS、TMS、UNS、KG)
  • Anthropic MCP服务器 --文件系统、GitHub、PostgreSQL、Slack、谷歌云端硬盘。..
  • 您构建的任何自定义MCP服务器

大语言模型提供商

使用 任何与OpenAI兼容的API:

提供者 基本URL
OpenAI https://api.openai.com/v1
Ollama(当地) http://localhost:11434/v1
Azure OpenAI https://YOUR.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT/v1
vLLM http://localhost:8000/v1
文学硕士 http://localhost:4000/v1
LM工作室 http://localhost:1234/v1
Anthropic 通过LiteLLM代理

msg参考

mcp工具调用

方向 属性 类型 描述
输入 msg.payload object 工具参数
输入 msg.topic string 工具名称(如果未在配置中设置)
输出 msg.payload 任意 工具结果(自动解析的JSON)
输出 msg.mcpResult object 原始MCP响应

人工智能代理

方向 属性 类型 描述
输入 msg.payload string 用户问题或任务
输出 msg.payload string 代理的最终答案
输出 msg.agentLog 阵列 [{tool, args, result}] 每次通话
输出 msg.iterations number LLM推理步骤总数

llm呼叫

方向 属性 类型 描述
输入 msg.payload string 用户消息
输入 msg.messages array 上一次对话(多回合)
输入 msg.tools array OpenAI格式工具定义
输出 msg.payload string LLM响应文本
输出 msg.toolCalls array 工具调用(如果有)
输出 msg.usage object 令牌使用统计信息

配置

MCP服务器(配置节点)

字段 描述 示例
统一资源定位符 MCP服务器端点 http://localhost:3001/mcp
运输 协议变体 Streamable HTTP (默认)或 SSE
API密钥 可选不记名代币 sk-...

LLM提供程序(配置节点)

字段 描述 示例
基础URL OpenAI兼容端点 https://api.openai.com/v1
模型 型号标识符 gpt-4o
API密钥 您的API密钥 sk-...

用例

域名 您可以构建什么
制造 OEE监控、容量规划、预测性维护、质量根本原因分析
工业物联网 MQTT→ AI 代理→ MQTT管道、传感器数据分析、异常检测
楼宇自动化 智能能源管理,BACnet/Modbus+AI推理
IT/DevOps 数据库代理、日志分析、自动事件响应
原型设计 实现代理人工智能原型的最快方法——Node-RED中的可视化调试

需求

  • 节点红色>=3.0.0
  • Node.js>=18.0.0
  • 要连接的MCP服务器
  • LLM API密钥(用于 llm-call 和 ai-agent 节点)

贡献

问题和PR欢迎! github/巴伐利亚分析/节点审查控制mcp

许可证

阿帕奇-2.0 --无论在商业上还是非商业上,都可以在任何地方使用它。


Built by OpenShopFloor — the open-source AI platform for factory operations

Live Demo · GitHub · Node-RED Flow Library