Skip to main content
Glama

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
NameRequiredDescriptionDefault
numbersYes

Implementation Reference

  • 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
  • The @math_mcp.tool decorator registers the multiply function as an MCP tool on the math_mcp FastMCP server instance.
    @math_mcp.tool
  • 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]. """

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/avanishd-3/math-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server