Skip to main content
Glama
avanishd-3

Math MCP Server

by avanishd-3

add

Adds a list of numbers with 64-bit floating point precision. Provide numbers as a list like [1, 2, 3] to calculate their sum.

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'add' MCP tool. It sums the provided list of numbers using NumPy's sum with 64-bit float precision, rounds to the precision limit, logs the operation, and returns the result. Raises ValueError for empty lists.
    @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
  • Schema definition via type annotations (input: list[int | float], output: float) and docstring describing usage and examples for the 'add' 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].
        """
  • Registration of the 'add' tool to the FastMCP server instance 'math_mcp' using the @tool decorator.
    @math_mcp.tool

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other 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