Skip to main content
Glama

sympy_mcp_algebra_operation

Perform algebraic operations including simplify, expand, factor, and collect on mathematical expressions using SymPy within the Fermat MCP server.

Instructions

Do algebraic operations like simplify, expand, factor, collect

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYes
exprYes
symsNo
rationalNo
ratioNo
measureNo
deepNo
modulusNo
power_baseNo
power_expNo
mulNo
logNo
multinomialNo
basicNo
fracNo
signNo
evaluateNo
exactNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function implementing the 'sympy_mcp_algebra_operation' tool. It performs SymPy algebra operations (simplify, expand, factor, collect) on input expressions with configurable parameters.
    def algebra_operation(
        operation: AlgebraOperation,
        expr: Union[str],
        syms: Optional[Union[str, List[str]]] = None,
        # Common parameters
        rational: bool = False,
        # Simplify parameters
        ratio: float = 1.7,
        measure=None,
        # Expand parameters
        deep: bool = True,
        modulus: Optional[int] = None,
        power_base: bool = True,
        power_exp: bool = True,
        mul: bool = True,
        log: bool = True,
        multinomial: bool = True,
        basic: bool = True,
        # Factor parameters
        frac: bool = False,
        sign: bool = False,
        # Collect parameters
        evaluate: bool = True,
        exact: bool = False,
    ) -> str:
        """
        Unified interface for algebra operations.
    
        Args:
            operation: The algebra operation to perform. One of:
                - 'simplify': Simplify the expression
                - 'expand': Expand the expression
                - 'factor': Factor the expression
                - 'collect': Collect terms with respect to symbols
            expr: The expression to process (string or SymPy expression)
            syms: Symbols to collect with respect to (only used for 'collect' operation)
            **kwargs: Additional arguments to pass to the underlying SymPy function
    
        Returns:
            str: The result of the operation as a string
    
        Examples:
            >>> algebra_operation('simplify', 'x**2 + 2*x + 1 + (x + 1)**2')
            '2*x**2 + 4*x + 2'
            >>> algebra_operation('collect', 'x*y + x - 3 + 2*x**2 - z*x**2 + x**3', 'x')
            'x**3 + x**2*(2 - z) + x*(y + 1) - 3'
        """
        # Convert string to SymPy expression if needed
        expr_obj = sympify(expr) if isinstance(expr, str) else expr
    
        # Process symbols if provided
        syms_list = None
        if syms is not None:
            if isinstance(syms, (str)):
                syms_list = [syms]
            elif isinstance(syms, list):
                syms_list = [sym for sym in syms]
    
        # Dispatch to the appropriate operation
        if operation == "simplify":
            return str(_simplify(expr_obj, ratio=ratio, measure=measure, rational=rational))
        elif operation == "expand":
            return str(
                _expand(
                    expr_obj,
                    deep=deep,
                    modulus=modulus,
                    power_base=power_base,
                    power_exp=power_exp,
                    mul=mul,
                    log=log,
                    multinomial=multinomial,
                    basic=basic,
                    **({"fraction": True} if rational else {}),
                )
            )
        elif operation == "factor":
            return str(
                _factor(
                    expr_obj,
                    frac=frac,
                    sign=sign,
                    **({"rational": True} if rational else {}),
                )
            )
        elif operation == "collect":
            if syms_list is None:
                raise ValueError("Symbols must be provided for 'collect' operation")
            return str(_collect(expr_obj, syms_list, evaluate=evaluate, exact=exact))
        else:
            valid_ops = get_args(AlgebraOperation)
            raise ValueError(f"Invalid operation. Must be one of: {valid_ops}")
  • Registers the algebra_operation handler as a tool in the FastMCP 'sympy_mcp' server, which names it 'sympy_mcp_algebra_operation'.
    sympy_mcp.tool(
        algebra_operation,
        description="Do algebraic operations like simplify, expand, factor, collect",
    )
  • Type definition for valid algebra operations used in the tool schema.
    # Define operation types for type hints
    AlgebraOperation = Literal["simplify", "expand", "factor", "collect"]
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions what operations are available but doesn't describe what these operations do, their mathematical effects, error conditions, performance characteristics, or output format. For a tool with 18 parameters and complex mathematical operations, this is a significant gap.

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 that directly states the tool's purpose. There's no wasted space or unnecessary elaboration. It's appropriately sized for what it does convey, though it's under-specified rather than concise.

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 (18 parameters, mathematical operations), lack of annotations, and 0% schema description coverage, the description is severely incomplete. While an output schema exists (which helps with return values), the description doesn't provide enough context about when to use which operation, what the parameters mean, or the mathematical behavior of the tool.

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 0% schema description coverage and 18 parameters (only 2 required), the description provides absolutely no information about parameters. It doesn't explain what 'expr' should contain, what 'syms' represents, or what any of the 16 optional parameters control. This 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.

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 algebraic operations and lists specific operations (simplify, expand, factor, collect), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like sympy_mcp_calculus_operation or sympy_mcp_equation_operation, which likely handle related 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. It doesn't mention when to choose algebraic operations over calculus or equation operations from sibling tools, nor does it specify prerequisites or exclusions for usage.

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