Skip to main content
Glama
Math & Statistics Calculator API for AI Agents

Math & Statistics Calculator API for AI Agents

by chunyunglo

Math & Statistics Calculator API for AI Agents

Stop letting your LLM guess numbers. This Actor evaluates math expressions safely and computes basic statistics for a list of numbers, deterministically, in one call. It works as a normal Apify Actor (API, schedules, integrations) and also as an MCP server so AI agents can call it as a tool.

What it does

  • Expression evaluation: arithmetic (+ - * / // % **), parentheses, constants (pi, e, tau) and functions (sqrt, sin, cos, tan, asin, acos, atan, log, log10, log2, exp, floor, ceil, abs, round, min, max, sum, factorial, gcd, radians, degrees, mean, median, stdev, variance). Expressions are parsed into a syntax tree and only a whitelist of numeric operations is executed. Python eval is never used.

  • Statistics: count, sum, mean, median, mode, min, max, range, sample variance and standard deviation, population variance and standard deviation.

  • Floating point noise is rounded away (0.1 + 0.2 gives 0.3), configurable with decimals.

Related MCP server: mcp-math-tools

Input example

{
  "expressions": ["(12.5 * 4) + sqrt(144)"],
  "numbers": [2, 4, 4, 4, 5, 5, 7, 9],
  "statistics": ["mean", "median", "mode", "pstdev"],
  "decimals": 10
}

Provide expressions, numbers, or both. statistics is optional (default: all).

Output example

[
  {"type": "expression", "expression": "(12.5 * 4) + sqrt(144)", "result": 62},
  {"type": "statistics", "mean": 5, "median": 4.5, "mode": [4], "pstdev": 2}
]

mode is always a list because a data set can have several modes. variance and stdev are null when fewer than two numbers are given.

Pricing

US$0.002 per run (event: Calculation run), regardless of how many expressions or numbers are in the run.

Limits

  • Up to 1000 expressions per run, each up to 1000 characters.

  • Up to 100,000 numbers per run.

  • Integer bases and exponents in ** are capped at 10,000; factorial accepts 0-1000; results larger than 1e300 are rejected.

  • Use ** for powers. ^ is rejected to avoid silent XOR mistakes.

  • Only numbers are supported (no strings, variables or complex numbers).

  • Invalid input (unknown function, division by zero, non-numeric result) stops the run with a clear error message.

  • Results are IEEE double precision, not arbitrary-precision decimals (except integer arithmetic, which is exact).

Credits

This Actor is built on the Python standard library (ast, math and statistics modules), distributed under the Python Software Foundation License. It does not wrap a third-party open-source project.


Hosted version: Apify Store · Docs: https://chunyunglo.github.io/afw-tools/math-statistics-calculator-api/

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      A
      quality
      D
      maintenance
      Enables mathematical calculations through basic arithmetic operations including addition, subtraction, multiplication, division, exponentiation, and logarithms. Provides a simple interface for AI agents to perform mathematical computations.
      6
      3
      -
    • A
      license
      A
      quality
      D
      maintenance
      Enables safe math expression evaluation, unit conversion, statistical analysis, number formatting, and percentage calculations for AI agents via MCP.
      5
      48 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Provides exact, deterministic tools for math, dates, units, validation, and more to AI agents, returning precise answers with explicit assumptions and warnings instead of model guesses.
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Provides LLMs with deterministic math tools for sandboxed expression evaluation, descriptive statistics, primality testing, prime factorization, GCD/LCM, quadratic solving, and base conversion. Every operation runs real code rather than relying on the model's arithmetic, with expression parsing restricted to a whitelist of operators, constants, and functions.
      21
      11 PyPI
      1
      MIT