sympy_count_ops
Count the number of operations in a symbolic expression to evaluate its complexity.
Instructions
Count operations.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expr | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_sympy/tools.py:2394-2397 (handler)The handler function for the sympy_count_ops tool. Takes a string expression, converts it to a SymPy object via _sympify(), counts operations with sympy.count_ops(), and returns the result as a string.
@mcp.tool() def sympy_count_ops(expr: str) -> str: """Count operations.""" return str(sympy.count_ops(_sympify(expr))) - src/mcp_sympy/tools.py:2394-2397 (registration)The tool is registered using the @mcp.tool() decorator on the function, where mcp = fastmcp.FastMCP('mcp-sympy') is the FastMCP instance defined at line 119.
@mcp.tool() def sympy_count_ops(expr: str) -> str: """Count operations.""" return str(sympy.count_ops(_sympify(expr))) - src/mcp_sympy/tools.py:2395-2397 (schema)The schema is inferred from the function signature: takes a single string parameter 'expr' and returns a string.
def sympy_count_ops(expr: str) -> str: """Count operations.""" return str(sympy.count_ops(_sympify(expr))) - src/mcp_sympy/tools.py:114-116 (helper)Helper function _sympify() converts a string expression to a SymPy Basic object, used by the handler to parse input.
def _sympify(expr: str) -> sympy.Basic: """Convert string expression to SymPy object.""" return sympy.sympify(expr)