calculate_percentage
Calculate what percentage one number is of another number. Enter the part and whole values to compute the percentage result.
Instructions
Calculate what percentage one number is of another number.
Args:
part: The part (the number you want to find the percentage of)
whole: The whole (the total or reference number)
Returns:
The percentage as a number (e.g., 25.0 means 25%)
Raises:
ValueError: If whole is zero
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| part | Yes | ||
| whole | Yes |
Implementation Reference
- server.py:147-164 (handler)The handler function for the 'calculate_percentage' tool, which calculates the percentage that 'part' is of 'whole'. It includes input validation to prevent division by zero. Registered via the @mcp.tool() decorator.@mcp.tool() def calculate_percentage(part: float, whole: float) -> float: """ Calculate what percentage one number is of another number. Args: part: The part (the number you want to find the percentage of) whole: The whole (the total or reference number) Returns: The percentage as a number (e.g., 25.0 means 25%) Raises: ValueError: If whole is zero """ if whole == 0: raise ValueError("Cannot calculate percentage when whole is zero") return (part / whole) * 100