Skip to main content
Glama
sdiehl
by sdiehl

create_matrix

Generate symbolic or numeric matrices using a list of lists. Define matrix elements as numbers or expressions, optionally assign a variable name, and store the result for symbolic algebra operations.

Instructions

Creates a SymPy matrix from the provided data.

Args:
    matrix_data: A list of lists representing the rows and columns of the matrix.
                Each element can be a number or a string expression.
    matrix_var_name: Optional name for storing the matrix. If not provided, a
                     sequential name will be generated.

Example:
    # Create a 2x2 matrix with numeric values
    matrix_key = create_matrix([[1, 2], [3, 4]], "M")

    # Create a matrix with symbolic expressions (assuming x, y are defined)
    matrix_key = create_matrix([["x", "y"], ["x*y", "x+y"]])

Returns:
    A key for the stored matrix.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
matrix_dataYes
matrix_var_nameNo

Implementation Reference

  • The handler function for the 'create_matrix' tool. It parses the input matrix data, creates a SymPy Matrix object, stores it in the global expressions dictionary with a generated or provided key, and returns the key. Decorated with @mcp.tool() for registration.
    def create_matrix(
        matrix_data: List[List[Union[int, float, str]]],
        matrix_var_name: Optional[str] = None,
    ) -> str:
        """Creates a SymPy matrix from the provided data.
    
        Args:
            matrix_data: A list of lists representing the rows and columns of the matrix.
                        Each element can be a number or a string expression.
            matrix_var_name: Optional name for storing the matrix. If not provided, a
                             sequential name will be generated.
    
        Example:
            # Create a 2x2 matrix with numeric values
            matrix_key = create_matrix([[1, 2], [3, 4]], "M")
    
            # Create a matrix with symbolic expressions (assuming x, y are defined)
            matrix_key = create_matrix([["x", "y"], ["x*y", "x+y"]])
    
        Returns:
            A key for the stored matrix.
        """
        global expression_counter
    
        try:
            # Process each element to handle expressions
            processed_data = []
            for row in matrix_data:
                processed_row = []
                for elem in row:
                    if isinstance(elem, (int, float)):
                        processed_row.append(elem)
                    else:
                        # Parse the element as an expression using local variables
                        parse_dict = {**local_vars, **functions}
                        parsed_elem = parse_expr(str(elem), local_dict=parse_dict)
                        processed_row.append(parsed_elem)
                processed_data.append(processed_row)
    
            # Create the SymPy matrix
            matrix = Matrix(processed_data)
    
            # Generate a key for the matrix
            if matrix_var_name is None:
                matrix_key = f"matrix_{expression_counter}"
                expression_counter += 1
            else:
                matrix_key = matrix_var_name
    
            # Store the matrix in the expressions dictionary
            expressions[matrix_key] = matrix
    
            return matrix_key
        except Exception as e:
            return f"Error creating matrix: {str(e)}"
  • server.py:1555-1555 (registration)
    The @mcp.tool() decorator registers the create_matrix function as an MCP tool.
    def create_matrix(
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool creates a matrix and stores it (implied by 'key for the stored matrix'), but lacks details on behavioral traits like error handling (e.g., invalid data), side effects (e.g., state persistence), or performance considerations. It adds some context (e.g., optional naming, sequential generation) but is incomplete for a mutation tool.

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

Conciseness4/5

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

The description is well-structured with clear sections (purpose, args, example, returns) and uses bullet points for readability. It's appropriately sized—each sentence adds value, such as clarifying data types and providing examples. However, the example section is slightly verbose with two cases, though both are illustrative.

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

Completeness3/5

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

Given the tool's moderate complexity (2 parameters, mutation operation) and lack of annotations or output schema, the description is partially complete. It covers the core functionality and parameters well but misses behavioral details (e.g., what happens on failure, storage limits) and doesn't fully explain the return value ('key for the stored matrix') in context of the system. It's adequate but has gaps for safe agent use.

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

Parameters4/5

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

The schema description coverage is 0%, so the description must compensate. It effectively explains both parameters: 'matrix_data' as 'a list of lists representing rows and columns' with examples of numeric and string expressions, and 'matrix_var_name' as an optional name with default behavior. This adds significant meaning beyond the bare schema, though it doesn't cover all edge cases (e.g., empty lists).

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's purpose: 'Creates a SymPy matrix from the provided data.' It specifies the verb ('creates') and resource ('SymPy matrix'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'create_vector_field' or 'create_custom_metric', which might also create mathematical objects.

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. It doesn't mention sibling tools like 'matrix_determinant' or 'solve_linear_system' that might be related, nor does it specify prerequisites (e.g., needing SymPy installed or defined variables). The examples show usage but don't explain context or alternatives.

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

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/sdiehl/sympy-mcp'

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