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 整合