From 97fb4a5cea502260b8aa4ae3e3af964d16ee10a0 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Thu, 27 Mar 2025 16:46:36 +0800 Subject: [PATCH] fix: format MCP tool messages with detailed JSON representation --- .../ai_chat_step_node/impl/base_chat_node.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 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 f8927bf0a..c5a0de1a1 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 @@ -27,6 +27,18 @@ from setting.models import Model from setting.models_provider import get_model_credential from setting.models_provider.tools import get_model_instance_by_model_user_id +tool_message_template = """ +
+ + Called MCP Tool: %s + + +```json +%s +``` +
+ +""" def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow, answer: str, reasoning_content: str): @@ -96,8 +108,10 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers): agent = create_react_agent(chat_model, client.get_tools()) response = agent.astream({"messages": message_list}, stream_mode='messages') async for chunk in response: - # if isinstance(chunk[0], ToolMessage): - # print(chunk[0]) + if isinstance(chunk[0], ToolMessage): + content = tool_message_template % (chunk[0].name, chunk[0].content) + chunk[0].content = content + yield chunk[0] if isinstance(chunk[0], AIMessageChunk): yield chunk[0]