Sagemath Mcp Server

io.github.justice8096由 GitHub 帳號 justice8096 發布v1.0.1更新於 Oct 25, 2026

MCP server wrapping SageMath's full computer algebra system — 10 symbolic-math tools for LLMs.

已驗證STDIO僅桌面資料與分析AI 與機器學習

概覽

AI 產生的概覽

一個本機 MCP 伺服器,封裝 SageMath,為助理提供 10 個精確符號數學工具:解方程式、微積分、因式分解、矩陣、數論、繪圖與 LaTeX 轉換。

可以做什麼
執行任意 SageMath 運算式,並以符號方式求解代數或超越方程式。計算任意階導數與不定/定積分,並以多種模式化簡運算式。對多項式或整數做因式分解,執行行列式、反矩陣、特徵值、秩、RREF 等矩陣運算。進行質數判定、下一個質數、歐拉函數、gcd、lcm、質數區間等數論運算。將運算式繪製為 base64 PNG 圖像,並轉換為 LaTeX。
適用情境
當助理需要可靠的精確或符號運算而非心算時使用:多步代數、微積分、矩陣運算、數論,或為數學文稿產生 LaTeX 與圖像。
執行需求
以 Node.js 18 或更新版本的本機程序執行,從 npm 安裝。需要本機已安裝 SageMath 且 sage 在 PATH 中,或需要 Docker 來執行 SageMath 映像。選用環境變數:TRANSPORT、PORT、API_KEY、SAGE_TIMEOUT、SAGE_DOCKER_IMAGE。
安裝前請注意
evaluate 工具會執行任意 SageMath 運算式,應視為在 SageMath 程序內執行程式碼。HTTP 傳輸僅在設定 API_KEY 時受保護,未設定時沒有預設憑證。Docker 映像預設使用 sagemath/sagemath:latest,來自第三方且未固定版本。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Sagemath Mcp Server,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

SageMath MCP Server

[License: CC0-1.0] [npm]

A Model Context Protocol server that exposes SageMath — a 100+ package computer algebra system — to LLM clients such as Claude. Where most "math MCPs" wrap a single library (SymPy, mathjs), this one subprocess-wraps the entire SageMath stack so the model has access to genuine symbolic mathematics, not arithmetic.

Why

LLMs are bad at exact arithmetic, brittle with multi-step algebra, and unreliable when symbolic manipulation matters. The right pattern is to keep the conceptual reasoning in the model and delegate mechanical computation to a tool — the same trick a person with dyscalculia uses with a calculator. SageMath gives you the broadest tool surface for that delegation: factoring, integration, eigenvalues, number theory, LaTeX rendering, and plotting all behind one interface.

Tools

ToolDescription
sage_evaluateRun an arbitrary SageMath expression.
sage_solve_equationSolve algebraic / transcendental equations symbolically.
sage_differentiateCompute derivatives (any order, any variable).
sage_integrateIndefinite and definite integrals.
sage_simplifySimplify expressions (default, full, trig, rational).
sage_factorFactor polynomials or integers.
sage_matrix_opsDeterminant, inverse, eigenvalues, rank, RREF, transpose over QQ / RR / ZZ / CC.
sage_plotPlot an expression and return a base64 PNG.
sage_latex_convertConvert a SageMath expression to LaTeX.
sage_number_theoryis_prime, next_prime, factor, euler_phi, gcd, lcm, prime_range, sigma, moebius.

All tools follow the same schema pattern (see src/schemas/common.ts).

Installation

The server needs either a local SageMath install or Docker available on the host so it can spawn a SageMath process.

Option 1: npm + local SageMath

bash
npm install -g @justice8096/sagemath-mcp-server# requires `sage` on PATH — see https://doc.sagemath.org/html/en/installation/sagemath-mcp

Option 2: Docker (no local SageMath required)

bash
docker compose up# uses the official sagemath/sagemath image; the server runs inside the container

Option 3: from source

bash
git clone https://github.com/justice8096/sagemath-mcp-server.gitcd sagemath-mcp-servernpm installnpm run buildnpm start

Configuring an MCP client

Claude Desktop / Claude Code (stdio transport)

Add to ~/.claude.json (or the equivalent Claude Desktop config):

json
{  "mcpServers": {    "sagemath": {      "command": "sagemath-mcp"    }  }}

Remote / HTTP transport

bash
TRANSPORT=http API_KEY=your-secret-key npm start

Then point an MCP HTTP client at http://<host>:3000/mcp with the matching API_KEY header.

Architecture

  • TypeScript wrapper, runtime is Node.js ≥ 18.
  • Subprocess wrapping — the wrapper code is CC0; SageMath remains GPL-3.0 and runs as a separate process, which is the canonical safe interaction model per the GNU GPL FAQ on aggregation. Embedding via FFI would propagate copyleft; subprocess execution does not.
  • Dual transport — stdio (Claude Desktop, Claude Code, local MCP clients) and Streamable HTTP (remote deployment, optional API_KEY env var).
  • i18n — English, Spanish, French via src/i18n.ts and locales/.
  • Multi-format build — build.ts emits Claude plugin, OpenAI function-calling, n8n node, MCP server descriptor, CLI tool, and YAML prompt-library outputs from the same source manifest.

Configuration

Env varDefaultPurpose
TRANSPORTstdiostdio or http.
PORT3000HTTP port when TRANSPORT=http.
API_KEY(none)If set, HTTP requests must include matching API_KEY header.
SAGE_TIMEOUT30000Per-call SageMath timeout in milliseconds.
SAGE_DOCKER_IMAGEsagemath/sagemath:latestImage used when SageMath isn't installed locally.

Security

  • All SageMath input is sanitized to strip shell metacharacters before subprocess execution; see src/services/sage-executor.ts.
  • HTTP transport requires API_KEY if set — there is no default credential.
  • See SECURITY.md and THREAT_MODEL.md for the full posture.
  • Pre-commit audit suite under audits/: SAST/DAST scan, supply-chain audit, CWE mapping, LLM-compliance report, contribution analysis.

License

This wrapper is released under CC0-1.0 (public domain). SageMath itself remains GPL-3.0; the subprocess execution model keeps the licenses independent. See SECURITY.md and the project's compliance analysis for the legal reasoning.

Status

v1.0.0 — public release. The wrapper layer is stable; the SageMath surface is feature-rich and stable upstream. File issues at https://github.com/justice8096/sagemath-mcp-server/issues.

來源:README.md,提交 da1a377

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.0.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分