calculator
Safe arithmetic expression evaluator. Useful for models that hallucinate basic math. The parser is hand-rolled — there is no eval, no Go AST, no string-to-code path.
Usage
bash
native-mcp calculatorNo flags, no permissions: it's pure compute, no I/O.
Tools
evaluate
| Field | Type | Required | Description |
|---|---|---|---|
expression | string | yes | Arithmetic expression to evaluate. |
Returns the numeric result as text. Integer results are formatted without a decimal point; floats use Go's shortest-round-trip representation.
Grammar
text
+ - * / % binary
^ ** power (right-associative)
+ - unary
( ... ) grouping
1.5e2 scientific notationBuilt-in functions
abs, sqrt, pow(x, y), exp, ln (alias log), log10, log2, sin, cos, tan, floor, ceil, round, min(a, b, ...), max(a, b, ...).
Built-in constants
pi, e, inf, nan.
Examples
| Expression | Result |
|---|---|
2 + 2 | 4 |
(7 - 3) * 5 | 20 |
2^10 | 1024 |
2^3^2 | 512 (right-assoc, = 2^9) |
sqrt(2) | 1.4142135623730951 |
sin(pi/2) | 1 |
min(1, -3, 4) | -3 |
Errors
The tool returns an isError: true result for:
- Empty or syntactically invalid expressions
- Division or modulo by zero
- Unknown identifiers or functions
- Wrong arity on a built-in function
Register in Claude Code
bash
claude mcp add native-calc native-mcp calculator