Skip to main content
Glama
cyanheads

calculator-mcp-server

by cyanheads

Version License Docker MCP SDK npm TypeScript Bun

Install in Claude Desktop Install in Cursor Install in VS Code

Framework

公共托管服务器: https://calculator.caseyjhand.com/mcp


工具

一个工具即可完成所有数学运算:

工具名称

描述

calculate

对数学表达式求值、化简代数表达式,或计算符号导数。

calculate

一个工具即可覆盖服务器的全部用途。operation 参数默认为 evaluate,因此常见用法只需 { expression: "..." }

  • 求值(Evaluate) — 算术、三角函数、对数、统计、矩阵、复数、单位换算、组合数学

  • 化简(Simplify) — 以符号方式化简代数表达式(例如 2x + 3x -> 5 * x)。支持代数和三角恒等式

  • 求导(Derivative) — 计算符号导数(例如 3x^2 + 2x + 1 -> 6 * x + 2

  • 通过 scope 参数设置变量作用域:{ "x": 5, "y": 3 }

  • 数值结果精度可配置

  • 基于表单的 MCP 客户端传入的空白可选 variableprecision 值将被视为未提供


Related MCP server: math-mcp

资源

URI 模式

描述

calculator://help

可用函数、运算符、常量和语法参考。


特性

基于 @cyanheads/mcp-ts-core 构建:

  • 声明式工具定义 — 每个工具一个文件,框架负责注册和验证

  • 所有工具统一错误处理

  • 结构化日志,支持可选的 OpenTelemetry 追踪

  • 本地运行(stdio/HTTP)或 Docker 运行

计算器专属特性:

  • 加固的 math.js v15 实例 — 禁用危险函数,通过 vm.runInNewContext() 在沙箱中求值并设置超时

  • 无需认证 — 所有操作均为只读且无状态

  • 输入验证:表达式长度限制、拒绝表达式分隔符(分号和换行)、仅允许数值型作用域值

  • 结果验证:阻止危险结果类型(函数、解析器、结果集),可配置最大结果大小

  • 作用域净化:仅允许数值型值,防止原型污染(阻止 __proto__constructor 等)


快速开始

公共托管实例

公共实例位于 https://calculator.caseyjhand.com/mcp — 无需安装。通过 Streamable HTTP 将任意 MCP 客户端指向该地址:

{
  "mcpServers": {
    "calculator-mcp-server": {
      "type": "streamable-http",
      "url": "https://calculator.caseyjhand.com/mcp"
    }
  }
}

自托管 / 本地

将以下配置之一添加到您的 MCP 客户端配置文件中:

{
  "mcpServers": {
    "calculator-mcp-server": {
      "type": "stdio",
      "command": "bunx",
      "args": ["@cyanheads/calculator-mcp-server@latest"]
    }
  }
}

或使用 npx(无需 Bun):

{
  "mcpServers": {
    "calculator-mcp-server": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@cyanheads/calculator-mcp-server@latest"]
    }
  }
}

或使用 Docker:

{
  "mcpServers": {
    "calculator-mcp-server": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "MCP_TRANSPORT_TYPE=stdio",
        "ghcr.io/cyanheads/calculator-mcp-server:latest"
      ]
    }
  }
}

前置要求

安装

  1. 克隆仓库:

git clone https://github.com/cyanheads/calculator-mcp-server.git
  1. 进入目录:

cd calculator-mcp-server
  1. 安装依赖:

bun install

配置

变量

描述

默认值

CALC_MAX_EXPRESSION_LENGTH

允许的最大表达式字符串长度(10–10,000)。

1000

CALC_EVALUATION_TIMEOUT_MS

最大求值时间(毫秒)(100–30,000)。

5000

CALC_MAX_RESULT_LENGTH

最大结果字符串长度(字符数)(1,000–1,000,000)。

100000

MCP_TRANSPORT_TYPE

传输方式:stdiohttp

stdio

MCP_HTTP_HOST

HTTP 服务器的主机名。

localhost

MCP_HTTP_PORT

HTTP 服务器的端口。

3010

MCP_HTTP_ENDPOINT_PATH

HTTP MCP 端点的路径。

/mcp

MCP_HTTP_MAX_BODY_BYTES

最大入站 HTTP 请求大小;0 表示不限制。

1048576

MCP_AUTH_MODE

认证模式:nonejwtoauth

none

MCP_LOG_LEVEL

日志级别(RFC 5424)。

info

有关可选的会话、可恢复性、日志和遥测设置,请参阅 .env.example


运行服务器

本地开发

  • 构建并运行生产版本:

    bun run build
    bun run start:http   # or start:stdio
  • 运行检查和测试:

    bun run devcheck     # Lints, formats, type-checks
    bun run test         # Runs test suite

Docker

docker build -t calculator-mcp-server .
docker run -p 3010:3010 calculator-mcp-server

该镜像默认以 Streamable HTTP 模式运行在端口 3010 上,使用无状态会话,日志输出到 /var/log/calculator-mcp-server


项目结构

目录

用途

src/mcp-server/tools/

工具定义(*.tool.ts)。

src/mcp-server/resources/

资源定义(*.resource.ts)。

src/services/

领域服务集成(MathService)。

src/config/

使用 Zod 进行环境变量解析和验证。

docs/

生成的目录树。


开发指南

有关开发指南和架构规则,请参阅 AGENTS.mdCLAUDE.md。简要说明:

  • 处理器抛出异常,框架负责捕获 — 工具逻辑中不使用 try/catch

  • 使用 ctx.log 记录日志

  • src/index.ts 中注册新工具和资源


贡献

欢迎提交 Issue 和 Pull Request。提交前请先运行检查:

bun run devcheck
bun run test

许可证

Apache-2.0 — 详情请参阅 LICENSE

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

No tool schema history has been recorded yet.

Maintenance

ActivityMaintained
ResponsivenessResponsive

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    A
    maintenance
    Provides secure mathematical computation capabilities including expression evaluation, symbolic math (derivatives, simplification), matrix operations, statistics, and unit conversion, with multi-tier acceleration through WebAssembly and WebWorkers for high-performance calculations.
    7
    178
    ISC
  • A
    license
    A
    quality
    C
    maintenance
    A secure MCP server for evaluating mathematical expressions with grammar validation, function whitelisting, and sandboxed execution. It provides tools for expression evaluation, variable management, and resources for grammar and function documentation.
    6
    37
    MIT
  • A
    license
    B
    quality
    C
    maintenance
    High-precision mathematics server for MCP clients, providing exact integer arithmetic, symbolic derivatives, and numerical calculus via LaTeX-style input.
    6
    7
    2
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Provides a token-efficient exact math engine for AI agents, enabling computation of derivatives, integrals, equations, and optimized Python/NumPy code via a single MCP tool.
    4
    MIT

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/cyanheads/calculator-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server