RuleGo RuleGo
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 流式计算
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • 🌊StreamSQL
  • 🤖智能体框架
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 流式计算
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • 🌊StreamSQL
  • 🤖智能体框架
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • 快速入门

  • 规则链

  • 标准组件

  • 扩展组件

    • 扩展组件概述
    • 过滤器

    • 动作

    • 转换器

    • 外部的

    • ai

      • 智能体

      • 组件

        • 智能体
        • LLM
        • 图像生成
        • 意图识别
        • 本地意图识别
        • MCP 客户端
          • 双重角色
          • 配置
          • 执行结果
          • 配置示例
            • 直接调用远程工具
            • 动态工具名(从消息元数据获取)
            • Stdio 模式(本地进程)
            • 作为智能体的工具提供者
          • 应用示例
        • MCP 服务端
    • CI

    • IoT

    • 流式计算

    • 文件

  • 自定义组件

  • 组件市场

  • 可视化

  • AOP

  • 触发器

  • 高级主题

  • RuleGo-Server

  • 问题

目录

MCP 客户端

x/mcpClient 组件:v0.36.0+ MCP(Model Context Protocol)客户端节点,连接远程 MCP 服务器并调用指定工具,将结果写入消息体传递给下游节点。同时可作为 MCPToolProvider 注册到 RuleConfig UDF,供 ai/agent 智能体的 self 模式调用远程工具。

# 双重角色

MCP 客户端在规则链中有两种使用方式:

  1. 直接调用模式:作为规则链节点,在 OnMsg 时调用指定的远程 MCP 工具
  2. 工具提供者模式:启动时自动发现远程 MCP 服务器的全部工具,注册为 MCPToolProvider,供智能体的 MCP 工具(server: "self")调用

# 配置

字段 类型 说明 默认值
server string MCP 服务器地址。支持 HTTP URL(http:///https://)和 stdio 命令 必填
toolName string 调用的远程工具名称。支持 ${metadata.xxx} ${msg.xxx} 表达式。为空时从 metadata.mcpToolName 获取
args string 工具参数 JSON 模板。支持 ${msg.xxx} ${metadata.xxx} 表达式。为空时使用消息体 JSON
toolFilter []string 工具过滤器(仅影响 MCPToolProvider 注册),空或 ["*"] 表示注册全部工具

# 执行结果

  • 工具调用结果写入 msg.Data,通过 Success 连接类型传递给下游节点
  • 调用失败时通过 Failure 连接类型传递错误信息

# 配置示例

# 直接调用远程工具

{
  "id": "s1",
  "type": "x/mcpClient",
  "name": "获取天气",
  "configuration": {
    "server": "http://localhost:8080/mcp",
    "toolName": "get_weather",
    "args": "{\"city\": \"${msg.city}\", \"unit\": \"celsius\"}"
  }
}
1
2
3
4
5
6
7
8
9
10

# 动态工具名(从消息元数据获取)

{
  "id": "s1",
  "type": "x/mcpClient",
  "name": "MCP工具调用",
  "configuration": {
    "server": "http://localhost:8080/mcp",
    "toolName": "${metadata.mcpToolName}",
    "args": ""
  }
}
1
2
3
4
5
6
7
8
9
10

toolName 为空时,组件从 msg.Metadata["mcpToolName"] 获取工具名。args 为空时,使用 msg.Data 的 JSON 作为工具参数。

# Stdio 模式(本地进程)

{
  "id": "s1",
  "type": "x/mcpClient",
  "name": "本地MCP工具",
  "configuration": {
    "server": "mcp-server --port 8080",
    "toolName": "search",
    "args": "{\"query\": \"${msg.query}\"}"
  }
}
1
2
3
4
5
6
7
8
9
10

当 server 不是 HTTP URL 时,组件将其解析为命令行,通过 stdio 传输与 MCP 服务通信。

# 作为智能体的工具提供者

MCP 客户端启动时(Start())自动连接远程服务器、发现工具并注册为 MCPToolProvider。在规则链中配置后,智能体可以通过 self 模式使用这些远程工具:

{
  "tools": [
    {
      "type": "mcp",
      "config": {
        "server": "self",
        "tools": ["get_weather", "search"]
      }
    }
  ]
}
1
2
3
4
5
6
7
8
9
10
11

toolFilter 可控制注册哪些工具到 MCPToolProvider:

{
  "toolFilter": ["get_weather", "search"]
}
1
2
3

# 应用示例

{
  "ruleChain": {
    "id": "mcp-demo",
    "name": "MCP调用示例",
    "root": true
  },
  "metadata": {
    "firstNodeIndex": 0,
    "nodes": [
      {
        "id": "node_mcp",
        "type": "x/mcpClient",
        "name": "调用远程工具",
        "configuration": {
          "server": "http://localhost:8080/mcp",
          "toolName": "get_weather",
          "args": "{\"city\": \"${msg.city}\"}"
        }
      },
      {
        "id": "node_log",
        "type": "log",
        "name": "记录结果",
        "configuration": {
          "jsScript": "return 'Weather result: ' + msg.data;"
        }
      }
    ],
    "connections": [
      {"fromId": "node_mcp", "toId": "node_log", "type": "Success"}
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
在 GitHub 上编辑此页 (opens new window)
上次更新: 2026/05/28, 01:50:04
本地意图识别
MCP 服务端

← 本地意图识别 MCP 服务端→

Theme by Vdoing | Copyright © 2023-2026 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式