sympy_piecewise
Define piecewise functions by specifying expression-condition pairs separated by semicolons.
Instructions
Create piecewise function (format: "expr,condition; expr2,condition2").
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pairs | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_sympy/tools.py:2233-2240 (handler)The handler function for the sympy_piecewise tool. Parses a semicolon-separated list of 'expr,condition' pairs, sympifies each, and constructs a SymPy Piecewise object.
@mcp.tool() def sympy_piecewise(pairs: str) -> str: """Create piecewise function (format: "expr,condition; expr2,condition2").""" pieces = [] for pair in pairs.split(";"): expr_str, cond = pair.split(",") pieces.append((_sympify(expr_str.strip()), _sympify(cond.strip()))) return str(Piecewise(*pieces)) - src/mcp_sympy/tools.py:2233-2234 (registration)Registration via the @mcp.tool() decorator on the FastMCP instance 'mcp' at line 119.
@mcp.tool() def sympy_piecewise(pairs: str) -> str: - src/mcp_sympy/tools.py:114-116 (helper)Helper function used by the handler to convert string expressions to SymPy objects.
def _sympify(expr: str) -> sympy.Basic: """Convert string expression to SymPy object.""" return sympy.sympify(expr) - src/mcp_sympy/tools.py:2234-2240 (schema)Input schema: a single string parameter 'pairs'. Output: a string (the string representation of the Piecewise object).
def sympy_piecewise(pairs: str) -> str: """Create piecewise function (format: "expr,condition; expr2,condition2").""" pieces = [] for pair in pairs.split(";"): expr_str, cond = pair.split(",") pieces.append((_sympify(expr_str.strip()), _sympify(cond.strip()))) return str(Piecewise(*pieces))