mirror of https://github.com/dapr/dapr-agents.git
Fix: Return the content if hasattr(result, 'content') && hasattr(content, 'text') to reiterate from the model (#84)
* Fix: Return the content if hasattr(result, 'content') && hasattr(content, 'text') to reiterate from the model Signed-off-by: Casper Guldbech Nielsen <scni@novonordisk.com> * Remove the set on error_message as it is not returned Signed-off-by: Casper Guldbech Nielsen <scni@novonordisk.com> * Fix: Change the order of the if statements to ensure the return of the content text before raising error Signed-off-by: Casper Guldbech Nielsen <scni@novonordisk.com> * Simplify the if conditions and remove unnecessary code Signed-off-by: Casper Guldbech Nielsen <scni@novonordisk.com> * Add mcp==1.6.0 to requirements as the mcp client needs it Signed-off-by: Casper Guldbech Nielsen <scni@novonordisk.com> --------- Signed-off-by: Casper Guldbech Nielsen <scni@novonordisk.com>
This commit is contained in:
parent
c872c5a8bd
commit
62d4cdbe02
|
@ -355,28 +355,22 @@ class MCPClient(BaseModel):
|
|||
Raises:
|
||||
ToolError: If the result indicates an error
|
||||
"""
|
||||
# Handle error result
|
||||
if hasattr(result, 'isError') and result.isError:
|
||||
error_message = "Unknown error"
|
||||
if hasattr(result, 'content') and result.content:
|
||||
for content in result.content:
|
||||
if hasattr(content, 'text'):
|
||||
error_message = content.text
|
||||
break
|
||||
raise ToolError(f"MCP tool error: {error_message}")
|
||||
|
||||
# Extract text content from result
|
||||
if hasattr(result, 'content') and result.content:
|
||||
text_contents = []
|
||||
for content in result.content:
|
||||
if hasattr(content, 'text'):
|
||||
text_contents.append(content.text)
|
||||
|
||||
|
||||
# Return single string if only one content item
|
||||
if len(text_contents) == 1:
|
||||
return text_contents[0]
|
||||
elif text_contents:
|
||||
return text_contents
|
||||
|
||||
if hasattr(result, 'isError') and result.isError:
|
||||
# This will only trigger if the above if didn't contain content.text
|
||||
raise ToolError(f"MCP tool error: {result}")
|
||||
|
||||
# Fallback for unexpected formats
|
||||
return str(result)
|
||||
|
|
|
@ -13,4 +13,5 @@ cloudevents==1.11.0
|
|||
pyyaml==6.0.2
|
||||
rich==13.9.4
|
||||
huggingface_hub==0.27.1
|
||||
numpy==2.2.2
|
||||
numpy==2.2.2
|
||||
mcp==1.6.0
|
Loading…
Reference in New Issue