Skip to main content
Glama
calculator-mcp-server

calculator-mcp-server

by Amankhan1009

Calculator MCP Server

A Model Context Protocol server exposing calculator operations, built as a learning project.

Tools

  • add(a, b)

  • subtract(a, b)

  • multiply(a, b)

  • divide(a, b)

  • power(base, exponent)

  • square_root(number)

  • modulus(a, b)

Related MCP server: Calculator MCP

Run

uv run mcp dev src/calculator_mcp/server.py

Test

uv run pytest tests/ -v

Architecture

  • operations.py — pure calculator logic, no MCP dependency

  • server.py — FastMCP tool registration, thin wrappers over operations.py

  • exceptions.py — custom exception hierarchy (CalculatorError base)

  • tests/ — pytest unit tests, independent of the MCP layer

Connect to Claude Desktop

Add this to claude_desktop_config.json:

{
  "mcpServers": {
    "calculator": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/calculator-mcp-server", "mcp", "run", "src/calculator_mcp/server.py"]
    }
  }
}

This structure generalizes to any MCP server: keep domain logic separate from protocol code, use typed exceptions per failure mode, annotate tools honestly (readOnly/idempotent/destructive/openWorld), and test the logic layer without needing a live server.

Available Tools

7 tools
addA
Read-onlyIdempotent

Add two numbers together.

Args: a: The first number. b: The second number.

Returns: The sum of a and b.

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

divideA
Read-onlyIdempotent

Divide the first number by the second.

Args: a: The number to be divided (the dividend). b: The number to divide by (the divisor). Must not be zero.

Returns: The result of a divided by b.

Raises: DivisionByZeroError: If b is zero.

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

modulusA
Read-onlyIdempotent

Compute the remainder when dividing a by b.

Args: a: The dividend. b: The divisor. Must not be zero.

Returns: The remainder of a divided by b.

Raises: DivisionByZeroError: If b is zero.

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

multiplyA
Read-onlyIdempotent

Multiply two numbers together.

Args: a: The first number. b: The second number.

Returns: The product of a and b.

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

powerA
Read-onlyIdempotent

Raise a number to a power.

Args: base: The base number. exponent: The power to raise the base to.

Returns: base raised to the power of exponent.

Raises: InvalidPowerOperationError: If the result would be complex, or if the computation overflows.

Inputs: base (required), exponent (required). Returns: result

square_rootA
Read-onlyIdempotent

Compute the square root of a number.

Args: number: The number to take the square root of. Must be non-negative.

Returns: The square root of number.

Raises: NegativeSquareRootError: If number is negative.

Inputs: number (required). Returns: result

subtractA
Read-onlyIdempotent

Subtract the second number from the first.

Args: a: The number to subtract from. b: The number to subtract.

Returns: The result of a minus b.

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 7 tools

    Disambiguation5/5

    Each tool performs a distinct mathematical operation: add, subtract, multiply, divide, modulus, square_root, and power. There is no overlap or ambiguity between them, so an agent will never have to guess which tool to use for a given operation.

    Naming Consistency4/5

    The names are clear and short, but not perfectly uniform: add, subtract, multiply, divide, and power are verbs, while modulus and square_root are nouns. However, this is a common and readable convention for math operations, and the intent is obvious.

    Tool Count5/5

    With 7 tools, the server is well-scoped for a calculator. It covers basic arithmetic plus modulus, square root, and power, which is a reasonable and expected set for the purpose without unnecessary bloat.

    Completeness4/5

    The core arithmetic and common math operations are present, providing good coverage for a calculator server. Minor omissions like absolute value or factorial exist, but they are not essential for the primary purpose and agents can typically work around them.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides basic arithmetic operations and advanced mathematical functions through the Model Context Protocol (MCP), with features like calculation history tracking and expression evaluation.
      1
      -
    • A
      license
      B
      quality
      D
      maintenance
      Provides mathematical computation capabilities including basic arithmetic operations (add, subtract, multiply, divide), advanced functions (square root, factorial, logarithm), and trigonometric functions (sin, cos, tan) through the Model Context Protocol.
      5
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Provides basic mathematical operations including addition, subtraction, multiplication, division, and power calculations through a Model Context Protocol interface.
      5
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides basic arithmetic operations (add, multiply, divide) for AI assistants through the Model Context Protocol.
      ISC