Skip to main content
Glama

numpy_mcp_numerical_operation

Perform numerical operations including arithmetic, statistics, linear algebra, and trigonometric functions using NumPy within the Fermat MCP server for mathematical computations.

Instructions

Do numerical operation like add, sub, mul, div, power, abs, exp, log, sqrt, sin, cos, tan, mean, median, std, var, min, max, argmin, argmax, percentile, dot, matmul, inv, det, eig, solve, svd

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYes
aNo
bNo
shapeNo
new_shapeNo
axisNo
qNo
startNo
stopNo
stepNo
numNo
fill_valueNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function implementing the 'numpy_mcp_numerical_operation' tool logic using NumPy for various array and linear algebra operations.
    def numerical_operation(
        operation: str,
        a: Optional[Union[list, float, int]] = None,
        b: Optional[Union[list, float, int]] = None,
        shape: Optional[list] = None,
        new_shape: Optional[list] = None,
        axis: int = 0,
        q: Optional[float] = None,
        start: Optional[float] = None,
        stop: Optional[float] = None,
        step: Optional[float] = 1.0,
        num: Optional[int] = None,
        fill_value: Optional[float] = None,
    ) -> Union[list, float, int, dict]:
        """
        Unified interface for numerical operations using numpy.
    
        Args:
            operation: The operation to perform. One of:
                - 'create_array': Convert list to array (a: list)
                - 'zeros': Array of zeros (shape: list)
                - 'ones': Array of ones (shape: list)
                - 'full': Array filled with value (shape: list, fill_value: float)
                - 'arange': Evenly spaced values (start: float, stop: float, step: float)
                - 'linspace': Evenly spaced samples (start: float, stop: float, num: int)
                - 'reshape': Reshape array (a: list, new_shape: list)
                - 'flatten': Flatten array (a: list)
                - 'concatenate': Join arrays (a: list[list], axis: int)
                - 'transpose': Transpose array (a: list)
                - 'stack': Stack arrays (a: list[list], axis: int)
                - 'add': Element-wise addition (a: list, b: list)
                - 'subtract': Element-wise subtraction (a: list, b: list)
                - 'multiply': Element-wise multiplication (a: list, b: list)
                - 'divide': Element-wise division (a: list, b: list)
                - 'power': Element-wise power (a: list, b: list)
                - 'abs_val': Absolute value (a: list)
                - 'exp': Exponential (a: list)
                - 'log': Natural logarithm (a: list)
                - 'sqrt': Square root (a: list)
                - 'sin': Sine (a: list)
                - 'cos': Cosine (a: list)
                - 'tan': Tangent (a: list)
                - 'mean': Mean (a: list)
                - 'median': Median (a: list)
                - 'std': Standard deviation (a: list)
                - 'var': Variance (a: list)
                - 'min_val': Minimum value (a: list)
                - 'max_val': Maximum value (a: list)
                - 'argmin': Index of minimum (a: list)
                - 'argmax': Index of maximum (a: list)
                - 'percentile': Percentile (a: list, q: float)
                - 'dot': Dot product (a: list, b: list)
                - 'matmul': Matrix multiplication (a: list, b: list)
                - 'inv': Matrix inverse (a: list)
                - 'det': Matrix determinant (a: list)
                - 'eig': Eigenvalues/vectors (a: list)
                - 'eigenvals': Eigenvalues only (a: list)
                - 'solve': Solve linear system (a: list, b: list)
                - 'svd': Singular Value Decomposition (a: list)
            a: First input array or value
            b: Second input array or value (for binary operations)
            shape: Shape of the output array (for creation operations)
            new_shape: New shape for reshape operation
            axis: Axis along which to perform operations (default: 0)
            q: Percentile value (0-100) for percentile operation
            start: Start value for arange/linspace
            stop: Stop value for arange/linspace
            step: Step size for arange (default: 1.0)
            num: Number of samples for linspace
            fill_value: Fill value for 'full' operation
    
        Returns:
            Result of the operation, type depends on operation
        """
        a_array = np.array(a) if a is not None else None
        b_array = np.array(b) if b is not None else None
    
        if operation == "create_array":
            return a_array.tolist()
        elif operation == "zeros":
            return np.zeros(shape).tolist()
        elif operation == "ones":
            return np.ones(shape).tolist()
        elif operation == "full":
            return np.full(shape, fill_value).tolist()
        elif operation == "arange":
            return np.arange(start, stop, step).tolist()
        elif operation == "linspace":
            return np.linspace(start, stop, num).tolist()
        elif operation == "reshape":
            return a_array.reshape(new_shape).tolist()
        elif operation == "flatten":
            return a_array.ravel().tolist()
        elif operation == "concatenate":
            return np.concatenate([np.array(arr) for arr in a], axis=axis).tolist()
        elif operation == "transpose":
            return a_array.T.tolist()
        elif operation == "stack":
            return np.stack([np.array(arr) for arr in a], axis=axis).tolist()
        elif operation == "add":
            return (a_array + b_array).tolist()
        elif operation == "subtract":
            return (a_array - b_array).tolist()
        elif operation == "multiply":
            return (a_array * b_array).tolist()
        elif operation == "divide":
            return (a_array / b_array).tolist()
        elif operation == "power":
            return np.power(a_array, b_array).tolist()
        elif operation == "abs_val":
            return np.abs(a_array).tolist()
        elif operation == "exp":
            return np.exp(a_array).tolist()
        elif operation == "log":
            return np.log(a_array).tolist()
        elif operation == "sqrt":
            return np.sqrt(a_array).tolist()
        elif operation == "sin":
            return np.sin(a_array).tolist()
        elif operation == "cos":
            return np.cos(a_array).tolist()
        elif operation == "tan":
            return np.tan(a_array).tolist()
        elif operation == "mean":
            return float(np.mean(a_array))
        elif operation == "median":
            return float(np.median(a_array))
        elif operation == "std":
            return float(np.std(a_array))
        elif operation == "var":
            return float(np.var(a_array))
        elif operation == "min_val":
            return float(np.min(a_array))
        elif operation == "max_val":
            return float(np.max(a_array))
        elif operation == "argmin":
            return int(np.argmin(a_array))
        elif operation == "argmax":
            return int(np.argmax(a_array))
        elif operation == "percentile":
            return float(np.percentile(a_array, q))
        elif operation == "dot":
            return float(np.dot(a_array, b_array))
        elif operation == "matmul":
            return np.matmul(a_array, b_array).tolist()
        elif operation == "inv":
            return np.linalg.inv(a_array).tolist()
        elif operation == "det":
            return float(np.linalg.det(a_array))
        elif operation == "eig":
            vals, vecs = np.linalg.eig(a_array)
            return {"eigenvalues": vals.tolist(), "eigenvectors": vecs.tolist()}
        elif operation == "eigenvals":
            vals = np.linalg.eigvals(a_array)
            return vals.tolist()
        elif operation == "solve":
            return np.linalg.solve(a_array, b_array).tolist()
        elif operation == "svd":
            U, S, Vt = np.linalg.svd(a_array)
            return {"U": U.tolist(), "S": S.tolist(), "Vt": Vt.tolist()}
        else:
            raise ValueError(f"Unknown operation: {operation}")
  • Registers the numerical_operation function as the 'numpy_mcp_numerical_operation' tool in the FastMCP server.
    numpy_mcp.tool(
        numerical_operation,
        description="Do numerical operation like add, sub, mul, div, power, abs, exp, log, sqrt, sin, cos, tan, mean, median, std, var, min, max, argmin, argmax, percentile, dot, matmul, inv, det, eig, solve, svd",
    )
  • Type hints and comprehensive docstring defining the input schema and supported operations for the tool.
    def numerical_operation(
        operation: str,
        a: Optional[Union[list, float, int]] = None,
        b: Optional[Union[list, float, int]] = None,
        shape: Optional[list] = None,
        new_shape: Optional[list] = None,
        axis: int = 0,
        q: Optional[float] = None,
        start: Optional[float] = None,
        stop: Optional[float] = None,
        step: Optional[float] = 1.0,
        num: Optional[int] = None,
        fill_value: Optional[float] = None,
    ) -> Union[list, float, int, dict]:
        """
        Unified interface for numerical operations using numpy.
    
        Args:
            operation: The operation to perform. One of:
                - 'create_array': Convert list to array (a: list)
                - 'zeros': Array of zeros (shape: list)
                - 'ones': Array of ones (shape: list)
                - 'full': Array filled with value (shape: list, fill_value: float)
                - 'arange': Evenly spaced values (start: float, stop: float, step: float)
                - 'linspace': Evenly spaced samples (start: float, stop: float, num: int)
                - 'reshape': Reshape array (a: list, new_shape: list)
                - 'flatten': Flatten array (a: list)
                - 'concatenate': Join arrays (a: list[list], axis: int)
                - 'transpose': Transpose array (a: list)
                - 'stack': Stack arrays (a: list[list], axis: int)
                - 'add': Element-wise addition (a: list, b: list)
                - 'subtract': Element-wise subtraction (a: list, b: list)
                - 'multiply': Element-wise multiplication (a: list, b: list)
                - 'divide': Element-wise division (a: list, b: list)
                - 'power': Element-wise power (a: list, b: list)
                - 'abs_val': Absolute value (a: list)
                - 'exp': Exponential (a: list)
                - 'log': Natural logarithm (a: list)
                - 'sqrt': Square root (a: list)
                - 'sin': Sine (a: list)
                - 'cos': Cosine (a: list)
                - 'tan': Tangent (a: list)
                - 'mean': Mean (a: list)
                - 'median': Median (a: list)
                - 'std': Standard deviation (a: list)
                - 'var': Variance (a: list)
                - 'min_val': Minimum value (a: list)
                - 'max_val': Maximum value (a: list)
                - 'argmin': Index of minimum (a: list)
                - 'argmax': Index of maximum (a: list)
                - 'percentile': Percentile (a: list, q: float)
                - 'dot': Dot product (a: list, b: list)
                - 'matmul': Matrix multiplication (a: list, b: list)
                - 'inv': Matrix inverse (a: list)
                - 'det': Matrix determinant (a: list)
                - 'eig': Eigenvalues/vectors (a: list)
                - 'eigenvals': Eigenvalues only (a: list)
                - 'solve': Solve linear system (a: list, b: list)
                - 'svd': Singular Value Decomposition (a: list)
            a: First input array or value
            b: Second input array or value (for binary operations)
            shape: Shape of the output array (for creation operations)
            new_shape: New shape for reshape operation
            axis: Axis along which to perform operations (default: 0)
            q: Percentile value (0-100) for percentile operation
            start: Start value for arange/linspace
            stop: Stop value for arange/linspace
            step: Step size for arange (default: 1.0)
            num: Number of samples for linspace
            fill_value: Fill value for 'full' operation
    
        Returns:
            Result of the operation, type depends on operation
        """
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description offers no behavioral information. It doesn't mention that this is a computational tool, whether operations are performed in-memory, what the output format is, error handling, performance characteristics, or any constraints. The description is purely a list of operation names without context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

