Skip to main content
Glama
apetta
by apetta

integral

Compute symbolic and numerical integrals to find antiderivatives or calculate areas under curves. Supports definite and indefinite integration with exact analytical or approximate numerical methods.

Instructions

Compute symbolic and numerical integrals (definite and indefinite).

Examples:

INDEFINITE INTEGRAL (antiderivative): expression="x^2", variable="x" Result: "x^3/3"

DEFINITE INTEGRAL (area): expression="x^2", variable="x", lower_bound=0, upper_bound=1 Result: 0.333

TRIGONOMETRIC: expression="sin(x)", variable="x", lower_bound=0, upper_bound=3.14159 Result: 2.0 (area under one period)

NUMERICAL METHOD (non-elementary): expression="exp(-x^2)", variable="x", lower_bound=0, upper_bound=1, method="numerical" Result: 0.746824 (Gaussian integral approximation)

SYMBOLIC ANTIDERIVATIVE: expression="1/x", variable="x" Result: "log(x)"

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 integrate (e.g., 'x^2', 'sin(x)')
variableYesIntegration variable (e.g., 'x', 't')
lower_boundNoLower bound for definite integral (omit for indefinite)
upper_boundNoUpper bound for definite integral (omit for indefinite)
methodNoIntegration method: symbolic=exact/analytical, numerical=approximate (requires bounds)symbolic

Implementation Reference

  • MCP tool registration decorator for the 'integral' tool, defining name, detailed description with usage examples, and tool annotations.
    @mcp.tool( name="integral", description="""Compute symbolic and numerical integrals (definite and indefinite). Examples: INDEFINITE INTEGRAL (antiderivative): expression="x^2", variable="x" Result: "x^3/3" DEFINITE INTEGRAL (area): expression="x^2", variable="x", lower_bound=0, upper_bound=1 Result: 0.333 TRIGONOMETRIC: expression="sin(x)", variable="x", lower_bound=0, upper_bound=3.14159 Result: 2.0 (area under one period) NUMERICAL METHOD (non-elementary): expression="exp(-x^2)", variable="x", lower_bound=0, upper_bound=1, method="numerical" Result: 0.746824 (Gaussian integral approximation) SYMBOLIC ANTIDERIVATIVE: expression="1/x", variable="x" Result: "log(x)" """, annotations=ToolAnnotations( title="Integral Calculator", readOnlyHint=True, idempotentHint=True, ), )
  • Input schema using Pydantic Annotated Fields defining parameters for the integral tool: expression, variable, optional bounds for definite integrals, and method (symbolic or numerical).
    async def integral( expression: Annotated[ str, Field( description="Mathematical expression to integrate (e.g., 'x^2', 'sin(x)')", min_length=1 ), ], variable: Annotated[ str, Field(description="Integration variable (e.g., 'x', 't')", min_length=1) ], lower_bound: Annotated[ float | None, Field(description="Lower bound for definite integral (omit for indefinite)") ] = None, upper_bound: Annotated[ float | None, Field(description="Upper bound for definite integral (omit for indefinite)") ] = None, method: Annotated[ Literal["symbolic", "numerical"], Field( description="Integration method: symbolic=exact/analytical, numerical=approximate (requires bounds)" ), ] = "symbolic", ) -> str:
  • Core execution logic of the integral tool: parses expression with SymPy, computes symbolic integrals (definite/indefinite) using integrate(), numerical using SciPy quad(), builds metadata, formats result, handles errors.
    """Compute integrals using SymPy (symbolic/exact) or SciPy (numerical/approximate). Supports indefinite (antiderivatives) and definite (area) integrals.""" try: expr = sympify(expression) var = Symbol(variable) is_definite = lower_bound is not None and upper_bound is not None if method == "symbolic": if is_definite: # Definite symbolic integral result = integrate(expr, (var, lower_bound, upper_bound)) numeric_value = float(N(result)) metadata = { "expression": expression, "variable": variable, "lower_bound": lower_bound, "upper_bound": upper_bound, "symbolic_result": str(result), "type": "definite", } return format_result(numeric_value, metadata) else: # Indefinite symbolic integral result = integrate(expr, var) antiderivative_str = str(result) metadata = { "expression": expression, "variable": variable, "type": "indefinite", } return format_result(antiderivative_str, metadata) elif method == "numerical": if not is_definite: raise ValueError("Numerical integration requires lower_bound and upper_bound") # Convert SymPy expression to numeric function func = lambdify(var, expr, "numpy") # Use SciPy's quad for numerical integration result, error = integrate_numeric.quad(func, lower_bound, upper_bound) metadata = { "expression": expression, "variable": variable, "lower_bound": lower_bound, "upper_bound": upper_bound, "error_estimate": float(error), "method": "numerical", "type": "definite", } return format_result(float(result), metadata) else: raise ValueError(f"Unknown method: {method}") except Exception as e: raise ValueError( f"Integration failed: {str(e)}. " f"Example: expression='x^2', variable='x', lower_bound=0, upper_bound=1" )

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