calculator
Evaluates a mathematical expression and returns the numeric result. Supports standard arithmetic operators, parentheses, and common mathematical functions.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
expression | string | Yes | The 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
| Expression | Result |
|---|---|
sqrt(2) * pi | 4.442882938158366 |
abs(-42) | 42.0 |
2^10 | 1024.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).
| Code | When | Delivered as |
|---|---|---|
invalid_arguments | An argument is missing or the wrong type. | protocol error (invalid_params) |
invalid_expression | The expression is malformed, references an unknown function, or produces a non-finite result (e.g. division by zero). | tool error (isError) |
internal_error | An unexpected server error. | protocol error (internal_error) |
Notes
- Results are always returned as a 64-bit floating-point number. Integer expressions like
2 + 2return4.0, not4. - The evaluator is stateless — each call is independent with no variable persistence between calls.