SageMath MCP Server
Exposes the entire SageMath computer algebra system to LLM clients for symbolic mathematics, including algebra, calculus, number theory, matrix operations, plotting, and LaTeX conversion.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
SageMath MCP Server
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.
Related MCP server: SageMath MCP Server
Tools
Tool | Description |
| Run an arbitrary SageMath expression. |
| Solve algebraic / transcendental equations symbolically. |
| Compute derivatives (any order, any variable). |
| Indefinite and definite integrals. |
| Simplify expressions ( |
| Factor polynomials or integers. |
| Determinant, inverse, eigenvalues, rank, RREF, transpose over |
| Plot an expression and return a base64 PNG. |
| Convert a SageMath expression to LaTeX. |
|
|
All tools follow the same schema pattern (see src/schemas/common.ts).
Every tool except sage_evaluate accepts plain mathematics only: numbers, variable names, operators, brackets, and a fixed list of math functions (see src/services/expression-guard.ts). Anything else is refused with a message that points to sage_evaluate, which runs any SageMath code.
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
npm install -g @justice8096/sagemath-mcp-server
# requires `sage` on PATH — see https://doc.sagemath.org/html/en/installation/
sagemath-mcpOption 2: Docker (no local SageMath required)
docker compose up
# uses the official sagemath/sagemath image; the server runs inside the containerOption 3: from source
git clone https://github.com/justice8096/sagemath-mcp-server.git
cd sagemath-mcp-server
npm install
npm run build
npm startConfiguring an MCP client
Claude Desktop / Claude Code (stdio transport)
Add to ~/.claude.json (or the equivalent Claude Desktop config):
{
"mcpServers": {
"sagemath": {
"command": "sagemath-mcp"
}
}
}Remote / HTTP transport
The HTTP transport requires an API key. The server will not start in HTTP mode without one.
export API_KEY="$(openssl rand -hex 32)"
TRANSPORT=http npm startThe server listens on 127.0.0.1:3000 by default. Point an MCP HTTP client at http://127.0.0.1:3000/mcp and send the key in an X-API-Key header or as Authorization: Bearer <key>.
To accept connections from other machines, set HOST=0.0.0.0 and put TLS in front of the port. Read the Security section first: anyone holding the key can run code on the host.
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 (loopback by default,
API_KEYrequired).i18n — English, Spanish, French via
src/i18n.tsandlocales/.Multi-format build —
build.tsemits Claude plugin, OpenAI function-calling, n8n node, MCP server descriptor, CLI tool, and YAML prompt-library outputs from the same source manifest.
Configuration
Env var | Default | Purpose |
|
|
|
|
| Interface the HTTP transport listens on. |
|
| HTTP port when |
| (none) | Required when |
|
|
|
|
| Per-call SageMath timeout in milliseconds. The process is killed when it expires. The first call on a host can be slow; lower this once you know how your host behaves. |
|
| Image used in Docker mode. |
|
| Docker network for each call. |
|
| Memory limit for each container. |
Security
SageMath code is Python. sage_evaluate runs any SageMath code, so it can open files, start processes and use the network. Treat access to that tool as the ability to run code. The other nine tools accept plain mathematics only and cannot run code.
Docker is the default. When Docker is installed and running, each call runs in a throwaway container with no network, no Linux capabilities, and memory and process limits. Without Docker the server uses a local
sage, and the code runs as your user, with your files. SetSAGE_EXECUTION_MODE=dockerto rule out that fallback.No shell. The program reaches SageMath as a single process argument. Shell characters in tool arguments have no effect. Versions up to 1.0.1 built a shell command line and were open to command injection; upgrade.
HTTP needs a key. The HTTP transport refuses to start without
API_KEYand listens on loopback by default.Math-only tools. The nine structured tools check their expressions against an allow-list before anything runs. Quotes, attribute access, keywords and unknown function calls are refused.
Prompt injection. A model that reads untrusted content can be steered into calling these tools.
sage_evaluateis marked as not read-only so that clients ask before running it. The other nine are read-only.See
SECURITY.mdandTHREAT_MODEL.mdfor the full posture, andCHANGELOG.mdfor the 1.1.0 security fixes.Audit reports are 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.1.1. Version 1.1.0 was a security release: versions up to 1.0.1 are vulnerable; see CHANGELOG.md. 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.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Unofficial Math.js MCP — wraps the mathjs.org API (free, no auth)
Scientific compute for AI agents: symbolic, numerical, quantum, chemistry, ODE. Paid via x402.
MCPCalc gives agents access to a comprehensive library of calculators spanning finance, math, health, construction, engineering, food, automotive, and more. It includes a full Computer Algebra System (CAS) and a grid-based Spreadsheet calculator.
This MCP server enables users to perform scientific computations regarding linear algebra and vect…
Related MCP Servers
- FlicenseCqualityDmaintenanceExposes a broad mathematics toolkit including symbolic algebra, calculus, numerical methods, linear algebra, statistics, discrete math, graph theory, rendering, and optional GPU acceleration via MCP tools for use with Claude Desktop and other MCP hosts.513-
- AlicenseBqualityAmaintenanceA universal mathematics MCP server that gives LLM clients full access to SageMath for symbolic calculus, number theory, linear algebra, and more, with persistent state across tool calls.40129 PyPI22MIT
- AlicenseAqualityCmaintenanceEnables advanced mathematics operations including linear algebra, vector math, symbolic computation, and calculus through MCP tools. Designed for use with Claude and other MCP-compatible LLMs.192MIT
- AlicenseAqualityBmaintenanceProvides an MCP server exposing compute, verify, and plot tools backed by Giac/Xcas for exact symbolic and numerical mathematics, enabling LLMs to solve calculus, algebra, geometry, and more with verified results.3234 npm3GPL 3.0