Skip to content

Commit ec12ad0

Browse files
authored
fix: MCP node display nesting issue (#3822)
1 parent f61a567 commit ec12ad0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,25 @@
3333
<strong>Called MCP Tool: <em>%s</em></strong>
3434
</summary>
3535
36-
```json
3736
%s
38-
```
37+
3938
</details>
4039
4140
"""
4241

42+
tool_message_json_template = """
43+
```json
44+
%s
45+
```
46+
"""
47+
48+
49+
def generate_tool_message_template(name, context):
50+
if '```' in context:
51+
return tool_message_template % (name, context)
52+
else:
53+
return tool_message_template % (name, tool_message_json_template % (context))
54+
4355

4456
def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow, answer: str,
4557
reasoning_content: str):
@@ -110,7 +122,7 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers):
110122
response = agent.astream({"messages": message_list}, stream_mode='messages')
111123
async for chunk in response:
112124
if isinstance(chunk[0], ToolMessage):
113-
content = tool_message_template % (chunk[0].name, chunk[0].content)
125+
content = generate_tool_message_template(chunk[0].name, chunk[0].content)
114126
chunk[0].content = content
115127
yield chunk[0]
116128
if isinstance(chunk[0], AIMessageChunk):

0 commit comments

Comments
 (0)