Skip to main content

Calculator MCP Server

PyPI Python License: MIT

An MCP server that does arithmetic, exactly — so an LLM does not have to do it mentally.

One tool, calculate, evaluating expressions against a hand-rolled AST allowlist. No eval(), no sympy, no unbounded dependencies.

2 + 3 * (4 - 1) / 2 ** 2   ->  4.25
sqrt(16) + sin(pi/2)       ->  5.0
123456789 * 987654321      ->  121932631112635269

Why this exists

The widely-used mcp-server-calculator package is abandoned (last commit May 2025) and declares mcp>=1.4.1 with no upper bound. When the MCP Python SDK released v2 and removed mcp.server.fastmcp, every uvx …@latest install of it started crashing on import — which took down the entire MCP proxy hosting it, and every other server alongside it.

No maintained Python replacement exists. The one actively-maintained npm calculator computes in float64, so 123456789 * 987654321 comes back as 121932631112635260 — off by 9. That is a poor trait in a tool whose whole purpose is that the model should not be doing the arithmetic itself.

So this server:

  • bounds its one dependency (mcp[cli]>=2,<3) — the failure above cannot recur here;
  • keeps integers exact at any size, never coercing to float;
  • bounds resource use, not just code execution — see below.

Safety

Two problems, and most calculator servers only solve the first.

Code execution. Expressions are parsed with ast.parse and walked against an explicit allowlist of node types. Attribute is not on it, so (1).__class__.__bases__ is rejected. A Call is only evaluated when its target is a bare name in the function allowlist, so __import__('os').system(…) is rejected before any argument is even evaluated.

Resource exhaustion. An allowlist alone still lets 9**9**9 occupy the process for minutes on unbounded bignum exponentiation — the incumbent hangs for over five seconds on it. Four caps close that: expression length (500 chars), nesting depth (32), result size (4300 digits, checked on the operands before exponentiating), and factorial argument (1000).

Full detail in docs/tech/SAFE-EVALUATION.md.

Install

uvx calc-mcp-server

Pin it. Do not add @latest — that is how the package this replaces broke.

Configure

As a stdio MCP server:

{
  "mcpServers": {
    "calculator": {
      "command": "uvx",
      "args": ["calc-mcp-server"]
    }
  }
}

The calculate tool

Argument Type Description
expression str The expression to evaluate

Returns the result as a string, or a line starting with Error: explaining why the expression was rejected. The tool never raises, so a bad expression is an answer the agent can read back rather than a tool-call failure.

Operators+ - * / // % **, parentheses, unary +/-. ^ is accepted as a power operator, and × · ÷ are accepted as their ASCII equivalents (speech-to-text produces them).

Constantspi, e, tau.

Functionsabs round min max sqrt exp log log2 log10 sin cos tan asin acos atan atan2 degrees radians hypot floor ceil factorial gcd lcm.

Results — integer arithmetic returns an exact integer of any size. Floats are rendered at 12 significant digits, which removes IEEE-754 representation noise (0.1 + 0.2 reads 0.3, not 0.30000000000000004) while keeping far more precision than a calculator result is used at. A whole float keeps its .0, so 8 / 2 reads 4.0 and stays distinct from the exact integer 4.

Development

uv sync
uv run pytest tests/ -v
uv run ruff check .
uv run ruff format .

See AGENTS.md for the project guide and docs/ for the full documentation set.

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

calc_mcp_server-0.1.6.tar.gz (87.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

calc_mcp_server-0.1.6-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file calc_mcp_server-0.1.6.tar.gz.

File metadata

  • Download URL: calc_mcp_server-0.1.6.tar.gz
  • Upload date:
  • Size: 87.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for calc_mcp_server-0.1.6.tar.gz
Algorithm Hash digest
SHA256 82d5c52bd2c59ce0bcbf687c5183a6e114d1b7ec689a7811850d1ac1c70ac55f
MD5 993919203c6d8763e55b78dd74a65746
BLAKE2b-256 15085ed68b879509a59710a6946e710db7afa1c26b1a6712ad12eb2be49117b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for calc_mcp_server-0.1.6.tar.gz:

Publisher: release.yml on slettmayer/calc-mcp-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file calc_mcp_server-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: calc_mcp_server-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for calc_mcp_server-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 187a16d3e2ee7434e0a28dbc9596d674ba88d14ba0a000f4f940f85cde1b875c
MD5 84cf7d7da7a183f3e33e5d45c61304ca
BLAKE2b-256 bf190bc1c2fb5561a2b8128f6c7785fce82f6f519b8ca7a80ec8280676b030e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for calc_mcp_server-0.1.6-py3-none-any.whl:

Publisher: release.yml on slettmayer/calc-mcp-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.8

2 files

0.1.7

2 files

This release

0.1.6 This release

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page