sympy_derivative
Differentiate a symbolic expression with respect to a variable, with optional order, returning an unevaluated Derivative object.
Instructions
Create a Derivative object (unevaluated).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expr | Yes | String expression | |
| variable | Yes | Variable to differentiate | |
| order | No | Order of derivative |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_sympy/tools.py:545-562 (handler)The handler function for the sympy_derivative tool. It converts string expression and variable to SymPy objects and creates an unevaluated Derivative object.
def sympy_derivative(expr: str, variable: str, order: int = 1) -> str: """Create a Derivative object (unevaluated). Args: expr: String expression variable: Variable to differentiate order: Order of derivative Returns: Derivative object as string Example: >>> sympy_derivative("x**2", "x") "Derivative(x**2, x)" """ var = sympy.Symbol(variable) result = Derivative(_sympify(expr), var, order) return str(result) - src/mcp_sympy/tools.py:544-544 (registration)Registration of the sympy_derivative function as an MCP tool via @mcp.tool() decorator on line 544.
@mcp.tool() - src/mcp_sympy/tools.py:114-116 (helper)The _sympify helper function used inside sympy_derivative 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:545-562 (schema)The type annotations (expr: str, variable: str, order: int = 1) serve as the input schema for the tool.
def sympy_derivative(expr: str, variable: str, order: int = 1) -> str: """Create a Derivative object (unevaluated). Args: expr: String expression variable: Variable to differentiate order: Order of derivative Returns: Derivative object as string Example: >>> sympy_derivative("x**2", "x") "Derivative(x**2, x)" """ var = sympy.Symbol(variable) result = Derivative(_sympify(expr), var, order) return str(result)