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 分