sagemath_health
Check SageMath availability and basic readiness for mathematical computations through the MCP SageMath Server.
Instructions
Lightweight self-check of SageMath availability and basic readiness
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:83-97 (handler)Inline handler function for the 'sagemath_health' tool. Performs a simple 'print(1+1)' evaluation to check if SageMath is responsive and returns structured health status.
async () => { const health = await evaluateSage('print(1+1)', 3000); const ok = !health.timedOut && health.exitCode === 0; return { content: [{ type: 'text', text: `${ok ? 'SageMath is responsive' : 'SageMath check failed'} (structured JSON below)\n${JSON.stringify({ ok, details: health })}`, }], structuredContent: { ok, message: ok ? 'SageMath executed a trivial script successfully.' : 'SageMath failed to execute a trivial script.', details: health, }, }; } - src/index.ts:73-82 (schema)Input and output schema definition for the 'sagemath_health' tool using Zod.
{ title: 'SageMath Health Check', description: 'Lightweight self-check of SageMath availability and basic readiness', inputSchema: {}, outputSchema: { ok: z.boolean(), message: z.string(), details: z.record(z.unknown()).optional(), }, }, - src/index.ts:71-98 (registration)Registration of the 'sagemath_health' tool on the MCP server.
server.registerTool( 'sagemath_health', { title: 'SageMath Health Check', description: 'Lightweight self-check of SageMath availability and basic readiness', inputSchema: {}, outputSchema: { ok: z.boolean(), message: z.string(), details: z.record(z.unknown()).optional(), }, }, async () => { const health = await evaluateSage('print(1+1)', 3000); const ok = !health.timedOut && health.exitCode === 0; return { content: [{ type: 'text', text: `${ok ? 'SageMath is responsive' : 'SageMath check failed'} (structured JSON below)\n${JSON.stringify({ ok, details: health })}`, }], structuredContent: { ok, message: ok ? 'SageMath executed a trivial script successfully.' : 'SageMath failed to execute a trivial script.', details: health, }, }; } ); - src/tools/sagemath.ts:78-90 (helper)Helper function 'evaluateSage' that executes SageMath code by writing to temp file and spawning process. Used by the health handler for the simple check.
export async function evaluateSage(code: string, timeoutMs = 10000): Promise<SageRunResult & { tmpDir?: string }> { const sage = getSageExecutable(); const tmpRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'mcp-sage-')); const scriptPath = path.join(tmpRoot, 'script.sage'); await fs.writeFile(scriptPath, code, 'utf8'); const result = await runProcess(sage, [scriptPath], timeoutMs); // Attempt cleanup try { await fs.rm(tmpRoot, { recursive: true, force: true }); } catch {} return { ...result }; }