add
Perform precise addition of positive and negative numbers, including fractions, with 64-bit floating point accuracy using a list-based input format. Ideal for mathematical computations in AI systems.
Instructions
Adds 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:38-56 (handler)The handler function for the 'add' tool, decorated with @math_mcp.tool for registration. It validates input, sums the list of numbers using numpy with 64-bit float precision, rounds to the precision limit, logs the operation, and returns the result.@math_mcp.tool def add( numbers: list[int | float], ) -> float: """Adds 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 addition.") 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 addition result = np.round(np.sum(numbers, dtype=np.float64), decimals=SIXTY_FOUR_BIT_FLOAT_DECIMAL_PLACES) logging.info(f"Adding numbers: {numbers} -> Result: {result}") return result