Skip to main content
Glama
by apetta

integral

Compute symbolic and numerical integrals to find antiderivatives or calculate areas under curves. Supports definite and indefinite integration with exact or approximate 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

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

Input Schema (JSON Schema)

{ "properties": { "context": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification." }, "expression": { "description": "Mathematical expression to integrate (e.g., 'x^2', 'sin(x)')", "minLength": 1, "type": "string" }, "lower_bound": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Lower bound for definite integral (omit for indefinite)" }, "method": { "default": "symbolic", "description": "Integration method: symbolic=exact/analytical, numerical=approximate (requires bounds)", "enum": [ "symbolic", "numerical" ], "type": "string" }, "output_mode": { "default": "full", "description": "Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details.", "enum": [ "full", "compact", "minimal", "value", "final" ], "type": "string" }, "upper_bound": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Upper bound for definite integral (omit for indefinite)" }, "variable": { "description": "Integration variable (e.g., 'x', 't')", "minLength": 1, "type": "string" } }, "required": [ "expression", "variable" ], "type": "object" }

Implementation Reference

  • The main handler function implementing symbolic (SymPy integrate) and numerical (SciPy quad) integration for definite and indefinite integrals. Handles metadata and formatting.
    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: """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" )
  • Pydantic-based schema definition via @mcp.tool decorator, including input parameters (expression, variable, bounds, method), detailed description with 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, ), )
  • Tool registration via the @mcp.tool decorator on the handler function.
    @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, ), )
  • Import of the 'calculus' module in server.py, which triggers automatic registration of all decorated tools including 'integral' via MCP decorators.
    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