Skip to main content
Glama

calc_eval

Evaluate mathematical expressions with configurable decimal precision. Perform accurate arithmetic computations for calculations and problem-solving.

Instructions

Alias of calc.eval

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exprYes
precisionNo

Implementation Reference

  • The main handler function `calcEval` that evaluates a math expression using mathjs. It normalizes exponent notation (**, mũ, lũy thừa -> ^), evaluates the expression, and optionally formats the result with configurable precision (capped at 0-20). Returns {ok, result} on success or {ok, error} on failure.
    export async function calcEval(expr: string, precision?: number) {
      try {
        const norm = normalizeExponent(expr);
        const res = math.evaluate(norm);
        let out = String(res);
        if (typeof res === 'number' && Number.isFinite(res) && typeof precision === 'number') {
          const p = Math.max(0, Math.min(precision, 20));
          out = res.toFixed(p);
        }
        return { ok: true, result: out };
      } catch (e: any) {
        return { ok: false, error: e?.message || 'calc error' };
      }
    }
  • Helper function `normalizeExponent` that normalizes various exponent notations (Python **, Vietnamese 'mũ'/'lũy thừa') into the caret ^ operator used by mathjs.
    function normalizeExponent(s: string): string {
      let t = s;
    
      // Python style
      t = t.replace(/\*\*/g, '^');
    
      // "mũ", "mu" (viết không dấu), "lũy thừa"
      // ví dụ: "5 mũ 10" -> "5 ^ 10"
      t = t.replace(/\s*(m[ũu]|lu[ũu]y\s*thừa)\s*/gi, ' ^ ');
    
      // tuỳ chọn: gom nhiều khoảng trắng
      t = t.replace(/\s+/g, ' ').trim();
      return t;
  • src/server.ts:29-36 (registration)
    Registration of the 'calc_eval' tool as an alias of 'calc.eval'. Uses Zod schema for input validation (expr: string, precision: optional integer 0-64), calls calcEval, and returns JSON-stringified result as text content.
    server.tool('calc_eval', 'Alias of calc.eval',
      { expr: z.string(), precision: z.number().int().min(0).max(64).optional() },
      OPEN,
      async ({ expr, precision }) => {
        const res = await calcEval(expr, precision);
        return { content: [{ type: 'text', text: JSON.stringify(res) }] };
      }
    );
  • Input schema for calc_eval: 'expr' (required string) and 'precision' (optional integer, min 0, max 64).
    { expr: z.string(), precision: z.number().int().min(0).max(64).optional() },
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description provides no behavioral details beyond being an alias. The annotation 'openWorldHint: true' suggests unknown side effects, but the description does not clarify what those might be. For a tool with no annotation coverage on safety or behavior, the description should compensate but fails to do so.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely short, consisting of a single phrase. While concise, it is under-specified and does not convey enough information to be useful. It sacrifices clarity for brevity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of an output schema, two parameters with zero coverage, and no descriptive text, the definition is severely incomplete. The agent lacks critical context to invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must explain parameters but does not. It mentions neither 'expr' nor 'precision', leaving the agent without context on their meaning, format, or constraints beyond what the schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states 'Alias of calc.eval', which indicates a relationship but fails to explain what the tool does. The name 'calc_eval' hints at evaluating a calculation, but without further context, the agent cannot discern its specific purpose. It does not distinguish itself from the sibling 'calc.eval'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidelines are provided about when to use this tool versus alternatives. The description only states it is an alias, offering no context for usage scenarios, prerequisites, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/khanhs-234/tool4lm'

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