{"record":{"id":"f6c20dceb33e936a","repo":"crewAIInc/crewAI","slug":"tool-execution-failed-e-s","errorCode":null,"errorMessage":"Tool execution failed: {e!s}","messagePattern":"Tool execution failed: (.+?)","errorType":"exception","errorClass":"MergeAgentHandlerToolError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/merge_agent_handler_tool/merge_agent_handler_tool.py","lineNumber":142,"sourceCode":"                params={\"name\": self.tool_name, \"arguments\": kwargs},\n            )\n\n            if \"result\" in result and \"content\" in result[\"result\"]:\n                content = result[\"result\"][\"content\"]\n                if content and len(content) > 0:\n                    text_content = content[0].get(\"text\", \"\")\n                    try:\n                        return json.loads(text_content)\n                    except json.JSONDecodeError:\n                        return text_content\n\n            return result\n\n        except MergeAgentHandlerToolError:\n            raise\n        except Exception as e:\n            logger.error(f\"Unexpected error executing tool {self.tool_name}: {e!s}\")\n            raise MergeAgentHandlerToolError(f\"Tool execution failed: {e!s}\") from e\n\n    @classmethod\n    def from_tool_name(\n        cls,\n        tool_name: str,\n        tool_pack_id: str,\n        registered_user_id: str,\n        base_url: str = \"https://ah-api.merge.dev\",\n        **kwargs: Any,\n    ) -> te.Self:\n        \"\"\"\n        Create a MergeAgentHandlerTool from a tool name.\n\n        Args:\n            tool_name: Name of the tool (e.g., \"linear__create_issue\")\n            tool_pack_id: UUID of the Tool Pack\n            registered_user_id: UUID of the registered user\n            base_url: Base URL for Agent Handler API (defaults to production)","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/merge_agent_handler_tool/merge_agent_handler_tool.py#L124-L160","documentation":"The catch-all in MergeAgentHandlerTool._run: any exception that is not already a MergeAgentHandlerToolError (those are re-raised untouched) gets logged and re-wrapped as \"Tool execution failed: ...\" with the original as __cause__. It fires during parsing of the MCP response content or while navigating the result structure — e.g. unexpected content shapes, missing keys, or JSON shape surprises.","triggerScenarios":"The remote tool returns a content array whose first element has no 'text'; tools/call returns an unexpected result envelope; KeyErrors while walking result[\"result\"][\"content\"]; unexpected types from json.loads.","commonSituations":"Remote tool pack updated and changed its response format; a remote tool returning error content instead of text; edge-case responses (empty content list).","solutions":["Inspect e.__cause__ (and the log line) — it names the real underlying exception","Call the same tool via a raw tools/call request and print the full JSON to see the actual content shape","Pin/verify the tool pack version if the response format regressed; report schema changes to the pack owner","Handle unexpected content types gracefully on your side (e.g. default to str(result) instead of assuming text)"],"exampleFix":"# before\nresult = tool._run(query=\"acme\")  # Tool execution failed: KeyError 'text'\n\n# after\ntry:\n    result = tool._run(query=\"acme\")\nexcept MergeAgentHandlerToolError as e:\n    logging.error(\"underlying cause: %r\", e.__cause__)\n    raise","handlingStrategy":"try-catch","validationCode":"def parse_mcp_content(result: dict):\n    content = result.get(\"result\", {}).get(\"content\", [])\n    if content and isinstance(content[0], dict) and \"text\" in content[0]:\n        import json\n        try:\n            return json.loads(content[0][\"text\"])\n        except json.JSONDecodeError:\n            return content[0][\"text\"]\n    return result","typeGuard":null,"tryCatchPattern":"try:\n    result = tool._run(**kwargs)\nexcept MergeAgentHandlerToolError as e:\n    cause = e.__cause__\n    logging.error(\"tool call failed; cause=%r\", cause)\n    if isinstance(cause, (KeyError, TypeError)):\n        # response shape changed — inspect raw tools/call output\n        dump_raw_response()\n    raise","preventionTips":["Log e.__cause__ — the wrapper hides the real exception type","Pin tool pack versions when response formats matter","Smoke-test each tool after pack updates"],"tags":["error-handling","merge","json-parsing","crewai-tools"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}