Return the first content block that parses as JSON, else content[0].
(resp)
| 220 | # ---------------------------------------------------------------------------- helpers |
| 221 | |
| 222 | def text_of(resp) -> str | None: |
| 223 | """Return the first content block that parses as JSON, else content[0].""" |
| 224 | if not isinstance(resp, dict): |
| 225 | return None |
| 226 | res = resp.get("result") |
| 227 | if not isinstance(res, dict): |
| 228 | return None |
| 229 | content = res.get("content") or [] |
| 230 | for block in content: |
| 231 | t = block.get("text", "") |
| 232 | try: |
| 233 | json.loads(t) |
| 234 | return t |
| 235 | except Exception: |
| 236 | continue |
| 237 | return content[0].get("text") if content else None |
| 238 | |
| 239 | |
| 240 | def discover(cli: McpClient) -> dict: |