sympy_matrix
Construct a matrix by specifying rows separated by semicolons, enabling symbolic mathematical operations.
Instructions
Create a matrix from rows.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | Yes | Semicolon-separated rows, e.g., "1,2; 3,4" |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_sympy/tools.py:585-601 (handler)Handler function for the 'sympy_matrix' tool. Takes a semicolon-separated string of rows, splits into a 2D list of integers, and creates a sympy Matrix, returning it as a string.
@mcp.tool() def sympy_matrix(rows: str) -> str: """Create a matrix from rows. Args: rows: Semicolon-separated rows, e.g., "1,2; 3,4" Returns: Matrix as string Example: >>> sympy_matrix("1,2; 3,4") "Matrix([[1, 2], [3, 4]])" """ row_list = [r.split(",") for r in rows.split(";")] matrix_data = [[int(x.strip()) for x in row] for row in row_list] return str(Matrix(matrix_data)) - src/mcp_sympy/tools.py:585-585 (registration)The @mcp.tool() decorator registers 'sympy_matrix' as a FastMCP tool on the 'mcp-sympy' server.
@mcp.tool() - src/mcp_sympy/tools.py:119-119 (registration)The 'mcp' FastMCP server instance used to register all tools via the @mcp.tool() decorator.
mcp = fastmcp.FastMCP("mcp-sympy") - src/mcp_sympy/tools.py:1-2 (helper)Module docstring and imports. The 'sympy_matrix' handler uses 'Matrix' imported from sympy on line 26.
"""MCP tools that expose SymPy's symbolic mathematics functionality.""" - tests/test_tools.py:111-114 (helper)Test for sympy_matrix creation, verifying the output contains 'Matrix'.
def test_matrix_creation(self): """Test matrix creation.""" result = tools.sympy_matrix("1,2; 3,4") assert "Matrix" in result