multiply
Multiply numbers in a list with 64-bit floating point precision. Provide numbers as a list like [1, 2, 3] or [1/2, 1/3, 1/4] to get the product.
Instructions
Multiplies a list of positive and/or negative numbers with 64 bit floating point precision and returns a 64 bit float. You need to provide them in the format of a list. For example, [1, 2, 3] would return 6.0. You can also use fractions if you want to, like [1/2, 1/3, 1/4].
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| numbers | Yes |
Implementation Reference
- src/math_server.py:72-89 (handler)The core implementation of the 'multiply' tool handler. It validates input, computes the product using NumPy's np.prod with float64 dtype, rounds to the precision of 64-bit floats, logs the operation, and returns the result.def multiply( numbers: list[int | float], ) -> float: """Multiplies a list of positive and/or negative numbers with 64 bit floating point precision and returns a 64 bit float. You need to provide them in the format of a list. For example, [1, 2, 3] would return 6.0. You can also use fractions if you want to, like [1/2, 1/3, 1/4]. """ # This is technically allowed by Fast MCP, but it is an error here if not numbers: logging.error("Received an empty list for multiplication.") raise ValueError("""The list of numbers cannot be empty. Try wrapping the numbers in brackets, like [1, 2, 3], if this is not the case. """) # Use numpy for fast multiplication result = np.round(np.prod(numbers, dtype=np.float64), decimals=SIXTY_FOUR_BIT_FLOAT_DECIMAL_PLACES) logging.info(f"Multiplying numbers: {numbers} -> Result: {result}") return result
- src/math_server.py:71-71 (registration)The FastMCP decorator that registers the multiply function as a tool named 'multiply'.@math_mcp.tool
- src/math_server.py:73-78 (schema)Type annotations defining the input as a list of int or float, output as float, and docstring describing usage and behavior for schema generation.numbers: list[int | float], ) -> float: """Multiplies a list of positive and/or negative numbers with 64 bit floating point precision and returns a 64 bit float. You need to provide them in the format of a list. For example, [1, 2, 3] would return 6.0. You can also use fractions if you want to, like [1/2, 1/3, 1/4]. """