What exact-calc MCP server does
The exact-calc MCP server gives AI agents a deterministic arithmetic service over MCP and the command line. It handles expressions such as 0.1 + 0.2, 1/3, powers, square roots, logarithms, and comparisons without relying on ordinary binary floating-point behavior.
Results use a rational Fraction domain when possible. Expressions that require non-rational values, such as sqrt(2), pi, or logarithms, fall back to Decimal with configurable precision. The response reports the value, numeric domain, exactness information, and the outcome of available checks.
How it works
Expressions are parsed into a Python AST and evaluated node by node. Only the supported operators, constants, and function names are accepted; constructs such as attribute access, indexing, lambdas, conditionals, and comprehensions are rejected. This avoids evaluating arbitrary Python code.
Numeric literals are recovered from the original expression text before conversion. For example, the text 0.1 is passed to Decimal as a decimal string rather than being reused as an already-rounded Python float.
The Python implementation first attempts exact rational arithmetic and automatically changes to decimal arithmetic when necessary. A separately implemented C++ parser provides an independent numerical check. The C++ path uses long double, so it checks agreement in scale and significant digits rather than establishing the primary exact result. If the engines disagree, the response reports the discrepancy instead of silently returning an unchecked value.
Setup and configuration
Install the package with pip install -e ., or run it without a local installation through uvx:
uvx --from git+https://github.com/flacales/exact-calc-mcp exact-calc --serve
A locally installed process can also start the MCP service with python -m exact_calc_mcp --serve. The package depends on the official MCP SDK version 1.x (mcp>=1.0.0,<2.0.0). The C++ engine is optional; if a compiler is unavailable, the Python implementation remains usable.
MCP clients configure the service as a stdio process. The README provides configurations for Claude Desktop, Claude Code, Cursor, VS Code, Codex, Cline, and Continue. For clients that do not use uvx, replace the command with python and run the installed module.
Tools and capabilities
The exact-calc MCP server exposes these MCP tools:
calculate(expression, precision=50): evaluates an expression and returns the value plus verification details.
verify(expression, precision=50): returns a trust judgment before the calculation details.
are_equal(left, right, precision=50): tests whether two expressions are mathematically equal.
to_fraction(decimal_string): converts a decimal string to an exact fraction.
engine_status(): reports the status of the available engines.
Supported syntax includes +, -, *, /, //, %, **, parentheses, and functions including sqrt, abs, round, min, max, factorial, gcd, lcm, ln, log, log10, exp, and pow. Constants include pi and e. Operator precedence follows Python, while round uses away-from-zero rounding and log(x) means the natural logarithm.
The command-line interface supports direct calculation, JSON output, expression comparison, decimal-to-fraction conversion, and engine diagnostics. This makes the tool usable by shell-capable agents even when an MCP client is not available.
Limitations and notes
Complex numbers are not supported, so sqrt(-1) fails. Trigonometric and hyperbolic functions are not implemented. The Python and C++ engines intentionally differ for modulo operations involving negative operands, which can produce a reported verification mismatch. C++ validation is limited by approximately 18–19 significant decimal digits. Hexadecimal literals are accepted by the Python path but not by the C++ checker.