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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_sage-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_sage-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file mcp_sage-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_sage-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for mcp_sage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 89343badc7da2e2b4388bec9aecec1ef4070c0f6bb0f0a43cdfec67e06303daf
MD5 a1a1c8de5c75f1f9ae1983ea46f4d220
BLAKE2b-256 9ed76409ade8b3b882f385817c6603c902b400dd5b62108981aa80ca6a9e6eee

See more details on using hashes here.

File details

Details for the file mcp_sage-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_sage-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for mcp_sage-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1967001b786ba3953f6ae5f279b8988ddb319a67a8b2550504e87c6d87ba7f72
MD5 ff8d5e71aaa04df9a3d52a11aa1eabd2
BLAKE2b-256 a8e16aced43660a5a7086b121583f96753d3e8bdd24458610e24e6b52a181810

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page