S

Sagemath MCP

by XBP-Europe · io.github.XBP-Europe/sagemath-mcp

A 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.

pypi Local · stdio GlamaOfficial MCP Registry High confidence

Install

Add to ~/Library/Application Support/Claude/claude_desktop_config.json

Windows / Linux path
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "io-github-xbp-europe-sagemath-mcp": {
      "command": "uvx",
      "args": [
        "sagemath-mcp"
      ],
      "env": {
        "SAGEMATH_MCP_STARTUP": "from sage.all import *",
        "SAGEMATH_MCP_IDLE_TTL": "900",
        "SAGEMATH_MCP_MAX_STDOUT": "100000",
        "SAGEMATH_MCP_PURE_PYTHON": "unset",
        "SAGEMATH_MCP_SAGE_BINARY": "sage",
        "SAGEMATH_MCP_EVAL_TIMEOUT": "30",
        "SAGEMATH_MCP_SHUTDOWN_GRACE": "2",
        "SAGEMATH_MCP_SECURITY_ENABLED": "true",
        "SAGEMATH_MCP_FORCE_PYTHON_WORKER": "false",
        "SAGEMATH_MCP_SECURITY_MAX_SOURCE": "8000",
        "SAGEMATH_MCP_SECURITY_ALLOW_IMPORTS": "false",
        "SAGEMATH_MCP_SECURITY_FORBID_GLOBAL": "true",
        "SAGEMATH_MCP_SECURITY_MAX_AST_DEPTH": "75",
        "SAGEMATH_MCP_SECURITY_MAX_AST_NODES": "2500",
        "SAGEMATH_MCP_SECURITY_LOG_VIOLATIONS": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORTS": "math,cmath,statistics,base64,io,sage,sage.all",
        "SAGEMATH_MCP_SECURITY_FORBID_NONLOCAL": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORT_PREFIXES": "sage."
      }
    }
  }
}

Restart Claude Desktop to activate the new server.

Add to .cursor/mcp.json (project) or ~/.cursor/mcp.json (global)

Windows / Linux path
Windows: .cursor\mcp.json (project) or %USERPROFILE%\.cursor\mcp.json (global)
Linux: .cursor/mcp.json (project) or ~/.cursor/mcp.json (global)
{
  "mcpServers": {
    "io-github-xbp-europe-sagemath-mcp": {
      "command": "uvx",
      "args": [
        "sagemath-mcp"
      ],
      "env": {
        "SAGEMATH_MCP_STARTUP": "from sage.all import *",
        "SAGEMATH_MCP_IDLE_TTL": "900",
        "SAGEMATH_MCP_MAX_STDOUT": "100000",
        "SAGEMATH_MCP_PURE_PYTHON": "unset",
        "SAGEMATH_MCP_SAGE_BINARY": "sage",
        "SAGEMATH_MCP_EVAL_TIMEOUT": "30",
        "SAGEMATH_MCP_SHUTDOWN_GRACE": "2",
        "SAGEMATH_MCP_SECURITY_ENABLED": "true",
        "SAGEMATH_MCP_FORCE_PYTHON_WORKER": "false",
        "SAGEMATH_MCP_SECURITY_MAX_SOURCE": "8000",
        "SAGEMATH_MCP_SECURITY_ALLOW_IMPORTS": "false",
        "SAGEMATH_MCP_SECURITY_FORBID_GLOBAL": "true",
        "SAGEMATH_MCP_SECURITY_MAX_AST_DEPTH": "75",
        "SAGEMATH_MCP_SECURITY_MAX_AST_NODES": "2500",
        "SAGEMATH_MCP_SECURITY_LOG_VIOLATIONS": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORTS": "math,cmath,statistics,base64,io,sage,sage.all",
        "SAGEMATH_MCP_SECURITY_FORBID_NONLOCAL": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORT_PREFIXES": "sage."
      }
    }
  }
}

Cursor usually picks up config changes automatically; if the server does not appear, reload the window.

Add to .mcp.json (project) or ~/.claude.json (global)

