MCPcopy Create free account
hub / github.com/IBM/mcp-cli / _parse_content_repr

Method _parse_content_repr

src/mcp_cli/chat/tool_processor.py:1365–1381  ·  view source on GitHub ↗

Parse a string like "content=[{'type': 'text', 'text': '4.2426'}]".

(self, repr_str: str)

Source from the content-addressed store, hash-verified

1363 return self._try_parse_number(combined)
1364
1365 def _parse_content_repr(self, repr_str: str) -> Any:
1366 """Parse a string like "content=[{'type': 'text', 'text': '4.2426'}]"."""
1367 import re
1368
1369 # Try to extract the text value using regex
1370 match = re.search(r"'text':\s*'([^']*)'", repr_str)
1371 if match:
1372 text = match.group(1)
1373 return self._try_parse_number(text)
1374
1375 # Try another pattern for double quotes
1376 match = re.search(r'"text":\s*"([^"]*)"', repr_str)
1377 if match:
1378 text = match.group(1)
1379 return self._try_parse_number(text)
1380
1381 return repr_str
1382
1383 def _try_parse_number(self, text: str) -> Any:
1384 """Try to parse a string as a number, return original if not possible."""

Callers 5

_extract_result_valueMethod · 0.95
test_single_quotesMethod · 0.80
test_double_quotesMethod · 0.80
test_no_matchMethod · 0.80
test_non_numeric_textMethod · 0.80

Calls 1

_try_parse_numberMethod · 0.95

Tested by 4

test_single_quotesMethod · 0.64
test_double_quotesMethod · 0.64
test_no_matchMethod · 0.64
test_non_numeric_textMethod · 0.64