XBP-Europe/sagemath-mcp

View on GitHub ↗

Stateful SageMath MCP server: 37 tools for symbolic math, algebra, number theory, graphs and plotting. A persistent Sage session per client, an AST policy in front of it, and a hardened container as the real boundary.

12 ★0 forksPythonUpdated 18d ago

What you need to know

Universal mathematics MCP server (37 tools, FastMCP 3.x) that hands LLM clients full SageMath — calculus, algebra, linear algebra, ODEs, number theory, combinatorics, graph/group/elliptic-curve/coding theory, statistics, probability, plotting, numeric methods, and vector calculus — with a persistent SageMath process per session and a hardened sandbox.

Install

pip install sagemath-mcp (then run sagemath-mcp, or python -m sagemath_mcp.server --help if not on PATH)
uv run sagemath-mcp in a source checkout (uv pip install -e .[dev]); docker build -t sagemath-mcp:latest . / docker compose up --build also supported.
Optional auto Sage runtime: make sage-container or ./scripts/setup_sage_container.sh.
Released images at ghcr.io/xbp-europe/sagemath-mcp are Cosign-signed; Helm chart runs non-root (runAsUser 1000).

Usage

  • Run over stdio (default) or streamable HTTP: sagemath-mcp --transport streamable-http --host 127.0.0.1 --port 8314.
  • State persists: variables/functions/assumptions survive across tool calls in the same MCP session (multi-step workflows).
  • Claude Desktop / Codex CLI use stdio; Gemini adds with gemini mcp add sagemath --transport stdio --command uv --arg run --arg sagemath-mcp.
  • Call evaluate_sage (or evaluate_sage_streaming) for open-ended execution, and the domain tools (solve_ode, matrix_operation, plot_expression, number_theory_operation, …) for structured math.
  • Session tools: reset/interrupt/cancel/start/list/stop for independent workspaces; /health endpoint for HTTP deployments.

Key features

  • 37 tools across 20 categories (calculus, algebra, symbolic sums, linear algebra incl. determinant/inverse/eigenvalues/rank/rref/transpose, first/higher-order ODEs via desolve, number theory, combinatorics, graph theory, group theory, elliptic curves, coding theory, polynomial rings, Boolean algebra, geometry, statistics, probability distributions, 2D/3D plotting, numeric root-finding, vector calculus).
  • Persistent per-session SageMath subprocesses with asyncio locks and idle culling; progress heartbeats (~1.5s) and per-call timeouts.
  • Security sandbox: deny-by-default name allowlist + AST validation before exec(); process isolation means a crash/timeout in one session can't affect others.
  • 3 MCP resources (session snapshot, aggregated metrics, docs links) plus /health; LaTeX output and stdout capture.
  • PyPI package, MCP Registry listed, Python 3.12+, SageMath 10.9, typed, coverage 100%.

Best for

Agents and mathematics users who need a real, comprehensive computer-algebra system over MCP for symbolic and numeric mathematics with persistent state.

Caveats

  • Requires SageMath (or the bundled container) — heavy local dependency; stdio is the default, HTTP is opt-in.
  • Caller code is gated by the allowlist + AST checks; helper names not offered by the allowlist are refused until reviewed.
  • Only tool/resource/prompt catalogues are cached; tool-call and resource-response caching are deliberately off to avoid cross-client collisions.
  • Sage startup is inherently slow on first use; progress heartbeats help clients detect stalls.
Platforms: LocalClients: Claude Desktop · Gemini CLI · Codex CLI

Reviewed 2026-08-18

Topics

ai-toolscasclaudecomputer-algebrafastmcpllmmathmathematicsmcpmcp-servermodel-context-protocolpythonsagesagemathsymbolic-computation
Stars
12★
Forks
0
Language
Python
License
MIT
Created
2025-11-02
Last push
2026-08-17