Skip to main content
Glama
calc_mcp

calc_mcp

by nocodig

calc_mcp

A calculator MCP service that provides addition, subtraction, multiplication, and division over stdio.

It uses the FastMCP API from the official MCP Python SDK, with dependencies pinned to 1.x to avoid interface changes from major version upgrades.

Available tools

All tools take two required numeric arguments, a and b, and support integers, decimals, and negative numbers.

Tool

Operation

Example arguments

Result

add

a + b

{"a": 2, "b": 3}

5.0

subtract

a - b

{"a": 2, "b": 5}

-3.0

multiply

a * b

{"a": -3, "b": 4}

-12.0

divide

a / b

{"a": 7, "b": 2}

3.5

A successful call returns {"result": 数值} as structuredContent, along with compatible text content. The tools do not read or write files and do not access the network.

Errors are returned with isError: true in the MCP tool result and do not interrupt the service:

  • Divisor is 0 or -0.0: Cannot divide by zero.

  • Operand is NaN or infinity: Operands must be finite numbers.

  • Result overflows to infinity: Result exceeds the supported finite number range.

  • Missing arguments or values that cannot be parsed as numbers: the SDK returns an argument validation error.

Arithmetic uses Python double-precision floating-point numbers, so the usual floating-point rounding errors apply; for example, 0.1 + 0.2 may return 0.30000000000000004. It is not meant for scenarios that require exact decimal arithmetic; this version does not support expression evaluation.

Related MCP server: My Calculator MCP Server

Directory structure

calc_mcp/
├── pyproject.toml          # 项目、依赖和命令行入口
├── uv.lock                 # 依赖版本锁定
├── README.md
├── .gitignore
├── src/calc_mcp/
│   ├── __init__.py
│   ├── __main__.py         # python -m calc_mcp 入口
│   ├── server.py           # MCP 实例和 stdio 启动
│   └── tools.py            # 四则运算、边界检查和工具注册
└── tests/
    └── test_server.py      # 算术单元测试和 stdio 集成测试

Installation and startup

Requires Python 3.10+ and uv. Run the following in the project directory:

uv sync
uv run calc-mcp

You can also start it via the module entry point:

uv run python -m calc_mcp

The service communicates with MCP clients over standard input/output and does not provide a web page. It is normal for it to wait for client messages right after startup. Do not print debug information to stdout; logs should be written to stderr.

MCP client configuration example

The following applies to clients that use the mcpServers JSON configuration format; adjust it to match your client:

{
  "mcpServers": {
    "calc-mcp": {
      "command": "uv",
      "args": [
        "--directory",
        "/Users/lifang/product/0826/calc_mcp",
        "run",
        "calc-mcp"
      ]
    }
  }
}

If the client cannot find uv, change command to the absolute path of the uv executable. After moving the project, update the directory path accordingly.

Verification

uv run python -m unittest discover -s tests -v

The tests cover the four arithmetic operations, negative numbers, decimals, zero, invalid arguments, non-finite numbers, and overflow. They also launch a real stdio subprocess to check MCP initialization, tool discovery, tool invocation, and normal calls after errors.

Future extension points

Add tool definitions in src/calc_mcp/tools.py and include the functions in the registration list of register_tools(). create_server() in server.py registers all tools centrally.

Available Tools

4 tools
addA
Read-onlyIdempotent

Add two finite numbers: a + b.

Inputs: a (required), b (required). Returns: result

divideA
Read-onlyIdempotent

Divide a by b: a / b. Operands must be finite and b must not be zero.

Inputs: a (required), b (required). Returns: result

multiplyA
Read-onlyIdempotent

Multiply two finite numbers: a * b.

Inputs: a (required), b (required). Returns: result

subtractA
Read-onlyIdempotent

Subtract b from a: a - b. Both operands must be finite numbers.

Inputs: a (required), b (required). Returns: result

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool maps to a single, distinct arithmetic operation: addition, subtraction, multiplication, or division. There is no overlap or ambiguity between tool purposes.

    Naming Consistency5/5

    All tool names follow the same simple verb-only pattern: add, subtract, multiply, divide. The naming is perfectly consistent and instantly predictable.

    Tool Count5/5

    Four tools is the ideal size for a basic arithmetic calculator server. Each tool covers a fundamental operation without unnecessary bloat.

    Completeness5/5

    The tool set fully covers the core arithmetic operations needed for a calculator: addition, subtraction, multiplication, and division, with appropriate edge-case handling for division by zero. It is a complete minimal surface for its stated purpose.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      D
      quality
      D
      maintenance
      Provides basic mathematical operations (addition, subtraction, multiplication, division) through a calculate tool. Supports both stdio and HTTP/SSE transport modes.
      1
      ISC
    • A
      license
      Not graded
      quality
      D
      maintenance
      Exposes add, subtract, multiply, and divide tools for performing arithmetic operations over stdio via the Model Context Protocol.
      ISC
    • F
      license
      A
      quality
      C
      maintenance
      Enables an LLM client to perform basic arithmetic on two numbers — addition, subtraction, multiplication, and division — plus reverse a supplied text string, through five simple tools exposed over stdio. Inputs and structured text results follow JSON schemas, with invalid operations such as division by zero surfaced as tool errors.
      5
      -