Calculator

io.github.slettmayer由 GitHub 账号 slettmayer 发布v0.1.9更新于 Oct 24, 2026

Exact arithmetic: one calculator tool over an AST allowlist, with integers exact at any size.

发布方自己的服务:calc.engineer

已验证STDIO仅桌面开发者工具

概览

AI 生成的概览

一个本地 MCP 服务器,提供单个 calculate 工具精确计算算术表达式,让助手不必心算数学。

可以做什么
计算含 +、-、*、/、//、%、** 与括号的算术表达式,也接受 Unicode 运算符变体和正负号,结果以字符串返回,出错时返回以 Error 开头的说明而非调用失败。使用 pi、e、tau 常量以及 sqrt、log、三角函数、factorial、gcd、lcm 等函数。整数在任意大小下保持精确,浮点数按 12 位有效数字输出以去除表示误差。
适用场景
当助手需要可靠的四则运算、大整数乘法或科学函数而不应自行估算时适合添加;也适合想要一个范围受限、用途单一的本地计算服务器而非通用代码执行工具的场景。
运行要求
作为本地 stdio 进程运行,通过 uvx 从 PyPI 包 calc-mcp-server 启动,需要 Python 环境及 uv/uvx。未声明任何账号、API 密钥、环境变量或请求头。README 建议固定版本,不要使用 @latest。
安装前请注意
该工具只做计算,不读写文件也不访问网络。表达式按允许列表解析,并受长度、嵌套深度、结果位数和阶乘参数上限约束,过大或嵌套过深的输入会返回 Error 说明而不会被求值。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Calculator,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

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.25sqrt(16) + sin(pi/2)       ->  5.0123456789 * 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

bash
uvx calc-mcp-server

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

Configure

As a stdio MCP server:

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

The calculate tool

ArgumentTypeDescription
expressionstrThe 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).

Constants — pi, e, tau.

Functions — abs 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

bash
uv syncuv run pytest tests/ -vuv 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.

来源:README.md,提交 b2e8ffa

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v0.1.9最新Sep 18, 2026
  2. v0.1.8Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

其他 Calc 集成