Windows / Linux path
Windows: .mcp.json (project) or %USERPROFILE%\.claude.json (global)
Linux: .mcp.json (project) or ~/.claude.json (global)
{
  "mcpServers": {
    "io-github-xbp-europe-sagemath-mcp": {
      "command": "uvx",
      "args": [
        "sagemath-mcp"
      ],
      "env": {
        "SAGEMATH_MCP_STARTUP": "from sage.all import *",
        "SAGEMATH_MCP_IDLE_TTL": "900",
        "SAGEMATH_MCP_MAX_STDOUT": "100000",
        "SAGEMATH_MCP_PURE_PYTHON": "unset",
        "SAGEMATH_MCP_SAGE_BINARY": "sage",
        "SAGEMATH_MCP_EVAL_TIMEOUT": "30",
        "SAGEMATH_MCP_SHUTDOWN_GRACE": "2",
        "SAGEMATH_MCP_SECURITY_ENABLED": "true",
        "SAGEMATH_MCP_FORCE_PYTHON_WORKER": "false",
        "SAGEMATH_MCP_SECURITY_MAX_SOURCE": "8000",
        "SAGEMATH_MCP_SECURITY_ALLOW_IMPORTS": "false",
        "SAGEMATH_MCP_SECURITY_FORBID_GLOBAL": "true",
        "SAGEMATH_MCP_SECURITY_MAX_AST_DEPTH": "75",
        "SAGEMATH_MCP_SECURITY_MAX_AST_NODES": "2500",
        "SAGEMATH_MCP_SECURITY_LOG_VIOLATIONS": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORTS": "math,cmath,statistics,base64,io,sage,sage.all",
        "SAGEMATH_MCP_SECURITY_FORBID_NONLOCAL": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORT_PREFIXES": "sage."
      }
    }
  }
}

The server will be available in the next Claude Code session.

Add to .vscode/mcp.json

Windows / Linux path
Windows: .vscode\mcp.json
Linux: .vscode/mcp.json
{
  "servers": {
    "io-github-xbp-europe-sagemath-mcp": {
      "command": "uvx",
      "args": [
        "sagemath-mcp"
      ],
      "env": {
        "SAGEMATH_MCP_STARTUP": "from sage.all import *",
        "SAGEMATH_MCP_IDLE_TTL": "900",
        "SAGEMATH_MCP_MAX_STDOUT": "100000",
        "SAGEMATH_MCP_PURE_PYTHON": "unset",
        "SAGEMATH_MCP_SAGE_BINARY": "sage",
        "SAGEMATH_MCP_EVAL_TIMEOUT": "30",
        "SAGEMATH_MCP_SHUTDOWN_GRACE": "2",
        "SAGEMATH_MCP_SECURITY_ENABLED": "true",
        "SAGEMATH_MCP_FORCE_PYTHON_WORKER": "false",
        "SAGEMATH_MCP_SECURITY_MAX_SOURCE": "8000",
        "SAGEMATH_MCP_SECURITY_ALLOW_IMPORTS": "false",
        "SAGEMATH_MCP_SECURITY_FORBID_GLOBAL": "true",
        "SAGEMATH_MCP_SECURITY_MAX_AST_DEPTH": "75",
        "SAGEMATH_MCP_SECURITY_MAX_AST_NODES": "2500",
        "SAGEMATH_MCP_SECURITY_LOG_VIOLATIONS": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORTS": "math,cmath,statistics,base64,io,sage,sage.all",
        "SAGEMATH_MCP_SECURITY_FORBID_NONLOCAL": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORT_PREFIXES": "sage."
      }
    }
  }
}

Reload the VS Code window to activate.

Add to ~/.codeium/windsurf/mcp_config.json

Windows / Linux path
Windows: %USERPROFILE%\.codeium\windsurf\mcp_config.json
Linux: ~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "io-github-xbp-europe-sagemath-mcp": {
      "command": "uvx",
      "args": [
        "sagemath-mcp"
      ],
      "env": {
        "SAGEMATH_MCP_STARTUP": "from sage.all import *",
        "SAGEMATH_MCP_IDLE_TTL": "900",
        "SAGEMATH_MCP_MAX_STDOUT": "100000",
        "SAGEMATH_MCP_PURE_PYTHON": "unset",
        "SAGEMATH_MCP_SAGE_BINARY": "sage",
        "SAGEMATH_MCP_EVAL_TIMEOUT": "30",
        "SAGEMATH_MCP_SHUTDOWN_GRACE": "2",
        "SAGEMATH_MCP_SECURITY_ENABLED": "true",
        "SAGEMATH_MCP_FORCE_PYTHON_WORKER": "false",
        "SAGEMATH_MCP_SECURITY_MAX_SOURCE": "8000",
        "SAGEMATH_MCP_SECURITY_ALLOW_IMPORTS": "false",
        "SAGEMATH_MCP_SECURITY_FORBID_GLOBAL": "true",
        "SAGEMATH_MCP_SECURITY_MAX_AST_DEPTH": "75",
        "SAGEMATH_MCP_SECURITY_MAX_AST_NODES": "2500",
        "SAGEMATH_MCP_SECURITY_LOG_VIOLATIONS": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORTS": "math,cmath,statistics,base64,io,sage,sage.all",
        "SAGEMATH_MCP_SECURITY_FORBID_NONLOCAL": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORT_PREFIXES": "sage."
      }
    }
  }
}

