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

Function _parse_tool_call_entry

src/mcp_cli/planning/executor.py:1014–1039  ·  view source on GitHub ↗

Parse a single tool call entry from either dict or object format. Args: tc: A tool call entry (dict or object with function attribute). Returns: Dict with 'name' and 'args', or None if parsing fails.

(tc: Any)

Source from the content-addressed store, hash-verified

1012
1013
1014def _parse_tool_call_entry(tc: Any) -> dict[str, Any] | None:
1015 """Parse a single tool call entry from either dict or object format.
1016
1017 Args:
1018 tc: A tool call entry (dict or object with function attribute).
1019
1020 Returns:
1021 Dict with 'name' and 'args', or None if parsing fails.
1022 """
1023 if isinstance(tc, dict):
1024 func = tc.get("function", {})
1025 name = func.get("name", "")
1026 args_str = func.get("arguments", "{}")
1027 elif hasattr(tc, "function"):
1028 func = tc.function
1029 name = getattr(func, "name", "")
1030 args_str = getattr(func, "arguments", "{}")
1031 else:
1032 return None
1033
1034 try:
1035 args = json.loads(args_str) if isinstance(args_str, str) else args_str
1036 except (json.JSONDecodeError, TypeError):
1037 args = {}
1038
1039 return {"name": name, "args": args} if name else None
1040
1041
1042def _summarize_variables(var_context: dict[str, Any]) -> str:

Callers 5

test_dict_entryMethod · 0.90
test_object_entryMethod · 0.90
_extract_tool_callFunction · 0.85

Calls 1

getMethod · 0.45

Tested by 4

test_dict_entryMethod · 0.72
test_object_entryMethod · 0.72