Skip to main content
Glama
GaloisHLee
by GaloisHLee

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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,
        },
      };
    }
  • 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,
          },
        };
      }
    );
  • 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 };
    }

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