Return type standardization

This commit is contained in:
2026-07-27 00:35:20 -07:00
parent baa48d7cec
commit f0e5267828
8 changed files with 47 additions and 48 deletions
+3 -13
View File
@@ -42,24 +42,14 @@ class MCPServer:
)
try:
result_data = await tool.handler(args)
content = await tool.handler(args)
except ToolError as e:
# Convert tool errors into a text response so the LLM can understand and potentially fix the input
result_data = {"text": str(e)}
content = [{"type": "text", "text": str(e)}]
except Exception as e:
# Catch-all for unexpected crashes to prevent server death
result_data = {"text": f"Unexpected internal error: {str(e)}"}
content = [{"type": "text", "text": f"Unexpected internal error: {str(e)}"}]
# Handle results that are already lists of content (for multimodal/multi-part responses)
if isinstance(result_data, list):
content = result_data
elif isinstance(result_data, dict) and "text" in result_data:
content = [{"type": "text", "text": result_data["text"]}]
elif isinstance(result_data, dict) and result_data.get("type") == "image":
content = [result_data]
else:
content = [result_data]
return {"content": content}
return Response(