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

Method _extract_tool_call_info

src/mcp_cli/chat/tool_processor.py:1214–1246  ·  view source on GitHub ↗

Extract tool name, arguments, and call ID from a tool call.

(self, tool_call: Any, idx: int)

Source from the content-addressed store, hash-verified

1212 logger.debug("finish_tool_calls() raised", exc_info=True)
1213
1214 def _extract_tool_call_info(self, tool_call: Any, idx: int) -> tuple[str, Any, str]:
1215 """Extract tool name, arguments, and call ID from a tool call."""
1216 llm_tool_name = "unknown_tool"
1217 raw_arguments: Any = {}
1218 call_id = f"call_{idx}"
1219
1220 if isinstance(tool_call, ToolCall):
1221 llm_tool_name = tool_call.function.name
1222 raw_arguments = tool_call.function.arguments
1223 call_id = tool_call.id
1224 # DEBUG: Log raw arguments from model
1225 logger.debug(
1226 f"RAW MODEL TOOL CALL: {llm_tool_name}, "
1227 f"raw_arguments type={type(raw_arguments).__name__}, "
1228 f"value={raw_arguments}"
1229 )
1230 elif isinstance(tool_call, dict) and "function" in tool_call:
1231 logger.warning(
1232 f"Received dict tool call instead of ToolCall model: {type(tool_call)}"
1233 )
1234 fn = tool_call["function"]
1235 llm_tool_name = fn.get("name", "unknown_tool")
1236 raw_arguments = fn.get("arguments", {})
1237 call_id = tool_call.get("id", call_id)
1238 else:
1239 logger.error(f"Unrecognized tool call format: {type(tool_call)}")
1240
1241 # Validate
1242 if not llm_tool_name or llm_tool_name == "unknown_tool":
1243 logger.error(f"Tool name is empty or unknown in tool call: {tool_call}")
1244 llm_tool_name = f"unknown_tool_{idx}"
1245
1246 return llm_tool_name, raw_arguments, call_id
1247
1248 def _parse_arguments(self, raw_arguments: Any) -> dict[str, Any]:
1249 """Parse raw arguments into a dictionary."""

Calls 1

getMethod · 0.45