{"record":{"id":"c9b8515c0f4cec00","repo":"datawhalechina/hello-agents","slug":"error-c9b851","errorCode":null,"errorMessage":"除数不能为零","messagePattern":"除数不能为零","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/YYHDBL-HelloCodeAgentCli/tools/builtin/protocol_tools.py","lineNumber":217,"sourceCode":"            def add(a: float, b: float) -> float:\n                \"\"\"加法计算器\"\"\"\n                return a + b\n\n            @server.tool()\n            def subtract(a: float, b: float) -> float:\n                \"\"\"减法计算器\"\"\"\n                return a - b\n\n            @server.tool()\n            def multiply(a: float, b: float) -> float:\n                \"\"\"乘法计算器\"\"\"\n                return a * b\n\n            @server.tool()\n            def divide(a: float, b: float) -> float:\n                \"\"\"除法计算器\"\"\"\n                if b == 0:\n                    raise ValueError(\"除数不能为零\")\n                return a / b\n\n            @server.tool()\n            def greet(name: str = \"World\") -> str:\n                \"\"\"友好问候\"\"\"\n                return f\"Hello, {name}! 欢迎使用 HelloAgents MCP 工具！\"\n\n            @server.tool()\n            def get_system_info() -> dict:\n                \"\"\"获取系统信息\"\"\"\n                import platform\n                import sys\n                return {\n                    \"platform\": platform.system(),\n                    \"python_version\": sys.version,\n                    \"server_name\": \"HelloAgents-BuiltinServer\",\n                    \"tools_count\": 6\n                }","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/YYHDBL-HelloCodeAgentCli/tools/builtin/protocol_tools.py#L199-L235","documentation":"ValueError raised by the 'divide' tool of the built-in FastMCP server in protocol_tools.py when the b argument is 0. It is an intentional domain error surfaced through MCP so the calling agent receives a clear message instead of a ZeroDivisionError traceback.","triggerScenarios":"Calling the builtin MCP divide tool with b=0 (including 0.0, and -0.0) or a computed denominator that evaluates to zero; LLM tool calls passing the wrong positional argument into b.","commonSituations":"Agent arithmetic chains (divide then average) where an intermediate result is 0; argument-order mixups swapping numerator and denominator; unit tests probing error handling of MCP tools.","solutions":["Guard the denominator at the call site: skip, clamp, or ask the model to recompute when it is 0.","Fix swapped arguments if the numerator was intended as the denominator.","Catch the ValueError/tool error in the MCP client and feed the message back to the agent for self-correction."],"exampleFix":"# before\nresult = divide(a=total, b=count)  # count == 0 -> error\n\n# after\nif count == 0:\n    result = 0.0  # or handle empty case explicitly\nelse:\n    result = divide(a=total, b=count)","handlingStrategy":"type-guard","validationCode":"def safe_divide_args(a: float, b: float) -> bool:\n    return b != 0 and abs(b) > 1e-12  # also guard near-zero floats","typeGuard":"def denominator_safe(b: float) -> bool:\n    return isinstance(b, (int, float)) and b != 0","tryCatchPattern":"try:\n    result = await client.call_tool('divide', {'a': total, 'b': count})\nexcept Exception as e:  # MCP surfaces tool errors as exceptions/results\n    if '除数不能为零' in str(e) or 'zero' in str(e).lower():\n        result = None  # handle empty aggregate explicitly\n    else:\n        raise","preventionTips":["Check the denominator before invoking the tool.","Feed tool error messages back to the agent for self-correction.","Prefer aggregate tools (avg) that handle empty inputs internally."],"tags":["mcp","arithmetic","tool-call","validation"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}