mcp-sage

v0.2.0
mcp-sage Checked 2 days ago Published 4 days ago

MCP server providing persistent SageMath sessions (Sage REPL over the Model Context Protocol)

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

sage_start

Start a new Sage session with sage.all imported and x predefined as a symbolic variable, as in the sage shell. Variables and definitions persist across sage_exec calls until sage_stop. Optional: sage_exec starts the session if it does not exist.

ParameterTypeDescription
session_idstringOptional session ID (default: 'default')

sage_exec

Execute Sage code in a persistent session. By default the code goes through the Sage preparser, as in the sage shell: ^ is power, integer and rational literals are exact Sage numbers (1/2 is a Rational), and R.<x> = QQ[] works. x is a symbolic variable until the code assigns it. Python functions that insist on Python numbers reject Sage literals (time.sleep(0.5) raises TypeError): write 0.5r or float(0.5), or pass preparse=false. Returns the value of the last expression, stdout, stderr and errors as one text. Calls on one session run one at a time. The timeout (default 60 s) covers the whole c…

ParameterTypeDescription
code *stringSage code to execute (multi-line allowed)
preparsebooleanRun the code through the Sage preparser (default: true). false runs it as plain Python: ^ is xor, 1/2 is a float.
session_idstringSession ID (default: 'default')
timeoutintegerSeconds to wait for the result (default: 60). The computation is not stopped at the timeout.

sage_interrupt

Interrupt the running computation in a session (Ctrl+C), for example after a sage_exec timeout. Returns once the kernel accepts new code (at most 5 s; otherwise it says the kernel may still be busy). The session and its variables are kept.

ParameterTypeDescription
session_idstringSession ID (default: 'default')

sage_stop

Stop a Sage session and free resources.

ParameterTypeDescription
session_idstringSession ID (default: 'default')

sage_list

List all active Sage sessions.