A Rust port of calc (Landon Curt Noll's arbitrary-precision calculator)
LocalAbout A Rust port of calc (Landon Curt Noll's arbitrary-precision calculator)
toRustCalcMCP is a Rust port of calc for users needing arbitrary-precision calculations through a CLI, browser REPL, or MCP. Its shared engine uses exact rational arithmetic.
Key features
- 01Exact rational arithmetic
- 02calc-compatible CLI
- 03Browser-based Web REPL
- 04MCP calculation tools
- 05Functions, variables, and control flow
- 06Complex numbers and lists
Use cases
- 01Evaluating high-precision expressions
- 02Using a calculator from an MCP client
- 03Interactive calculations in a browser
MCP support
Provides an MCP server using JSON-RPC 2.0 over stdio. Clients can evaluate expressions, configure session precision and display, and list built-in functions.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
docker run -i --rm ghcr.io/carlomagnoglobal/torustcalcmcp:latestLocal servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.
ghcr.io/carlomagnoglobal/torustcalcmcp:lateststdioTools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEtoRustCalcMCP
A Rust port of calc (Landon Curt Noll's
arbitrary-precision calculator) that works as:
rcalc— a calc-compatible command-line calculator- Web REPL — browser-based interactive calculator
- MCP server — JSON-RPC 2.0 over stdio for LLM/agent integration
Three interfaces, one engine. The numeric core uses exact rational arithmetic
(num-rational over num-bigint), which is the same model calc uses natively —
so 1/3 * 3 is exactly 1, and 2^256 is computed to the last digit.
👉 Getting Started in 2 minutes — new to rcalc? Start here. 👉 Install as Claude Desktop MCP — integrate with Claude Desktop.
Build
cargo build --release
# binaries:
# target/release/toRustCalcMCP (auto-detects MCP vs CLI)
# target/release/rcalc (always the CLI)
Optionally symlink: ln -s toRustCalcMCP rcalc — when argv[0] is rcalc,
toRustCalcMCP behaves as the calculator.
CLI usage (rcalc)
rcalc '2^100' # 1267650600228229401496703205376
rcalc '1/3 + 1/6' # 0.5
rcalc -m frac '1/3 + 1/6' # 1/2
rcalc 'gcd(462,1071)' # 21
rcalc 'fact(30)' # 265252859812191058636308480000000
rcalc 'sqrt(2)' # 1.4142135623730950488
rcalc 'isprime(1000003)' 'nextprime(1000003)' # 1 \n 1000033
echo '3*4' | rcalc -p # pipe mode
rcalc # interactive REPL (Ctrl-D to exit)
Flags: -p pipe mode, -q quiet, -m real|frac|int, -v version, -h help.
Several classic calc flags (-c -C -d -e -i -O -s -u) are accepted and ignored.
Web REPL usage
cargo build --release
./target/release/rcalc-web
# Open browser: http://localhost:8888
A modern browser-based REPL with:
- Interactive expression evaluation
- Command history (↑/↓ arrow keys)
- Syntax-highlighted output
- Full calc functionality (483 builtin names)
- Responsive design for mobile/desktop
Try it: open http://localhost:8888 and enter 2^256 or sin(pi()/6).
MCP usage
toRustCalcMCP --mcp # speak JSON-RPC 2.0 over stdio
Handshake → initialize, then tools/list, then tools/call. See
docs/MCP_TOOL_SCHEMA.json for the authoritative,
server-emitted schema and examples/mcp-config.json
for a client registration snippet.
Tools
| tool | purpose | key args |
|---|---|---|
calc_eval | evaluate an expression | expression (req), mode, digits, epsilon |
calc_config | get/set session precision & display | action (get/set), mode, digits, epsilon |
calc_functions | list builtins | filter (optional substring) |
calc_eval's mode/digits/epsilon are per-call overrides; calc_config set
changes them for the session.
Language supported
- Operators:
+ - * /(exact),//(integer divide),%(modulus),^/**(power), comparisons== != < <= > >=(yield1/0), unary-/+. - Variables and assignment:
x = 7; x^2. - User-defined functions:
define f(x) = x^2; f(5)→25. - Control flow:
if/else,while,forloops, blocks with{}. ;-separated statements; the value of each is printed (calc behaviour).- Numeric literals: integers,
a/brationals, decimals,1.2e-3,0x/0b. - Lists:
list(1,2,3); append(x,4); slice(x,1,3). - Complex numbers:
sqrt(-1)→i; arithmetic with+,-,*,/. - String literals:
"hello"; strlen(s); index(haystack, needle). - 483 builtin names (full parity with calc's 350, minus 15 documented interpreter internals, plus extensions) — see implementation status below.
Precision model
Numbers are exact rationals. Irrational results are approximated to within the
session epsilon (default exact 1/10^20), exactly like calc. Transcendentals (exp,
ln, sin, cos, tan) are computed at arbitrary precision via Taylor series
and Newton's method. sqrt, sin, cos, etc. converge until term < epsilon.
pi/e are 60-digit constants. A leading ~ in real-mode output marks an
inexact (rounded/non-terminating) rendering, as in calc.
Implementation Status — full upstream parity ✅
calc upstream (lcn2/calc func.c) defines 350 builtins. This port registers
483 builtin names covering 335 of the 350 upstream builtins (the other
148 that were long missing were added in the upstream-parity batches below),
plus dozens of extensions and aliases beyond upstream (statistics, hashing,
bit tricks, system info, and more).
Intentionally not implemented (15 interpreter internals)
These upstream names are artifacts of calc's C interpreter and have no meaningful mapping to this port's architecture; they remain unimplemented rather than shipping fake stubs:
access, calc_tty, calclevel, calcpath, custom, dp, estr,
inputlevel, memsize, name, param, prompt, protect, saveval,
stoponerror
Known deviations from upstream
- Out-parameter builtins return values instead:
d2dm/d2dms(and the g/h family) return[deg, min]/[deg, min, sec]lists;quomodreturns[q, r];search/rsearchreturn an index or null. - In-place/lvalue builtins return new values:
modify,copy,swap(builtins receive values, not references). base2()reads as 0 (no secondary base); setting it errors — the renderer has a single output base.free*()are no-ops: nothing is cached, values are computed on demand.
Full language features
- ✅ User-defined functions (
define name(params) = expr), higher-order builtins (select/forall/modifycall function values) - ✅ Control flow (
if/else,while,forloops) - ✅ Variables and scoping
- ✅ Lists and indexing (0-based, negative indices supported)
- ✅ Complex numbers with full arithmetic
- ✅ String literals and a complete string-function suite
- ✅ Base conversion (2-36, input and output)
- ✅ Arbitrary-precision arithmetic (exact rationals; exact 1/10^20 epsilon)
- ✅ File loading (
-f filename), file I/O builtins, REPL, pipe mode
Scope — Architecture & Design
calc upstream is ~92,000 lines of C with ~350 builtins and a full, Turing-complete scripting language. This port is a faithful core, structured for incremental, additive expansion:
- ✅ Exact-rational numeric engine — matches calc's native model
- ✅ Complete lexer/parser — handles the full expression syntax
- ✅ Tree-walk evaluator — with user-defined functions, control flow, scoping
- ✅ Builtin registry — extensible function map with auto-cataloging
- ✅ CLI & MCP server — two front-ends, one engine
- 🔄 Incremental builtins — each category slots in cleanly without rework
The architecture is stable; adding more functions is straightforward.
License
LGPL-2.1, matching calc upstream.
Test CI workflow
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.