| 311 | raise RuntimeError(f"Failed to fetch tools from MCP: {e}") |
| 312 | |
| 313 | def make_mcp_tool_function( |
| 314 | self, tool_name: str, param_names: list[str] |
| 315 | ) -> callable: |
| 316 | def wrapper(*args, is_catch_exception=True, **kwargs) -> dict: |
| 317 | if len(args) > len(param_names): |
| 318 | raise ValueError( |
| 319 | f"Too many arguments: expected {len(param_names)}, got {len(args)}" |
| 320 | ) |
| 321 | arguments = dict(zip(param_names, args)) |
| 322 | arguments.update(kwargs) |
| 323 | return self.invoke(tool_name, arguments, is_catch_exception) |
| 324 | |
| 325 | return wrapper |
| 326 | |
| 327 | def process_tool_calls(self, msg: Any) -> List[dict]: |
| 328 | tool_calls = msg.tool_calls or [] |