Skip to content

Commit 97fb4a5

Browse files
committed
fix: format MCP tool messages with detailed JSON representation
1 parent 80cd3ff commit 97fb4a5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
from setting.models_provider import get_model_credential
2828
from setting.models_provider.tools import get_model_instance_by_model_user_id
2929

30+
tool_message_template = """
31+
<details>
32+
<summary>
33+
<strong>Called MCP Tool: <em>%s</em></strong>
34+
</summary>
35+
36+
```json
37+
%s
38+
```
39+
</details>
40+
41+
"""
3042

3143
def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow, answer: str,
3244
reasoning_content: str):
@@ -96,8 +108,10 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers):
96108
agent = create_react_agent(chat_model, client.get_tools())
97109
response = agent.astream({"messages": message_list}, stream_mode='messages')
98110
async for chunk in response:
99-
# if isinstance(chunk[0], ToolMessage):
100-
# print(chunk[0])
111+
if isinstance(chunk[0], ToolMessage):
112+
content = tool_message_template % (chunk[0].name, chunk[0].content)
113+
chunk[0].content = content
114+
yield chunk[0]
101115
if isinstance(chunk[0], AIMessageChunk):
102116
yield chunk[0]
103117

0 commit comments

Comments
 (0)