From ec12ad0c2e0aed17bb949b23eb3daa049e12f8ae Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Tue, 5 Aug 2025 19:23:48 +0800 Subject: [PATCH] fix: MCP node display nesting issue (#3822) --- .../ai_chat_step_node/impl/base_chat_node.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py index 8f14f1386..b8607cf5d 100644 --- a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py +++ b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py @@ -33,13 +33,25 @@ tool_message_template = """ Called MCP Tool: %s -```json %s -``` + """ +tool_message_json_template = """ +```json +%s +``` +""" + + +def generate_tool_message_template(name, context): + if '```' in context: + return tool_message_template % (name, context) + else: + return tool_message_template % (name, tool_message_json_template % (context)) + def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow, answer: str, reasoning_content: str): @@ -110,7 +122,7 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers): response = agent.astream({"messages": message_list}, stream_mode='messages') async for chunk in response: if isinstance(chunk[0], ToolMessage): - content = tool_message_template % (chunk[0].name, chunk[0].content) + content = generate_tool_message_template(chunk[0].name, chunk[0].content) chunk[0].content = content yield chunk[0] if isinstance(chunk[0], AIMessageChunk):