Skip to main content
Glama
apetta

Vibe Math MCP

by apetta

limits_series

Compute limits and generate series expansions for mathematical expressions using SymPy. Analyze function behavior at points, including infinity, and create Taylor/Maclaurin expansions.

Instructions

Compute limits and series expansions using SymPy.

Examples:

CLASSIC LIMIT: expression="sin(x)/x", variable="x", point=0, operation="limit" Result: limit=1

LIMIT AT INFINITY: expression="1/x", variable="x", point="oo", operation="limit" Result: limit=0

ONE-SIDED LIMIT: expression="1/x", variable="x", point=0, operation="limit", direction="+" Result: limit=+∞ (approaching from right)

REMOVABLE DISCONTINUITY: expression="(x^2-1)/(x-1)", variable="x", point=1, operation="limit" Result: limit=2

MACLAURIN SERIES (at 0): expression="exp(x)", variable="x", point=0, operation="series", order=4 Result: "1 + x + x^2/2 + x^3/6 + O(x^4)"

TAYLOR SERIES (at point): expression="sin(x)", variable="x", point=3.14159, operation="series", order=4 Result: expansion around π

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextNoOptional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification.
output_modeNoOutput format: full (default), compact, minimal, value, or final. See batch_execute tool for details.full
expressionYesMathematical expression to analyse (e.g., 'sin(x)/x', 'exp(x)')
variableYesVariable for limit/expansion (e.g., 'x', 't')
pointYesPoint for limit/expansion (number, 'oo' for infinity, '-oo' for -infinity)
operationNoOperation: limit=compute limit, series=Taylor/Maclaurin expansionlimit
orderNoSeries expansion order (number of terms)
directionNoLimit direction: +=from right, -=from left, +-=both sides+-

Implementation Reference

  • The async handler function that implements the core logic for the 'limits_series' tool using SymPy's limit and series functions. Handles limits at points, infinity, one-sided limits, and Taylor series expansions.
    async def limits_series(
        expression: Annotated[
            str,
            Field(
                description="Mathematical expression to analyse (e.g., 'sin(x)/x', 'exp(x)')",
                min_length=1,
            ),
        ],
        variable: Annotated[
            str, Field(description="Variable for limit/expansion (e.g., 'x', 't')", min_length=1)
        ],
        point: Annotated[
            Union[float, str],
            Field(
                description="Point for limit/expansion (number, 'oo' for infinity, '-oo' for -infinity)"
            ),
        ],
        operation: Annotated[
            Literal["limit", "series"],
            Field(description="Operation: limit=compute limit, series=Taylor/Maclaurin expansion"),
        ] = "limit",
        order: Annotated[int, Field(description="Series expansion order (number of terms)", ge=1)] = 6,
        direction: Annotated[
            Literal["+", "-", "+-"],
            Field(description="Limit direction: +=from right, -=from left, +-=both sides"),
        ] = "+-",
    ) -> str:
        """Compute limits (lim[x→a]f(x)) and Taylor/Maclaurin series expansions using SymPy. Handles infinity, one-sided limits, removable discontinuities."""
        try:
            expr = sympify(expression)
            var = Symbol(variable)
    
            # Handle infinity
            if point == "oo" or point == "inf":
                point_sym = oo
            elif point == "-oo" or point == "-inf":
                point_sym = -oo
            else:
                point_sym = float(point)
    
            if operation == "limit":
                if direction == "+-":
                    # Two-sided limit
                    result = limit(expr, var, point_sym)
                else:
                    # One-sided limit
                    result = limit(expr, var, point_sym, direction)
    
                # Limit value is the primary result
                limit_str = str(result)
                metadata = {
                    "expression": expression,
                    "variable": variable,
                    "point": str(point),
                    "direction": direction,
                    "numeric_value": float(N(result)) if result.is_number else None,
                }
                return format_result(limit_str, metadata)
    
            elif operation == "series":
                # Series expansion
                series_expr = series(expr, var, point_sym, order)  # type: ignore[arg-type]
                series_str = str(series_expr)
    
                # Remove O() term for cleaner output
                series_no_o = series_expr.removeO()
    
                # Series string is the primary result
                metadata = {
                    "expression": expression,
                    "variable": variable,
                    "point": str(point),
                    "order": order,
                    "series_without_O": str(series_no_o),
                }
                return format_result(series_str, metadata)
    
            else:
                raise ValueError(f"Unknown operation: {operation}")
    
        except Exception as e:
            raise ValueError(
                f"Limit/series calculation failed: {str(e)}. "
                f"Example: expression='sin(x)/x', variable='x', point=0, operation='limit'"
            )
  • The @mcp.tool decorator defining the tool schema, including name, description, annotations, and parameter types/validations for inputs like expression, variable, point, operation, order, and direction.
    @mcp.tool(
        name="limits_series",
        description="""Compute limits and series expansions using SymPy.
    
    Examples:
    
    CLASSIC LIMIT:
        expression="sin(x)/x", variable="x", point=0, operation="limit"
        Result: limit=1
    
    LIMIT AT INFINITY:
        expression="1/x", variable="x", point="oo", operation="limit"
        Result: limit=0
    
    ONE-SIDED LIMIT:
        expression="1/x", variable="x", point=0, operation="limit", direction="+"
        Result: limit=+∞ (approaching from right)
    
    REMOVABLE DISCONTINUITY:
        expression="(x^2-1)/(x-1)", variable="x", point=1, operation="limit"
        Result: limit=2
    
    MACLAURIN SERIES (at 0):
        expression="exp(x)", variable="x", point=0, operation="series", order=4
        Result: "1 + x + x^2/2 + x^3/6 + O(x^4)"
    
    TAYLOR SERIES (at point):
        expression="sin(x)", variable="x", point=3.14159, operation="series", order=4
        Result: expansion around π""",
        annotations=ToolAnnotations(
            title="Limits and Series",
            readOnlyHint=True,
            idempotentHint=True,
        ),
    )
  • Import of the 'calculus' module in server.py, which triggers the registration of the limits_series tool via its @mcp.tool decorator.
    from .tools import array, basic, batch, calculus, financial, linalg, statistics  # noqa: E402

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/apetta/vibe-math-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server