Skip to main content
Glama
by apetta

derivative

Compute symbolic and numerical derivatives for mathematical expressions, including higher-order and partial derivatives, with optional point evaluation.

Instructions

Compute symbolic and numerical derivatives with support for higher orders and partial derivatives.

Examples:

FIRST DERIVATIVE: expression="x^3 + 2x^2", variable="x", order=1 Result: derivative="3x^2 + 4*x"

SECOND DERIVATIVE (acceleration/concavity): expression="x^3", variable="x", order=2 Result: derivative="6*x"

EVALUATE AT POINT: expression="sin(x)", variable="x", order=1, point=0 Result: derivative="cos(x)", value_at_point=1.0

PRODUCT RULE: expression="sin(x)*cos(x)", variable="x", order=1 Result: derivative="cos(x)^2 - sin(x)^2"

PARTIAL DERIVATIVE: expression="x^2*y", variable="y", order=1 Result: derivative="x^2" (treating x as constant)

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 differentiate (e.g., 'x^3 + 2*x^2', 'sin(x)')
variableYesVariable to differentiate with respect to (e.g., 'x', 't')
orderNoDerivative order (1=first derivative, 2=second, etc.)
pointNoOptional point for numerical evaluation of the derivative

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 differentiate (e.g., 'x^3 + 2*x^2', 'sin(x)')", "minLength": 1, "type": "string" }, "order": { "default": 1, "description": "Derivative order (1=first derivative, 2=second, etc.)", "minimum": 1, "type": "integer" }, "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" }, "point": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "description": "Optional point for numerical evaluation of the derivative" }, "variable": { "description": "Variable to differentiate with respect to (e.g., 'x', 't')", "minLength": 1, "type": "string" } }, "required": [ "expression", "variable" ], "type": "object" }

Implementation Reference

  • The complete 'derivative' tool implementation: @mcp.tool decorator registers the tool with schema and description; async handler uses SymPy (sympify, Symbol, diff, N, subs) to compute symbolic derivative of specified order w.r.t. variable, optionally evaluates numerically at point, returns formatted string with metadata.
    @mcp.tool( name="derivative", description="""Compute symbolic and numerical derivatives with support for higher orders and partial derivatives. Examples: FIRST DERIVATIVE: expression="x^3 + 2*x^2", variable="x", order=1 Result: derivative="3*x^2 + 4*x" SECOND DERIVATIVE (acceleration/concavity): expression="x^3", variable="x", order=2 Result: derivative="6*x" EVALUATE AT POINT: expression="sin(x)", variable="x", order=1, point=0 Result: derivative="cos(x)", value_at_point=1.0 PRODUCT RULE: expression="sin(x)*cos(x)", variable="x", order=1 Result: derivative="cos(x)^2 - sin(x)^2" PARTIAL DERIVATIVE: expression="x^2*y", variable="y", order=1 Result: derivative="x^2" (treating x as constant)""", annotations=ToolAnnotations( title="Derivative Calculator", readOnlyHint=True, idempotentHint=True, ), ) async def derivative( expression: Annotated[ str, Field( description="Mathematical expression to differentiate (e.g., 'x^3 + 2*x^2', 'sin(x)')", min_length=1, ), ], variable: Annotated[ str, Field( description="Variable to differentiate with respect to (e.g., 'x', 't')", min_length=1 ), ], order: Annotated[ int, Field(description="Derivative order (1=first derivative, 2=second, etc.)", ge=1) ] = 1, point: Annotated[ float | None, Field(description="Optional point for numerical evaluation of the derivative") ] = None, ) -> str: """Compute symbolic derivatives using SymPy. Supports higher orders and partial derivatives. Optional numerical evaluation at a point.""" try: expr = sympify(expression) var = Symbol(variable) # Compute derivative derivative_expr = diff(expr, var, order) derivative_str = str(derivative_expr) # Build metadata metadata = { "expression": expression, "variable": variable, "order": order, } # Evaluate at point if provided if point is not None: value = float(N(derivative_expr.subs(var, point))) metadata["value_at_point"] = value metadata["point"] = point return format_result(derivative_str, metadata) except Exception as e: raise ValueError( f"Derivative calculation failed: {str(e)}. Example: expression='x^2', variable='x'" )
  • Imports the calculus.py module, triggering registration of the 'derivative' tool via its @mcp.tool decorator.
    from . import calculus
  • Imports tools.calculus in server.py, ensuring the 'derivative' tool is registered on the MCP server instance.
    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