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
| Name | Required | Description | Default |
|---|---|---|---|
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, }; } );
- src/tools/sagemath.ts:73-76 (handler)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); }
- src/index.ts:16-27 (schema)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(), }, },
- src/tools/sagemath.ts:7-13 (schema)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; }
- src/tools/sagemath.ts:19-71 (helper)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, }); }); }); }