rMath MCPサーバー
コミット 2026年11月8日Enables an AI client to perform symbolic mathematics, calculus, and algebraic computations using a Rust-based CAS kernel.
別名 thread3d/rMath
- スター
- 0
- ツール
- —
- ダウンロード数(30日間)
- —
- 最新バージョン
- —
- 最終コミット
- 2026年11月8日
- ライセンス
- MIT
rMath MCPとは
Enables an AI client to perform symbolic mathematics, calculus, and algebraic computations using a Rust-based CAS kernel.
プロジェクトのREADMEから生成された概要
rMath MCP server について
Performing symbolic mathematics, calculus, and algebraic computations is what rMath enables for developers using an AI client. This system provides a Mathematica-style experience through a symbolic kernel written in Rust, which handles expression engines, pattern matching, and exact arithmetic. It is designed to be self-contained, requiring only cargo and python3 to build from source without external crates or pip packages.
Users can interact with the kernel via a web notebook that renders SVG plots and LaTeX-typeset math, or by connecting an MCP client through the Model Context Protocol using the make mcp command. For a native experience, the macOS app embeds a WKWebView to provide a standalone windowed application. The system also supports formal verification by handing claims to Lean 4 and Mathlib to ensure mathematical correctness through automated tactics.
できること
- 1Formal Proof VerificationVerify the truth of a mathematical claim using Lean 4 and Mathlib tactics.
- 2Algebraic SimplificationUse the kernel to perform pattern matching and algebraic manipulations on expressions.
プロジェクトの README から作成されています。すべてのユースケースは、その引用と照らし合わせて確認されています。
自動チェック
実行日 2026年11月15日完全なレポート →まだ検証されていません。サーバーには80点のスコア、重大な問題がないこと、および検証に必要な十分なデータが必要です。 チェックの仕組み · 点数を上げるための改善点
- ソースリポジトリがリンクされており、アクセス可能thread3d/rmath is public and reachablegithub.com/thread3d/rmath ↗合格
- パッケージがこのリポジトリをソースとして指定未チェック
- ビルドの来歴 (Sigstore 証明)未チェック
- オープンソースライセンス (OSI)MITspdx.org/licenses/MIT.html ↗合格
- 過去1年以内にコミットまたはリリースありLast commit or release 2026-11-08github.com/thread3d/rmath ↗合格
- OpenSSF Scorecard未チェック
- パッケージ名が有名なパッケージに酷似していない未チェック
- パッケージおよびその依存関係に重大な勧告なし未チェック
- モデルへの隠れた指示がない0 tool descriptions and the README read; no override phrases, credential paths or hidden characters合格
- 破壊的なツールがラベル付けされている未チェック
- リモートエンドポイントが MCP ハンドシェイクに応答未チェック
README
GitHubで見るrMath — a stand-alone Mathematica-style system
A self-contained clone of the Mathematica experience: a symbolic kernel in
Rust (expression engine, pattern matching, exact arithmetic, CAS) plus a
Python front end (web notebook + SVG plots). No external crates, no pip
packages — builds from source with nothing but cargo and python3.
In[1]:= f[n_] := f[n-1]*n; f[0] = 1; f[10]
Out[1]= 3628800
In[2]:= D[Sin[x]^2, x]
Out[2]= 2 Cos[x] Sin[x]
In[3]:= Integrate[x^2, {x, 0, 1}]
Out[3]= 1/3
In[4]:= Plot[Sin[x], {x, 0, 6}]
Out[4]= <an SVG plot in the notebook>
Quick start
Everything is driven by the Makefile from the project root:
make help # list all commands
make release # build the kernel (release)
make notebook-bg # start the web notebook in the background
make stop # stop it
make restart # stop + start again
make mcp # MCP server on stdio (for an MCP client)
The notebook then runs at http://127.0.0.1:8787 — open it and evaluate
cells (Enter evaluates, Shift+Enter inserts a newline, ↑/↓ walk history,
Ctrl+Space autocompletes). Inputs and outputs are typeset with LaTeX, plots
render as SVG. The same server is a self-describing JSON API (GET /api), and
make mcp exposes the kernel over the Model Context Protocol — see
HTTP API and MCP server.
Without make:
cd rmath && ~/.cargo/bin/cargo build --release # build the kernel
cd .. && python3 -m rmathpy.notebook --port 8787 # foreground server
macOS app (native window)
make app # build dist/rMath.app (native window app, ~3.4 MB)
make app-install # install into ~/Applications + register with Spotlight
open ~/Applications/rMath.app # or double-click it in Finder
rMath.app is a native Cocoa application: it embeds a WKWebView in a real
window (no browser needed) and starts the bundled notebook server + Rust kernel
as child processes. The bundle is self-contained — kernel binary, notebook
server, KaTeX fonts/CSS/JS, and the demo files — needing only a python3.
- Menus: ⌘R reload, ⌘+ / ⌘- / ⌘0 zoom, standard Cut/Copy/Paste, ⌘Q quit.
- Quitting stops everything: the server and its kernel are terminated with the app (no orphan processes).
- Startup: it uses port 8787, automatically moving to the next free port if that one is taken, shows a "Starting rMath…" splash, then swaps in the notebook. If startup fails it shows the log path instead.
- State: working directory
~/Library/Application Support/rMath/work(seeded with a copy ofdemo/), log~/Library/Logs/rMath.log.
Terminal controls shipped inside the bundle:
APP=~/Applications/rMath.app/Contents/MacOS
"$APP/rMath" --stop # stop a running instance (native app)
"$APP/rMath" --no-window # start server, wait for health, exit (self-test)
"$APP/rMath" --port=9000 # different port
"$APP/rMath-cli" --stop # shell-launcher equivalent (browser-based)
"$APP/rMath-cli" --no-open # start without opening a browser
Useful environment variables: RMATH_PYTHON=/path/to/python3 (choosing the
interpreter), RMATH_LOG_REQUESTS=1 (log every HTTP request to the app log),
and RMATH_NO_NATIVE=1 make app (build the older browser-launcher bundle
instead of the native app).
Demonstration file
demo/demo.mt is a tour of the kernel: 389 verified examples and 79 statements
in 24 sections
(arithmetic, complex numbers, elementary and special functions, Unicode input,
patterns, rules, scoping, lists, functional programming, algebra, polynomials,
calculus, equations, linear algebra, strings, logic, control flow, information
utilities, random numbers, file I/O), then calculus cross-checked in Lean, how
to verify a cell, and the notebook's own features, plus a function inventory
taken from Names[], ending with a plot.
Every example is re-executed against the kernel, in context (statement by
statement in one session, exactly as the notebook's Open does), by
make demo-gen — so an example that stops evaluating is reported rather than
left in the file as a lie. Load it with Get["demo/demo.mt"], which prints each
labelled step; in the app, File ▸ Open… loads each statement as its own
cell and turns a labelled example Print[" <expr> = ", <expr>] into the
bare <expr>, so every result gets an Out[n]= line.
Notebook interface
The window is a Mathematica-style notebook:
- Ribbon/toolbar: Evaluate, Evaluate All, New, Open, Save, Save Last Plot as SVG, Reset Kernel, zoom out/in, Standard/Traditional form, Steps, Help (all functional).
- Menus (native): rMath, File, Edit, Insert, Evaluation, Format, Cell,
Graphics, Palettes, Window, Help — with the usual shortcuts, e.g. ⌘N new,
⌘O open, ⌘S save, ⇧⌘S screenshot, ⇧⏎ evaluate, ⇧⌘⏎ evaluate all,
⇧⌘D show steps, ⌥⌘R reset kernel, ⌘+ / ⌘- / ⌘0 zoom, ⌘? help.
rMath --dump-menusprints the whole tree. - Cells: every evaluation shows
In[n]:=andOut[n]=labels with a cell bracket, inputs and outputs typeset through the kernel's TeX printer (StandardForm: square brackets for functions,\fracfor rationals,\sqrt, Greek letters, rules as→). Plots render inline as SVG. - Copying: inputs and outputs are typeset, but copying a cell puts its
source on the clipboard — the input as written, an output as its
InputForm— so an expression can be pasted back without a fraction losing its/(Together[1/x + 1/y]used to copy asTogether[1x+1y]). Unicode slashes and minus signs from rendered math (∕ ⁄ −) are accepted too. - Keyboard: Shift+Enter evaluates (Mathematica convention), Enter adds a new line to the cell, Ctrl+Space completes a function name, ↑/↓ walk history.
- Persistence: cell inputs are autosaved (debounced) to
<work dir>/.rmath-session.json, and replayed on load, so quitting and relaunching the app no longer loses the notebook. Replaying re-evaluates the cells, which also re-establishes any definitions they made. New clears the saved session. - Insert/Palettes menus insert
Pi,Infinity,Sqrt[,Integrate[,Sum[, comparison and rule operators, plus ready-made Plot/Table examples. - Typesetting form toggle: StandardForm (default:
Factor[x² - 1], upright names) ⇄ TraditionalForm (Factor(x² - 1), italic function names, parentheses). Switch from the Format menu (⌘T / ⇧⌘T), ⌃⇧T, or the Standard/Traditional button in the ribbon; existing cells re-typeset instantly (both renderings come back from the kernel, so nothing is re-evaluated). - Show steps: the Steps toggle in the ribbon (or Evaluation ▸ Show Steps, ⇧⌘D) makes every evaluation also display a derivation under its result — the named operations from the given input to the answer (chain rule, integration by parts, l'Hôpital, partial fractions, Pythagorean identity, …), rendered in the current typesetting form. The kernel records the steps during the same evaluation, so nothing is evaluated twice; the setting is remembered between sessions.
- Palettes: real floating palette windows (⌥⌘1…⌥⌘6 or the Palettes
menu) — Basic Math, Algebra, Calculus, Linear Algebra, Plot, Patterns. They
stay above the notebook and their buttons insert at the cursor; the math
palette inserts true Unicode (
π ∞ √ ≤ ≥ ≠ → θ α β …), which the kernel parses directly (√ is a prefix operator:√16→4,45 °→π/4). - Help (⌘? or the Help button) opens a searchable list of every kernel function; click a name to insert it.
Reporting a bug
One action captures everything needed to diagnose a problem:
- In the app: the bug button in the ribbon, or Help ▸ Report a Bug… (⇧⌘B).
- From a terminal:
make report(orrMath --report).
The button talks to the app through WebKit's script-message handler, so it works whether the page is hosted by the app or (for everything except app-only actions) in a browser; in a browser the button is dimmed and explains that reports need the app.
It writes bug-<timestamp>.md + bug-<timestamp>.png into
<workspace>/.shots/reports/ (the workspace path is recorded by
make app-install; otherwise ~/Desktop/rMath-reports), and puts a
paste-ready line on the clipboard:
rMath bug report: /Users/threaded/projects/rMath/.shots/reports/bug-20260912-080147.md
screenshot: /Users/threaded/projects/rMath/.shots/reports/bug-20260912-080147.png
last error: 1/0 — Infinite expression encountered.
Paste that into the chat. The report contains the app/kernel/Python versions, the port and log path, a JSON transcript of the last 12 cells (inputs, results, messages, whether a plot was involved), the last error, the page's current typesetting form, and the tail of the server log. The screenshot shows the window as it was.
Screenshots from the app
The app snapshots its own window — no Screen Recording permission is required, because it renders its own view rather than capturing the display.
-
In the app: File ▸ Save Screenshot (⌘S) writes
~/Desktop/rMath-<timestamp>.pngand reveals it in Finder. -
From a terminal, against a running instance:
APP=~/Applications/rMath.app/Contents/MacOS/rMath "$APP" --screenshot /tmp/shot.png # viewport PNG "$APP" --screenshot /tmp/page.pdf # full page as PDF "$APP" --screenshot /tmp/shot.png \ --js 'document.getElementById("inp").value="Plot[Sin[x],{x,0,6}]"; evaluate();' \ --delay 6 # drive the page, then shootAdd
--palette "Basic Math"to open a palette in the running app and capture it instead of the page. The app polls<tmpdir>/rMath-shot.request(line 1: destination, line 2: optional JavaScript, line 3: optional delay, line 4:pageorpalette:<name>) and answers throughrMath-shot.done.rMath --screenshot-palette <name> <out.png>renders a palette standalone.rMath --dump-menusprints the menu tree.
Lean integration (Lean 4 + Mathlib)
rMath can hand a claim to Lean 4 and let the kernel-checked proof decide it.
The project lives in lean/ (Mathlib; its ~8 GB .lake/ build tree is
gitignored):
| install | elan at ~/.elan, toolchain leanprover/lean4:v4.34.0-rc2 (pinned by lean/lean-toolchain, matching Mathlib), Mathlib via lake exe cache get |
install without a writable $HOME |
elan is found at $ELAN_BIN, then $ELAN_HOME/bin, then <repo>/.elan/bin, then ~/.elan/bin — on a machine whose home directory is read-only, ELAN_HOME=$PWD/.elan and MATHLIB_CACHE_DIR=$PWD/.mathlib-cache keep the ~3 GB toolchain and the ~450 MB download cache inside the repository (both gitignored) |
| project | RMATH_LEAN_PROJECT overrides lean/ |
| toolchain | a system lean/lake of another version cannot build Mathlib at the revision lean/lake-manifest.json pins, so the bridge and make lean-verify prefer elan's shims (lake then runs the version lean-toolchain names) |
| availability | rmathpy.lean.available() (and GET /api/lean/status, which also reports elan and mathlib) requires lake and a built Mathlib.olean — lake alone parses import Mathlib as an unknown module, so every check would fail |
| tests | make lean-test — translation and proof-shape tests, no Lean needed; make lean-verify — the real battery (proved and rejected claims), slow since Mathlib loads per claim |
What gets verified. Lean.verify translates the claim to a Lean statement
and runs solve | norm_num | ring | ring_nf | positivity | linarith | nlinarith | omega | simp | decide | rfl, so only a tactic that closes the goal counts:
| claim | outcome |
|---|---|
1/2 + 1/3 = 5/6, 2^10 = 1024, 20! = 2432902008176640000 |
verified |
Factor[x^2 - 1] = (-1 + x)(1 + x), Expand[(x+1)^3] = 1 + 3x + 3x^2 + x^3 |
verified (ring) |
Sqrt[2]^2 = 2, Sin[Pi/6] = 1/2 |
verified (over ℝ) |
x^2 >= 0 |
verified (positivity) |
Integrate[x^2, {x, 0, 1}] = 1/3 |
verified (integral_pow) — kernel calculus cross-checked |
Integrate[x^2, x] = 1/3 x^3, Integrate[Sin[x], x] = -Cos[x], Integrate[1/x, x] = Log[x] |
verified — an indefinite integral is checked by differentiating the antiderivative (deriv F = f) |
D[x^3 + Sin[x], x], D[Exp[x^2], x], D[Sin[x]^2, x], D[3 x^4, x], D[Cos[x], x], D[x, x], D[7, x], D[x^2 + 2 x + 1, x], D[1/x, x], D[Sin[x]/x, x], D[Log[x], x], D[Sqrt[x], x], D[Exp[x] Log[x], x], D[Log[x^2 + 1], x] |
verified — the kernel's derivative cross-checked through explicit HasDerivAt wiring (14 of 14 sampled shapes) |
Solve[x^2 - 3 x + 2 == 0, x], Solve[x^2 - 2 == 0, x] |
verified — every root the kernel returned is substituted back into the equation |
Det[{{2, 1}, {1, 3}}] = 5, Transpose[...], Dot[...] (matrix·vector, vector·matrix, vector·vector) |
verified — a matrix literal is !![...] over ℚ and the goal is closed entrywise (ext i j <;> fin_cases i <;> fin_cases j <;> simp, norm_num [Matrix.det_fin_two]) |
1/2 + 1/3 = 2/3 (false) |
not proved |
Steps[...] and Trace[...] are display wrappers, so verifying such a cell
checks the expression they derive against that expression's own value (the Step
list itself has no Lean translation). A Steps[D[Sin[x]^2, x]] cell therefore
verifies as the derivative; an inner expression the bridge cannot translate
(e.g. Solve) is reported by its own name.
Solve[...] is checked the same way: the kernel finds the roots, and Lean is
asked the independent question whether each really satisfies the equation.
Non-real roots are excluded — Lean's Real.sqrt of a negative is 0, so a claim
about them would be false — and an all-complex result is refused; a root needing
deeper radical reasoning can come back not proved rather than verified.
Automation and trust (Lean backlog). Generated files inline
lean/RMathLemmas.lean, which defines rmath_radical (a best-effort nested
square-root closer) plus a few @[simp] facts; the closing tactic list also
tries field_simp, norm_cast, gcongr, simp_all, aesop and grind. Every
claim is a named theorem rmath_check followed by #print axioms rmath_check,
so the panel shows which axioms closed it and a proof that used sorry is never
reported as verified. All-complex Solve results are now checked over ℂ
instead of refused. A numeric fuzz cross-check (random values through the kernel)
downgrades a verdict to cannot verify if the two sides disagree, catching
translation bugs. Persistence (latency). Lean.verify takes its verdict from
the persistent LSP server once that server has calibrated — it must report a
known-false claim as an error — reusing one session file so Mathlib loads once:
~2–3 s per claim instead of ~10 s. A check is only conclusive when the
server signals elaboration completion ($/lean/fileProgress); anything
inconclusive falls back to the one-shot lake env lean run, so a missing
diagnostics batch can never become a verdict. The panel's Fast check exposes
the server's diagnostics directly, and Find lemmas searches Loogle. Set
RMATH_LEAN_SERVER=0 to force the one-shot path. make lean-bench scores
translation and verification over the golden files and the demo (translation
coverage is 268 of 983 corpus claims: indefinite integrals, finite sums, the
Collect-like heads, Series/Normal[Series[...]] and NSolve are translated now);
RMATH_LEAN_HAMMER=1 retries not proved goals with external hammers (duper,
lean_smt) when the project supplies them.
rmath_radical walks the radicals in the goal bottom-up: for each radicand
t (innermost first) it proves 0 ≤ t, records (√t)² = t, then closes the
goal with nlinarith. That is what √((√5−1)/2) needs — 0 ≤ (√5−1)/2
follows from (√5)² = 5 and √5 ≥ 0 — so
Solve[x^4 + x^2 - 1 == 0, x] now verifies over ℝ (its two real roots; the
two non-real ones are excluded, since Lean's Real.sqrt of a negative is 0).
A radical whose sign is genuinely unprovable makes the tactic fail rather than
invent a verdict.
What a series claim is. Series[f, {x, a, n}] is checked as the Taylor
coefficients it printed: for each c_k, Lean proves f⁽ᵏ⁾(a) = k!·c_k. The
remainder O[x]^(n+1) is not part of the claim — that is a separate analytic
statement about f, and asserting it from the bridge would be the bridge's
opinion rather than the kernel's answer. NSolve is checked only when the roots
it printed are exact (1.0, 5/2); NSolve answers in machine numbers, so an
approximate root has no exact statement to check and is refused with the reason —
the point of the bridge is that a verdict is never invented.
Two subtleties worth knowing, both found by testing rather than reasoning:
- Every numeral carries its type. Without ascription Lean defaults
1/2to ℕ, where1/2 + 1/3 = 2/3is0 = 0— a false positive. Numerals are now ascribed (ℚ, or ℝ whenReal.*/Piappears) and^/Nat.factorialarguments as ℕ. solve, notfirst.first | norm_num | ringstops atnorm_numwhen it merely simplifies the goal, leaving it unsolved;solverequires a tactic that closes it.
Derivatives. There is no deriv tactic in this Mathlib, so D[...] results
are checked by building a HasDerivAt proof term structurally
(hasDerivAt_pow/_id/_const for leaves, then .add, .sub, .mul,
.const_mul, .neg, .pow, .inv, .div, .sin, .cos, .exp, .log,
.sqrt), with the function form written exactly as each lemma states it because
rw [h.deriv] matches syntactically. Where a lemma needs a non-zero argument
(quotients, Log, Sqrt) the side condition is emitted as a hypothesis —
example (x : ℝ) (h1 : x ≠ 0) : deriv (fun x => Real.sin x / x) x = … — stated in
reduced form (x ≠ 0, not id x ≠ 0) because that is what field_simp
recognises. Abs is still refused: this Mathlib has no HasDerivAt lemma for it.
Refused on purpose (with the reason shown in the panel): N[...] machine
approximations, complex numbers, GCD/LCM, bare expressions that are not
claims, and derivative shapes needing side conditions.
On speed: why verdicts are not server-backed yet. rmathpy/lean.py contains
a full LSP client (lean --server: Mathlib loads once, 0.5–0.9 s per check
instead of ~10 s). It is opt-in (RMATH_LEAN_SERVER=1) and never decides
verdicts, because testing showed it publishes empty diagnostic batches for
files with genuine errors — example : (1 : ℚ) = 2 := by norm_num came back
with no diagnostics, which would have reported false claims as verified.
Verdicts therefore come from the authoritative one-shot lake env lean run (its
exit status and diagnostics are the elaborator's own), and repeated claims are
cached, so a re-check is instant.
Two further routes to a fast and trustworthy server were attempted and are
documented, not shipped: hand-driving Elab.Frontend.processCommands against an
importModules environment (compiles, but returns with an empty message log —
elaboration is deferred to the snapshot machinery), and runFrontend with
incremental snapshots (the save step needs supportInterpreter). Both are
recorded in lean/RMathServer.lean, which is marked experimental and is not
wired into any code path.
In the app: the Lean ribbon button (or Help ▸ Lean… ⇧⌘L) opens a floating panel
with a snippet box (Mathlib is imported automatically), a Check button, and
severity-coloured diagnostics with line/column; Verify the last cell
(⌥⌘V) takes the cell's input and result, shows the generated Lean statement and
the outcome. Endpoints: GET /api/lean/status, POST /api/lean/check,
POST /api/lean/verify.
Setting it up (once per checkout). The toolchain, Mathlib and its cache are per-checkout state, so they are not in git; two commands manage them:
make lean-status # what is present, and what is missing (no Lean needed)
make lean-setup # install whatever is missing — idempotent
make lean-setup installs elan into .elan/ (unless ELAN_HOME says
otherwise) with the toolchain lean/lean-toolchain pins, downloads the Mathlib
build cache into .mathlib-cache/, runs lake exe cache get and lake build,
then reports through make lean-status. All three directories are gitignored
(~11 GB together), so a fresh clone or a git clean -xdf starts empty and
make lean-setup puts it back. make lean-verify refuses to run in that state
instead of skipping silently — a green suite that never checked a proof is the
failure mode this exists to prevent.
rMath MCPのよくある質問
How do I run the MCP server?
You can expose the kernel over the Model Context Protocol by running the command make mcp.
Does rMath require external dependencies like pip packages?
No, it is a self-contained system that builds from source using only cargo and python3, with no external crates or pip packages required.
Can rMath verify mathematical claims using Lean 4?
Yes, it can hand a claim to Lean 4 and use kernel-checked proofs to decide the outcome.