File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 117117![ 集成示例] ( img/maxkb_effect.png )
118118
119119### 3.2 Dify 集成示例
120+ !!! Tip ""
121+ 步骤⼀: 进入需要配置的工作空间,创建或进入一个 Chatflow 类型的应用。
122+
123+ 步骤二: 添加输入节点在,节点中定义输入变量: username(必填) 、password(必填)
124+
125+ 步骤三: 添加条件判断,在开始节点后添加条件分支(IF)。判断条件:access_token 是否为空。为空:执行登录逻辑,调用 MCP 工具 mcp_start。
126+
127+ 配置 MCP 工具参数(以 mcp_start 为例):
128+
129+ - 输入参数:
130+ ```
131+ {
132+ "username": "{{username}}",
133+ "password": "{{password}}"
134+ }
135+
136+ ```
137+ - MCP 服务配置:
138+ ```
139+ {
140+ "sqlbot_mcp": {
141+ "uri": "http://<SQLBot_MCP_IP>:8001/mcp",
142+ "transport": "sse"
143+ }
144+ }
145+ ```
146+ - MCP 工具返回包含 chat_id 和 access_token 的 JSON。解析返回值,添加 代码执行 节点(Python)来解析 JSON:
147+ ```
148+ import json
149+
150+ def main(arg1: str) -> dict:
151+ json_obj = json.loads(arg1)
152+ return {
153+ "chat_id": json_obj["data"]["chat_id"],
154+ "access_token": json_obj["data"]["access_token"]
155+ }
156+
157+ ```
158+ 添加变量赋值节点,将 chat_id 和 access_token 存储为全局变量,供后续 MCP 调用使用。
159+
160+ - 执行后续 MCP 业务调用
161+
162+ ```
163+ {
164+ "sqlbot_mcp": {
165+ "uri": "http://<SQLBot_MCP_IP>:8001/mcp",
166+ "transport": "sse"
167+ }
168+ }
169+ ```
170+ 步骤四:在流程末尾添加回答节点,将 MCP 返回的内容回复给用户。输入有效的 username 与 password 测试登录及 MCP 功能调用是否正常。
171+
172+
120173![ 集成示例] ( img/dify_mcp.png )
121174
122175![ 集成示例] ( img/dify_mcp_effect.png )
You can’t perform that action at this time.
0 commit comments