diff --git a/ms_agent/llm/utils.py b/ms_agent/llm/utils.py index 71bf745ad..6a336ca6e 100644 --- a/ms_agent/llm/utils.py +++ b/ms_agent/llm/utils.py @@ -47,8 +47,8 @@ class Message: partial: bool = False prefix: bool = False - # code block - resources: List[str] = field(default_factory=list) + # UI resources from mcp result + resources: List[Dict[str, str]] = field(default_factory=list) # usage completion_tokens: int = 0 diff --git a/ms_agent/tools/mcp_client.py b/ms_agent/tools/mcp_client.py index b868c7f7d..d6b971fbb 100644 --- a/ms_agent/tools/mcp_client.py +++ b/ms_agent/tools/mcp_client.py @@ -79,8 +79,10 @@ async def call_tool(self, server_name: str, tool_name: str, if content.type == 'text': texts.append(content.text) elif content.type == 'resource': - texts.append(str(content.resource)) - resources.append(str(content.resource)) + import json5 + json_str = content.resource.model_dump_json(by_alias=True) + texts.append(json_str) + resources.append(json5.loads(json_str)) if resources: return {'text': '\n\n'.join(texts), 'resources': resources}