Skip to main content
Glama

calc_eval

Evaluate mathematical expressions and calculate results with configurable precision for accurate computations.

Instructions

Alias of calc.eval

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exprYes
precisionNo

Implementation Reference

  • Core handler function implementing the calculation logic: normalizes expression, evaluates with mathjs, applies precision formatting, returns success/error object.
    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' };
      }
    }
  • Zod input schema for calc_eval tool: required string expr, optional integer precision (0-64).
    { expr: z.string(), precision: z.number().int().min(0).max(64).optional() },
  • src/server.ts:29-36 (registration)
    MCP server registration of 'calc_eval' tool: defines name, description, schema, options, and thin async handler wrapper around calcEval.
    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) }] };
      }
    );
  • Helper utility to normalize mathematical expressions, converting ** to ^ and Vietnamese exponent terms (e.g., 'mũ', 'lũy thừa') to ^ for mathjs compatibility.
    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;
    }
Behavior3/5

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

The description adds minimal behavioral context beyond the openWorldHint annotation. While 'Alias of calc.eval' suggests this tool mirrors another tool's behavior, it doesn't explain what that behavior actually is - whether it's a read-only calculation, what precision means, or any limitations. The openWorldHint annotation suggests flexibility, but the description doesn't elaborate on this. No contradiction with annotations exists.

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

Conciseness5/5

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

The description is maximally concise with just three words. While this conciseness comes at the expense of completeness, every word earns its place by establishing the relationship to another tool. There's no wasted language or unnecessary elaboration.

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

Completeness2/5

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

For a tool with 2 parameters, 0% schema description coverage, no output schema, and only one annotation (openWorldHint), the description is severely inadequate. It doesn't explain what the tool does, how to use it, what parameters mean, or what to expect in return. The minimal annotation coverage means the description should carry more explanatory weight than it does.

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

Parameters2/5

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

With 0% schema description coverage for both parameters, the description carries full burden for explaining parameter meaning but provides zero information about 'expr' or 'precision'. The description doesn't mention that 'expr' is a mathematical expression to evaluate or that 'precision' controls decimal precision. This leaves both parameters completely undocumented despite the schema providing only type constraints.

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 'Alias of calc.eval' is a tautology that restates the tool name rather than explaining what it does. It doesn't specify the verb (evaluate/calculate) or the resource (mathematical expressions), nor does it distinguish this tool from its sibling 'calc.eval' which appears to be the same functionality. The description fails to communicate the tool's actual purpose.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't explain why there's both 'calc_eval' and 'calc.eval' in the sibling list, nor does it mention any context for choosing this tool over other calculation or evaluation tools. There's no indication of appropriate use cases or prerequisites.

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