Skip to main content

sage-mcp

An MCP server providing persistent SageMath sessions to any MCP-compatible host: Claude Code, Claude Desktop, Cursor, or an agent harness such as mcp-minion.

Without this server, each SageMath computation runs in isolation: loading a list of graphs, analyzing one, then querying its automorphism group would require reloading the graph file three times. The Sage REPL server maintains state across calls, enabling iterative mathematical exploration.

Quickstart

The server is a single file using UV's inline dependency syntax (PEP 723):

uv run sage_repl_server.py

Claude Code / Claude Desktop config (.mcp.json or ~/.claude.json):

{
  "mcpServers": {
    "sage-repl": {
      "command": "uv",
      "args": ["run", "/path/to/sage_repl_server.py"]
    }
  }
}

An optional --directory /path/to/workdir argument sets the server's working directory, so that relative paths in Sage code (e.g. a file written by the agent) resolve inside a chosen run folder.

Tools

Tool Purpose
sage_start Create a new named session (auto-created on first sage_exec if omitted)
sage_exec Execute Sage/Python code and return results
sage_interrupt Send Ctrl+C to stop long-running computations
sage_stop Terminate a session and release resources
sage_list Show all active sessions

sage_exec returns structured output with separate fields for the expression result, stdout, stderr, and any errors. A configurable timeout (default 60 seconds) prevents hanging on infinite loops.

Architecture

The server drives SageMath through the Jupyter kernel protocol rather than raw subprocess management: reliable prompt detection, clean separation of stdout / stderr / return values, native interrupt support, and robust multi-line input. It injects a KernelSpec directly into the KernelManager, so SageMath's bundled Python runs with ipykernel without touching the user's Jupyter configuration. On session start the server imports sage.all, making all Sage functions immediately available. See SPEC.md for the full tool specification.

Requirements

  • SageMath 10.6+ in PATH (the server launches sage -python)
  • uv

Dependencies (resolved automatically by uv run): mcp (1.x low-level server API; pinned <2), jupyter_client, ipykernel.

Citation

This server was built for and used in the experiments of:

Neurosymbolic Discovery of Algebraic Graph Constructions. NeSy 2026. (Full citation and archive DOI to appear.)

License

MIT

Release files for mcp-sage 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-sage 0.1.0
File Size Uploaded
mcp_sage-0.1.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-sage 0.1.0
File Interpreter ABI Platform
mcp_sage-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / mcp_sage-0.1.0.tar.gz

Download URL mcp_sage-0.1.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
89343badc7da2e2b4388bec9aecec1ef4070c0f6bb0f0a43cdfec67e06303daf
BLAKE2b-256 checksum
How to use checksums
9ed76409ade8b3b882f385817c6603c902b400dd5b62108981aa80ca6a9e6eee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.2

Release files / mcp_sage-0.1.0-py3-none-any.whl

Download URL mcp_sage-0.1.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1967001b786ba3953f6ae5f279b8988ddb319a67a8b2550504e87c6d87ba7f72
BLAKE2b-256 checksum
How to use checksums
a8e16aced43660a5a7086b121583f96753d3e8bdd24458610e24e6b52a181810
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page