multiply
Calculate the product of a list of positive or negative numbers with 64-bit floating-point precision. Use fractions or integers in a list format, such as [1, 2, 3], to receive accurate multiplication results.
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 handler function for the 'multiply' MCP tool. It validates that the input list 'numbers' is non-empty, computes the product using numpy.prod with float64 dtype, rounds to 64-bit float precision, logs the operation, and returns the result as a float.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 @math_mcp.tool decorator registers the multiply function as an MCP tool on the math_mcp FastMCP server instance.@math_mcp.tool
- src/math_server.py:73-78 (schema)Type annotations and docstring defining the input schema (list of int/float) and output (float), including usage instructions for the multiply tool.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]. """