divide
Divide one number by another to calculate the quotient. Handles division operations while preventing division by zero errors.
Instructions
Divide the first number by the second number.
Args:
a: The dividend (number to be divided)
b: The divisor (number to divide by)
Returns:
The quotient of a divided by b (a / b)
Raises:
ValueError: If b is zero (division by zero)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- server.py:71-88 (handler)The divide tool handler function, registered via @mcp.tool() decorator. Performs a / b after checking if b is zero to avoid division by zero error. The type hints and docstring define the input schema and output.@mcp.tool() def divide(a: float, b: float) -> float: """ Divide the first number by the second number. Args: a: The dividend (number to be divided) b: The divisor (number to divide by) Returns: The quotient of a divided by b (a / b) Raises: ValueError: If b is zero (division by zero) """ if b == 0: raise ValueError("Division by zero is not allowed") return a / b