Restart Windsurf (or refresh its MCP servers panel) to activate the new server.

Windsurf Next uses ~/.codeium/windsurf-next/mcp_config.json. Devin Desktop (the Windsurf rebrand) uses ~/.config/devin/mcp_config.json and imports the Windsurf file.

Add to ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

Windows / Linux path
Windows: %APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
Linux: ~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
{
  "mcpServers": {
    "io-github-xbp-europe-sagemath-mcp": {
      "command": "uvx",
      "args": [
        "sagemath-mcp"
      ],
      "env": {
        "SAGEMATH_MCP_STARTUP": "from sage.all import *",
        "SAGEMATH_MCP_IDLE_TTL": "900",
        "SAGEMATH_MCP_MAX_STDOUT": "100000",
        "SAGEMATH_MCP_PURE_PYTHON": "unset",
        "SAGEMATH_MCP_SAGE_BINARY": "sage",
        "SAGEMATH_MCP_EVAL_TIMEOUT": "30",
        "SAGEMATH_MCP_SHUTDOWN_GRACE": "2",
        "SAGEMATH_MCP_SECURITY_ENABLED": "true",
        "SAGEMATH_MCP_FORCE_PYTHON_WORKER": "false",
        "SAGEMATH_MCP_SECURITY_MAX_SOURCE": "8000",
        "SAGEMATH_MCP_SECURITY_ALLOW_IMPORTS": "false",
        "SAGEMATH_MCP_SECURITY_FORBID_GLOBAL": "true",
        "SAGEMATH_MCP_SECURITY_MAX_AST_DEPTH": "75",
        "SAGEMATH_MCP_SECURITY_MAX_AST_NODES": "2500",
        "SAGEMATH_MCP_SECURITY_LOG_VIOLATIONS": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORTS": "math,cmath,statistics,base64,io,sage,sage.all",
        "SAGEMATH_MCP_SECURITY_FORBID_NONLOCAL": "true",
        "SAGEMATH_MCP_SECURITY_ALLOWED_IMPORT_PREFIXES": "sage."
      }
    }
  }
}

Cline reloads cline_mcp_settings.json automatically; if the server does not appear, reload the VS Code window.

Open it from Cline's MCP Servers panel → Configure. Roo Code uses a different file and format.

Configuration

Environment variables this server reads. Secrets stay on your machine.

NameRequiredDescription
SAGEMATH_MCP_STARTUP No Sage code executed during session bootstrap. Default: from sage.all import *
SAGEMATH_MCP_IDLE_TTL No Seconds of inactivity before a session is culled. Default: 900
SAGEMATH_MCP_MAX_STDOUT No Maximum characters of stdout returned per call. Default: 100000
SAGEMATH_MCP_PURE_PYTHON No When set to 1, load math stdlib instead of Sage modules. Default: unset
SAGEMATH_MCP_SAGE_BINARY No Path to the sage executable. Default: sage
SAGEMATH_MCP_EVAL_TIMEOUT No Per-evaluation timeout in seconds. Default: 30
SAGEMATH_MCP_SHUTDOWN_GRACE No Grace period before a stuck worker is terminated. Default: 2
SAGEMATH_MCP_SECURITY_ENABLED No Enable/disable AST-based code validation. Default: true
SAGEMATH_MCP_FORCE_PYTHON_WORKER No Use the pure-Python worker (helpful for tests/CI). Default: false
SAGEMATH_MCP_SECURITY_MAX_SOURCE No Maximum source length in characters. Default: 8000
SAGEMATH_MCP_SECURITY_ALLOW_IMPORTS No Permit import statements when set to true. Default: false
SAGEMATH_MCP_SECURITY_FORBID_GLOBAL No Block global statements when true. Default: true
SAGEMATH_MCP_SECURITY_MAX_AST_DEPTH No Maximum AST depth allowed. Default: 75
SAGEMATH_MCP_SECURITY_MAX_AST_NODES No Maximum AST node count allowed. Default: 2500
SAGEMATH_MCP_SECURITY_LOG_VIOLATIONS No Emit warnings when code is blocked. Default: true
SAGEMATH_MCP_SECURITY_ALLOWED_IMPORTS No Comma-separated allowlist of importable modules. Default: math,cmath,statistics,base64,io,sage,sage.all
SAGEMATH_MCP_SECURITY_FORBID_NONLOCAL No Block nonlocal statements when true. Default: true
SAGEMATH_MCP_SECURITY_ALLOWED_IMPORT_PREFIXES No Comma-separated prefixes treated as safe namespaces. Default: sage.

Similar servers