Skip to main content
Glama

numpy_mcp_matlib_operation

Perform matrix operations like creating random matrices, zeros, ones, identity matrices, reshaping, concatenating, transposing, and stacking arrays for mathematical computations.

Instructions

Do matrix operations: rand-mat, zeros, ones, eye, identity, arange, linspace, reshape, flatten, concatenate, transpose, stack

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYes
dataNo
shapeNo
mNo
nNo
kNo
startNo
stopNo
stepNo
numNo
axisNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function implementing the 'numpy_mcp_matlib_operation' tool. It provides a unified interface for various NumPy matrix and array operations such as creating zero/ones matrices, identity/eye matrices, random matrices, arange/linspace, reshape, flatten, concatenate, transpose, and stack.
    def matlib_operation(
        operation: str,
        data: Optional[Union[list, int, float]] = None,
        shape: Optional[Union[list, int]] = None,
        m: Optional[int] = None,
        n: Optional[int] = None,
        k: int = 0,
        start: Optional[float] = None,
        stop: Optional[float] = None,
        step: Optional[float] = None,
        num: Optional[int] = None,
        axis: int = 0,
    ) -> list:
        """
        Unified interface for numerical matrix operations using numpy.
    
        Args:
            operation: The matrix operation to perform. One of:
                - 'rand-mat': Matrix of random values (0-1) (m: int, n: int) -> 2D array
                - 'zeros': Matrix of zeros (shape: list) -> array
                - 'ones': Matrix of ones (shape: list) -> array
                - 'eye': 2D array with ones on diagonal (m: int, n: int, k: int) -> 2D array
                - 'identity': Identity matrix (n: int) -> 2D array
                - 'arange': Evenly spaced values (start: float, stop: float, step: float) -> 1D array
                - 'linspace': Evenly spaced numbers (start: float, stop: float, num: int) -> 1D array
                - 'reshape': Reshape array (data: list, shape: list) -> array
                - 'flatten': Flatten array (data: list) -> 1D array
                - 'concatenate': Join arrays (data: list[list], axis: int) -> array
                - 'transpose': Transpose array (data: list) -> array
                - 'stack': Stack arrays (data: list[list], axis: int) -> array
    
            data: Input data for matrix operations
            shape: Shape of the output matrix
            m: First dimension
            n: Second dimension
            k: Diagonal offset for eye operation
            start: Start value for arange/linspace
            stop: Stop value for arange/linspace
            step: Step size for arange
            num: Number of samples for linspace
            axis: Axis along which to perform operations
    
        Returns:
            list: The resulting matrix/array as a nested list
        """
    
        if operation == "zeros":
            return np.zeros(shape).tolist()
    
        elif operation == "ones":
            return np.ones(shape).tolist()
    
        elif operation == "eye":
            return np.eye(m or n, n, k).tolist()
    
        elif operation == "identity":
            return np.eye(n).tolist()
    
        elif operation == "rand-mat":
            return np.random.rand(m or 1, n or (m or 1)).tolist()
    
        elif operation == "arange":
            if start is None or stop is None:
                raise ValueError("start and stop are required for arange operation")
            if step is None:
                return np.arange(start, stop).tolist()
            return np.arange(start, stop, step).tolist()
    
        elif operation == "linspace":
            if start is None or stop is None or num is None:
                raise ValueError("start, stop, and num are required for linspace operation")
            return np.linspace(start, stop, num).tolist()
    
        elif operation == "reshape":
            if data is None or shape is None:
                raise ValueError("data and shape are required for reshape operation")
            return np.array(data).reshape(shape).tolist()
    
        elif operation == "flatten":
            if data is None:
                raise ValueError("data is required for flatten operation")
            return np.array(data).flatten().tolist()
    
        elif operation == "concatenate":
            if data is None:
                raise ValueError("data is required for concatenate operation")
            return np.concatenate([np.array(x) for x in data], axis=axis).tolist()
    
        elif operation == "transpose":
            if data is None:
                raise ValueError("data is required for transpose operation")
            return np.array(data).T.tolist()
    
        elif operation == "stack":
            if data is None:
                raise ValueError("data is required for stack operation")
            return np.stack([np.array(x) for x in data], axis=axis).tolist()
    
        else:
            raise ValueError(f"Unknown operation: {operation}")
  • Registers the matlib_operation handler as a tool in the 'numpy_mcp' FastMCP server instance, likely exposing it as 'numpy_mcp_matlib_operation'.
    numpy_mcp.tool(
        matlib_operation,
        description="Do matrix operations: rand-mat, zeros, ones, eye, identity, arange, linspace, reshape, flatten, concatenate, transpose, stack",
    )
  • Imports the matlib_operation function for use in tool registration.
    from fmcp.numpy_mcp.core.matlib import matlib_operation
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It lists operations but doesn't explain what each operation does, their side effects (e.g., whether they create new matrices or modify existing ones), error conditions, or output format. For a tool with 11 parameters and no annotation coverage, this is a significant gap in behavioral context.

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

Conciseness5/5

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

The description is extremely concise—a single sentence listing operations—with zero wasted words. It's front-loaded with the purpose and efficiently enumerates supported operations, making it easy to scan.

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?

Given the complexity (11 parameters, no annotations, 0% schema coverage) and the presence of an output schema, the description is incomplete. It doesn't explain how operations map to parameters, what inputs are needed for each operation, or behavioral traits. While the output schema might cover return values, the description lacks crucial context for proper tool invocation.

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

Parameters2/5

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

Schema description coverage is 0%, meaning none of the 11 parameters have descriptions in the schema. The description lists operations but doesn't explain which parameters correspond to which operations or their meanings (e.g., what 'm', 'n', 'k' represent). It adds minimal value beyond the schema, failing to compensate for the coverage gap.

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

Purpose4/5

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

The description clearly states the tool performs 'matrix operations' and lists specific operations (rand-mat, zeros, ones, etc.), providing a specific verb+resource. However, it doesn't explicitly distinguish this from sibling tools like 'sympy_mcp_matrix_operation' or 'numpy_mcp_numerical_operation', which likely handle similar mathematical operations.

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?

The description provides no guidance on when to use this tool versus alternatives. There are multiple sibling tools (e.g., sympy_mcp_matrix_operation, numpy_mcp_numerical_operation) that might overlap in functionality, but the description offers no comparison, prerequisites, or context for selection.

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