While technically concise as a single run-on list, the structure is poor - it's just a comma-separated enumeration without proper sentence structure or organization. The information isn't front-loaded with purpose; it jumps straight to listing operations without context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 12 parameters, 0% schema coverage, no annotations, but with an output schema, the description is severely inadequate. It doesn't explain the tool's scope, parameter usage, or behavioral characteristics. The output schema helps with return values, but the description doesn't provide the necessary context for proper tool selection and invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 12 parameters and 0% schema description coverage, the description provides zero information about parameters. It doesn't explain what 'operation' expects (the listed operations), how 'a' and 'b' relate to operations, what 'shape' and 'new_shape' do, or how other parameters like 'axis', 'q', 'start/stop/step' are used. The description fails to compensate for the complete lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description lists operations but is vague about what the tool actually does - it doesn't specify that it performs numerical operations on arrays/numbers using NumPy. While it distinguishes from plotting siblings, it doesn't clearly differentiate from other numerical/matrix operation siblings like numpy_mcp_matlib_operation or sympy_mcp_matrix_operation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives. The description doesn't mention NumPy specifically, provide context about numerical vs symbolic computation, or indicate when to choose this over sibling tools like sympy_mcp_algebra_operation or numpy_mcp_matlib_operation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/abhiphile/fermat-mcp'

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