MCPcopy Create free account
hub / github.com/1rgs/claude-code-proxy / parse_tool_result_content

Function parse_tool_result_content

server.py:419–461  ·  view source on GitHub ↗

Helper function to properly parse and normalize tool result content.

(content)

Source from the content-addressed store, hash-verified

417
418
419def parse_tool_result_content(content):
420 """Helper function to properly parse and normalize tool result content."""
421 if content is None:
422 return "No content provided"
423
424 if isinstance(content, str):
425 return content
426
427 if isinstance(content, list):
428 result = ""
429 for item in content:
430 if isinstance(item, dict) and item.get("type") == "text":
431 result += item.get("text", "") + "\n"
432 elif isinstance(item, str):
433 result += item + "\n"
434 elif isinstance(item, dict):
435 if "text" in item:
436 result += item.get("text", "") + "\n"
437 else:
438 try:
439 result += json.dumps(item) + "\n"
440 except:
441 result += str(item) + "\n"
442 else:
443 try:
444 result += str(item) + "\n"
445 except:
446 result += "Unparseable content\n"
447 return result.strip()
448
449 if isinstance(content, dict):
450 if content.get("type") == "text":
451 return content.get("text", "")
452 try:
453 return json.dumps(content)
454 except:
455 return str(content)
456
457 # Fallback for any other type
458 try:
459 return str(content)
460 except:
461 return "Unparseable content"
462
463
464def convert_anthropic_to_litellm(anthropic_request: MessagesRequest) -> Dict[str, Any]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected