Skip to main content

calculator

Evaluates a mathematical expression and returns the numeric result. Supports standard arithmetic operators, parentheses, and common mathematical functions.

Parameters​

ParameterTypeRequiredDescription
expressionstringYesThe mathematical expression to evaluate.

Supported syntax​

  • Arithmetic: +, -, *, /, ^ (power)
  • Parentheses for grouping: (2 + 3) * 4
  • Functions: sqrt, abs, sin, cos, tan, log, exp, floor, ceil
  • Constants: pi, e

Example​

{
"expression": "2 + 2 * (3 - 1)"
}

Result:

{
"result": 6.0,
"expression": "2 + 2 * (3 - 1)"
}

More examples​

ExpressionResult
sqrt(2) * pi4.442882938158366
abs(-42)42.0
2^101024.0
log(e)1.0
floor(3.9)3.0

Errors​

Each failure carries a precise code in the response. Argument-schema and server errors are JSON-RPC protocol errors; a rejected value is returned as a tool result with isError: true (so the agent can read the code and self-correct).

CodeWhenDelivered as
invalid_argumentsAn argument is missing or the wrong type.protocol error (invalid_params)
invalid_expressionThe expression is malformed, references an unknown function, or produces a non-finite result (e.g. division by zero).tool error (isError)
internal_errorAn unexpected server error.protocol error (internal_error)

Notes​

  • Results are always returned as a 64-bit floating-point number. Integer expressions like 2 + 2 return 4.0, not 4.
  • The evaluator is stateless — each call is independent with no variable persistence between calls.