基于模型上下文协议(MCP)服务器的可视化工作流编排工具
GoFlow 允许开发者将多个 MCP 工具无缝链接成复杂的、可重用的工作流,包含条件逻辑、数据转换和并行执行等功能——所有这些都不需要编写代码。
从源码构建(预发布版 - 尚无二进制文件)
git clone https://github.com/dshills/goflow.git
cd goflow
go build -o goflow ./cmd/goflow
# 可选:安装到系统路径
sudo mv goflow /usr/local/bin/
需求:Go 1.21 或更高版本
创建一个简单的读取-转换-写入管道:
# 1. 注册一个 MCP 服务器
goflow server add filesystem npx -y @modelcontextprotocol/server-filesystem /tmp
# 2. 创建测试数据
echo '{"data": [{"price": 10.5}, {"price": 20.3}, {"price": 5.2}]}' > /tmp/input.json
# 3. 复制示例工作流
cp examples/simple-pipeline.yaml ~/.goflow/workflows/data-pipeline.yaml
# 4. 运行工作流
goflow run data-pipeline
# 5. 检查输出
cat /tmp/output.txt
# 输出:Total: 36.0
结果:GoFlow 读取了 JSON 文件,计算了价格总和(36.0),并将结果写入文本文件——这一切都是通过文件系统 MCP 服务器编排完成的!
模型上下文协议(MCP)服务器是强大的 AI 辅助开发工具,但它们独立运行。构建复杂自动化需要:
GoFlow 提供:
工作流是由节点和边组成的有向无环图(DAG)。每个节点执行特定操作,边定义执行顺序。
version: "1.0"
name: "my-workflow"
description: "此工作流的作用"
variables:
- name: "input_file"
type: "string"
default: "/tmp/data.json"
servers:
- id: "filesystem"
command: "npx"
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
nodes:
- id: "start"
type: "start"
- id: "read"
type: "mcp_tool"
server: "filesystem"
tool: "read_file"
parameters:
path: "${input_file}"
output: "contents"
- id: "end"
type: "end"
return: "${contents}"
edges:
- from: "start"
to: "read"
- from: "read"
to: "end"
| 类型 | 目的 | 示例用例 |
|---|---|---|
| start | 工作流入口点 | 始终需要 |
| end | 工作流出口点 | 返回最终结果 |
| mcp_tool | 调用 MCP 服务器工具 | 读取文件,发起 API 调用 |
| transform | 数据转换 | 提取字段,计算值 |
| condition | 条件分支 | 根据数据路由 |
| loop | 集合迭代 | 处理多个项 |
| parallel | 并发执行 | 并行处理文件 |
变量存储工作流状态并在节点间传递数据:
variables:
- name: "threshold"
type: "number"
default: 100
nodes:
- id: "check"
type: "condition"
condition: "${value} > ${threshold}"
MCP 服务器为工作流节点提供工具:
servers:
- id: "filesystem"
command: "npx"
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
- id: "http"
command: "npx"
args: ["-y", "@modelcontextprotocol/server-fetch"]
读取 JSON,转换数据,写入输出:
# 参见:examples/simple-pipeline.yaml
version: "1.0"
name: "data-pipeline"
nodes:
- id: "read"
type: "mcp_tool"
tool: "read_file"
output: "data"
- id: "transform"
type: "transform"
input: "${data}"
expression: "jq(.data | map(.price) | add)"
output: "total"
- id: "write"
type: "mcp_tool"
tool: "write_file"
parameters:
content: "Total: ${total}"
根据数据路由执行:
# 参见:examples/conditional-workflow.yaml
nodes:
- id: "check_size"
type: "condition"
condition: "${file_size} > 1000000"
edges:
- from: "check_size"
to: "compress"
condition: "true"
label: "大文件"
- from: "check_size"
to: "upload"
condition: "false"
label: "小文件"
带有指数退避的重试:
# 参见:examples/error-handling.yaml
nodes:
- id: "fetch_api"
type: "mcp_tool"
tool: "http_get"
retry:
max_attempts: 3
backoff: "exponential"
initial_delay: "1s"
on: ["connection_error", "timeout"]
并发处理多个项:
# 参见:examples/parallel-batch.yaml
nodes:
- id: "process_batch"
type: "parallel"
branches:
- ["read_file1", "transform1", "write1"]
- ["read_file2", "transform2", "write2"]
- ["read_file3", "transform3", "write3"]
merge_strategy: "wait_all"
max_parallel: 10
更多示例在 examples/ 目录中。
# 初始化新工作流
goflow init <工作流名称>
# 验证工作流
goflow validate <工作流名称>
# 执行工作流
goflow run <工作流名称> [选项]
# 打开视觉编辑器
goflow edit <工作流名称>
# 列出所有工作流
goflow list
# 导出工作流(可分享)
goflow export <工作流名称>
# 导入工作流
goflow import <文件.yaml>
# 添加 MCP 服务器
goflow server add <服务器ID> <命令> [参数...]
# 列出已注册的服务器
goflow server list
# 测试服务器连接
goflow server test <服务器ID>
# 移除服务器
goflow server remove <服务器ID>
# 列出执行
goflow executions [--workflow <名称>]
# 查看执行详情
goflow execution <执行ID>
# 查看执行日志
goflow logs <执行ID>
完整 CLI 参考:快速入门指南
启动交互式终端用户界面:
# 创建或编辑现有工作流
goflow edit <工作流名称>
# 从模板开始
goflow edit <工作流名称> --template etl
视觉工作流编辑器是一个功能齐全的终端用户界面,用于无需编写 YAML 的工作流构建、编辑和验证。它提供了:
? 键的上下文敏感帮助1. 添加节点
按 a 打开节点调色板:
┌─── 添加节点 ────────────────────┐
│ │
│ 搜索: [_________________] │
│ │
│ ► 🔧 MCP 工具 │
│ 执行 MCP 服务器工具 │
│ │
│ 🔄 转换 │
│ 使用 JSONPath、模板或 jq 转换数据 │
│ │
│ ❓ 条件 │
│ 条件分支 │
│ │
│ [Enter: 选择] [Esc: 取消] │
└──────────────────────────────────┘
↓↑ 或 jk 导航"trans" → 显示转换Enter 将节点添加到画布2. 编辑节点属性
选择一个节点并按 e 编辑:
┌─── 编辑节点: tool-1 ───────────┐
│ │
│ ► 名称: [tool-1______________] │
│ 服务器ID: [filesystem_____] │
│ 工具名称: [read_file______] │
│ 路径: [/tmp/data.json______] │
│ │
│ [Tab: 下一个] [Enter: 保存] │
│ [Esc: 取消] │
└──────────────────────────────────┘
Tab/Shift+Tab 在字段间导航Enter 保存,Esc 取消3. 连接节点
按 c 开始边创建模式:
Enter 确认源节点Enter 创建边画布会自动使用正交(曼哈顿)布局路由边。
4. 验证工作流
按 v 运行验证:
┌─── 验证错误 (2) ───────┐
│ │
│ ► ❌ 节点 'tool-1': 必填字段 '工具名称' 缺失 │
│ │
│ ⚠️ 节点 'transform-2': 未连接节点 │
│ │
│ [Enter: 导航] [Esc: 关闭] │
└──────────────────────────────────┘
Enter 在错误上导航至有问题的节点5. 保存工作流
按 s 将更改保存到磁盘。修改过的工作流会在状态栏显示 *。
节点操作:
a:添加节点(打开调色板)e:编辑所选节点属性d:删除所选节点c:创建边(连接节点)x:删除所选边画布导航:
hjkl 或 ↑↓←→:平移画布(滚动)+/=:放大-:缩小0:重置缩放至 1.0xf:适应所有节点r:重置视图(中心于起始节点)工作流操作:
s:保存工作流v:验证工作流u:撤销上次操作Ctrl+r:重做操作视图切换:
?:切换帮助面板V:切换验证面板(大写字母 V)应用程序:
q:退出(如有修改会提示)Esc:取消当前操作Tab:下一个字段Shift+Tab:上一个字段Enter:保存更改Esc:取消编辑↓↑ 或 jk:导航节点类型/:聚焦搜索字段Enter:选择节点类型Esc:取消↓↑ 或 jk:滚动帮助文本Esc 或 ?:关闭帮助执行已注册 MCP 服务器中的工具。
必填字段:
名称:节点标识符服务器ID:已注册的 MCP 服务器工具名称:要执行的工具示例:从文件系统服务器读取文件
使用 JSONPath、jq 样式或模板表达式转换数据。
必填字段:
名称:节点标识符类型:jsonpath、jq 或 template表达式:转换表达式输入:源变量输出:目标变量示例:从 JSON 中提取电子邮件:$.user.email
根据布尔表达式分支执行。
必填字段:
名称:节点标识符表达式:布尔条件(例如,${count > 10})注意:条件节点必须有恰好两个出边(真/假路径)
遍历集合。
必填字段:
名称:节点标识符集合:包含数组的变量(例如,${items})变量:循环变量名(例如,item)注意:循环体节点连接在一个子图中
并发执行多个分支。
必填字段:
名称:节点标识符分支数:并行分支数量合并策略:wait_all、wait_any 或 race可选返回值的出口点。
必填字段:
名称:节点标识符输出:要返回的变量(可选)画布使用分层自动布局算法(Sugiyama 框架),在加载没有位置元数据的工作流时自动定位节点。
手动定位:
视觉反馈:
编辑器实时验证工作流:
结构:
节点特定: