sympy_python_code
Convert SymPy expressions into executable Python code for direct use in scripts or applications.
Instructions
Convert expression to Python code.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expr | Yes | SymPy expression string |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_sympy/tools.py:826-840 (handler)The handler function for the 'sympy_python_code' tool. It is decorated with @mcp.tool() (registration), takes a string expression, sympifies it, and returns the Python code representation via sympy.python().
@mcp.tool() def sympy_python_code(expr: str) -> str: """Convert expression to Python code. Args: expr: SymPy expression string Returns: Python code string Example: >>> sympy_python_code("x**2 + 1") "x**2 + 1" """ return str(sympy.python(_sympify(expr))) - src/mcp_sympy/tools.py:119-119 (registration)The MCP server instance (FastMCP) that the @mcp.tool() decorator registers the handler with.
mcp = fastmcp.FastMCP("mcp-sympy") - src/mcp_sympy/tools.py:114-116 (helper)The _sympify helper function that converts a string expression into a SymPy object, used by the handler.
def _sympify(expr: str) -> sympy.Basic: """Convert string expression to SymPy object.""" return sympy.sympify(expr)