(
self, *, args: dict[str, Any], tool_context: ToolContext
)
| 284 | |
| 285 | @override |
| 286 | async def run_async( |
| 287 | self, *, args: dict[str, Any], tool_context: ToolContext |
| 288 | ) -> Any: |
| 289 | if isinstance(self._require_confirmation, Callable): |
| 290 | args_to_call = args.copy() |
| 291 | try: |
| 292 | signature = inspect.signature(self._require_confirmation) |
| 293 | valid_params = set(signature.parameters.keys()) |
| 294 | has_kwargs = any( |
| 295 | param.kind == inspect.Parameter.VAR_KEYWORD |
| 296 | for param in signature.parameters.values() |
| 297 | ) |
| 298 | |
| 299 | # Detect context parameter by type or fallback to 'tool_context' name |
| 300 | context_param = ( |
| 301 | find_context_parameter(self._require_confirmation) or "tool_context" |
| 302 | ) |
| 303 | if context_param in valid_params or has_kwargs: |
| 304 | args_to_call[context_param] = tool_context |
| 305 | |
| 306 | # Filter args_to_call only if there's no **kwargs |
| 307 | if not has_kwargs: |
| 308 | # Add context param to valid_params if it was added to args_to_call |
| 309 | if context_param in args_to_call: |
| 310 | valid_params.add(context_param) |
| 311 | args_to_call = { |
| 312 | k: v for k, v in args_to_call.items() if k in valid_params |
| 313 | } |
| 314 | except ValueError: |
| 315 | args_to_call = args |
| 316 | |
| 317 | require_confirmation = await self._invoke_callable( |
| 318 | self._require_confirmation, args_to_call |
| 319 | ) |
| 320 | else: |
| 321 | require_confirmation = bool(self._require_confirmation) |
| 322 | |
| 323 | if require_confirmation: |
| 324 | if not tool_context.tool_confirmation: |
| 325 | tool_context.request_confirmation( |
| 326 | hint=( |
| 327 | f"Please approve or reject the tool call {self.name}() by" |
| 328 | " responding with a FunctionResponse with an expected" |
| 329 | " ToolConfirmation payload." |
| 330 | ), |
| 331 | ) |
| 332 | return { |
| 333 | "error": ( |
| 334 | "This tool call requires confirmation, please approve or" |
| 335 | " reject." |
| 336 | ) |
| 337 | } |
| 338 | elif not tool_context.tool_confirmation.confirmed: |
| 339 | return {"error": "This tool call is rejected."} |
| 340 | |
| 341 | if not is_feature_enabled(FeatureName._MCP_GRACEFUL_ERROR_HANDLING): # pylint: disable=protected-access |
| 342 | # Pre-fix behavior: exceptions bubble up to the agent runner. |
| 343 | return await super().run_async(args=args, tool_context=tool_context) |
nothing calls this directly
no test coverage detected