Skip to main content
Glama
GaloisHLee
by GaloisHLee

sagemath_version

Retrieve the version details of the local SageMath installation to verify compatibility and ensure proper setup for mathematical computations.

Instructions

Get local SageMath version information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • src/index.ts:14-39 (registration)
    Registers the sagemath_version MCP tool, defining its schema and a thin handler wrapper that calls getSageVersion and formats the MCP response.
    server.registerTool( 'sagemath_version', { title: 'SageMath Version', description: 'Get local SageMath version information', inputSchema: {}, outputSchema: { stdout: z.string(), stderr: z.string(), exitCode: z.number().nullable(), durationMs: z.number(), timedOut: z.boolean(), }, }, async () => { const result = await getSageVersion(); const structured = result as unknown as Record<string, unknown>; return { content: [{ type: 'text', text: `SageMath version response (structured JSON below)\n${JSON.stringify(structured)}`, }], structuredContent: structured, }; } );
  • Core handler logic for sagemath_version: spawns the SageMath executable with '--version' argument using the runProcess utility, returning stdout, stderr, exit code, etc.
    export async function getSageVersion(timeoutMs = 5000): Promise<SageRunResult> { const sage = getSageExecutable(); return runProcess(sage, ['--version'], timeoutMs); }
  • Input schema (empty) and output schema using Zod for validation of sagemath_version tool response fields.
    { title: 'SageMath Version', description: 'Get local SageMath version information', inputSchema: {}, outputSchema: { stdout: z.string(), stderr: z.string(), exitCode: z.number().nullable(), durationMs: z.number(), timedOut: z.boolean(), }, },
  • TypeScript interface defining the structure of SageMath execution results, matching the tool's output schema.
    export interface SageRunResult { stdout: string; stderr: string; exitCode: number | null; durationMs: number; timedOut: boolean; }
  • Utility function to spawn and manage SageMath child processes with timeout, stdout/stderr capture, and error handling.
    async function runProcess(cmd: string, args: string[], timeoutMs: number): Promise<SageRunResult> { const start = Date.now(); let stdout = ''; let stderr = ''; let timedOut = false; return new Promise<SageRunResult>((resolve) => { let child: ReturnType<typeof spawn> | undefined; try { child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] }); } catch (err: any) { resolve({ stdout: '', stderr: `Failed to spawn process: ${err?.message || String(err)}`, exitCode: null, durationMs: Date.now() - start, timedOut: false, }); return; } const t = setTimeout(() => { timedOut = true; try { child?.kill('SIGKILL'); } catch {} }, Math.max(1, timeoutMs)); // Handle asynchronous spawn errors (e.g., command not found) child.on('error', (err) => { clearTimeout(t); resolve({ stdout: '', stderr: `Process error: ${err?.message || String(err)}`, exitCode: null, durationMs: Date.now() - start, timedOut, }); }); child.stdout?.on('data', (d) => { stdout += d.toString(); }); child.stderr?.on('data', (d) => { stderr += d.toString(); }); child.on('close', (code) => { clearTimeout(t); resolve({ stdout, stderr, exitCode: code, durationMs: Date.now() - start, timedOut, }); }); }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/GaloisHLee/mcp-server-sagemath'

If you have feedback or need assistance with the MCP directory API, please join our Discord server