Skip to content

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 calculator

No flags, no permissions: it's pure compute, no I/O.

Tools

evaluate

FieldTypeRequiredDescription
expressionstringyesArithmetic 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 notation

Built-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

ExpressionResult
2 + 24
(7 - 3) * 520
2^101024
2^3^2512 (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

Released under the MIT License.