Flatten an MCP result's content blocks to the str ToolResult.output.
(content: Any)
| 34 | |
| 35 | |
| 36 | def _render_content(content: Any) -> str: |
| 37 | """Flatten an MCP result's content blocks to the str ToolResult.output.""" |
| 38 | if isinstance(content, str): |
| 39 | return content |
| 40 | if not content: |
| 41 | return "" |
| 42 | parts: list[str] = [] |
| 43 | for block in content: |
| 44 | if isinstance(block, dict): |
| 45 | if block.get("type") == "text": |
| 46 | parts.append(str(block.get("text", ""))) |
| 47 | else: |
| 48 | parts.append(str(block)) |
| 49 | else: |
| 50 | parts.append(str(block)) |
| 51 | return "\n".join(parts) |
| 52 | |
| 53 | |
| 54 | class McpRuntime: |