{"record":{"id":"1a1fe2005dda9dcf","repo":"iflytek/astron-agent","slug":"40027-failed-to-execute-mcp-server-tool","errorCode":"40027","errorMessage":"Failed to execute MCP server tool","messagePattern":"Failed to execute MCP server tool","errorType":"exception","errorClass":"PluginExc","httpStatus":null,"severity":"error","filePath":"core/agent/service/plugin/mcp.py","lineNumber":73,"sourceCode":"                        response.raise_for_status()\n                        if response.status == 200:\n                            resp = await response.json()\n                            sp.add_info_events(\n                                attributes={\n                                    \"mcp-plugin-run-outputs\": json.dumps(\n                                        resp, ensure_ascii=False\n                                    )\n                                }\n                            )\n                        else:\n                            sp.add_info_events(\n                                attributes={\n                                    \"mcp-plugin-run-outputs\": (\n                                        f\"response code is {response.status}\"\n                                    )\n                                }\n                            )\n                            raise RunMcpPluginExc\n            except asyncio.TimeoutError as e:\n                raise RunMcpPluginExc from e\n\n            end_time = int(round(time.time() * 1000))\n            plugin_response = PluginResponse(\n                code=resp.get(\"code\", \"\"),\n                sid=resp.get(\"sid\", \"\"),\n                start_time=start_time,\n                end_time=end_time,\n                result=resp,\n                log=[{\"name\": self.name, \"input\": action_input, \"output\": resp}],\n            )\n\n            return plugin_response\n\n\nclass McpPluginFactory(BaseModel):\n    app_id: str","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/agent/service/plugin/mcp.py#L55-L91","documentation":"RunMcpPluginExc raised in McpPluginRunner.run (mcp.py:73). The MCP plugin runner POSTs tool execution to RUN_MCP_PLUGIN_URL with an aiohttp timeout of MCP_CALL_TIMEOUT (default 90s); when the request exceeds it, asyncio.TimeoutError is caught and re-raised as the generic 40027 'Failed to execute MCP server tool'.","triggerScenarios":"Calling McpPluginRunner.run where the MCP plugin service takes longer than MCP_CALL_TIMEOUT seconds to respond to the tool-execution POST.","commonSituations":"Slow or hanging downstream MCP server tool, MCP plugin service overloaded, network latency between agent and plugin, MCP_CALL_TIMEOUT set too low for a legitimately long-running tool.","solutions":["Check whether the MCP server/tool itself is hung; test it directly outside the agent.","Raise the MCP_CALL_TIMEOUT env var (seconds) to accommodate legitimately slow tools.","Verify MCP plugin service health/resource usage; scale it if the queue is backing up.","Add retry-once-with-backoff for idempotent tools to tolerate transient slowness."],"exampleFix":"// before\ntimeout = aiohttp.ClientTimeout(total=int(os.getenv(\"MCP_CALL_TIMEOUT\", \"90\")))\n// after: give long tools more headroom\nos.environ.setdefault(\"MCP_CALL_TIMEOUT\", \"180\")\ntimeout = aiohttp.ClientTimeout(total=int(os.getenv(\"MCP_CALL_TIMEOUT\", \"90\")))","handlingStrategy":"retry","validationCode":"timeout_s = int(os.getenv(\"MCP_CALL_TIMEOUT\", \"90\"))\nif timeout_s < expected_tool_max_seconds:\n    logger.warning(\"MCP_CALL_TIMEOUT=%s may be too low for this tool\", timeout_s)","typeGuard":null,"tryCatchPattern":"try:\n    result = await runner.run(action_input, span)\nexcept RunMcpPluginExc as e:\n    if isinstance(e.__cause__, asyncio.TimeoutError):\n        logger.warning(\"MCP tool timed out; tool=%s timeout=%ss\", runner.name, timeout_s)\n    raise","preventionTips":["Size MCP_CALL_TIMEOUT to the slowest legitimate tool","Monitor MCP plugin/service latency and alert before timeouts occur","Only retry idempotent tools on timeout","Check downstream MCP server health when timeouts cluster"],"tags":["mcp","plugin","timeout","aiohttp","network"],"backgroundTag":"request-timeout","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}