Skip to main content

License: MIT AI Assisted

Calculator MCP Server

calculator-mcp is a Streamable HTTP MCP (Model Context Protocol) server that exposes 16 arithmetic operations as callable tools for an AI LLM (Large Language Model) to consume. It contains no math of its own — every tool is a thin synchronous wrapper that logs its arguments and delegates to an open-source shared math calculator calculator-lib-rubens PyPI library package.

Features

16 calculator tools available via MCP based on JSON-RPC 2.0 messages:

Two-operand operations: add, subtract, multiply, divide, power, nth_root, modulo, floor_divide

Single-operand operations: sqrt, absolute, floor, ceil, log10, ln, exp

Rounding: round_number (with configurable decimal places)

AI Disclaimer

This project includes code and documentation created with the assistance of AI tools. For details on usage, limits, and review practices, please see the AI Disclaimer.

Prerequisites

  • Python 3.14+
  • pip 26.2+
  • curl 8.7+

Installation and Usage

Installation

IMPORTANT: release versioning was recently reset to start again at version 0.0.1. Uninstall any previously installed version first.

  • Uninstall any previously installed release:

    pip uninstall calculator-mcp-rubens
    # recommend to purge the cache as well
    pip cache purge
    
  • To install into the user's home environment run command below

    # install "calculator-mcp" and dependencies into user local pip environment
    # NOTE: use --no-cache-dir to avoid issues with earlier version in cache
    pip --no-cache-dir install -U --user calculator-mcp-rubens --verbose
    
  • Confirm installed version with most recently released GitHub version at calculator-mcp/releases

    # show the installed version
    pip show calculator-mcp-rubens
    

Usage

Configuration

The server ships with a default config.yaml bundled inside the package. To override it, set the CALCULATOR_MCP_CONFIG environment variable to the absolute path of your custom configuration file:

export CALCULATOR_MCP_CONFIG=/path/to/your/config.yaml

When CALCULATOR_MCP_CONFIG is not set, the bundled default is used automatically. For more information about how to set up the config.yaml and further documentation, refer to config.yaml

Running the MCP Server

  • Launch calculator-mcp locally:

    calculator-mcp
    
  • Health check

    curl -v http://localhost:8080/health
    # Expect: OK
    

Legacy Era (Pre-July 2026)

The Legacy Era MCP server is based on a stateful session state that requires a connection setup handshake using initialize / initialized JSON-RPC messages.

NOTE To run the "Legacy Era" protocol change the config.yaml server -- > stateless to false.

1. Initialize MCP session

The MCP endpoint requires a session, established via initialize first. Run these in order:

  • Store the JSON below in a local file /tmp/initialize.json:

    # remove indentation spaces when copying/pasting this command to the shell
    cat > /tmp/initialize.json <<EOF
    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "initialize",
      "params": {
        "protocolVersion": "2025-06-18",
        "capabilities": {},
        "clientInfo": {
          "name": "curl-test",
          "version": "1.0"
        }
      }
    }
    EOF
    
  • Initialize the session and grab the Mcp-Session-Id from the response headers:

    # Look for the "mcp-session-id: <SID>" header in the output
    curl -i http://localhost:8080/mcp \
      -H "Content-Type: application/json" \
      -H "Accept: application/json, text/event-stream" \
      -d @/tmp/initialize.json
    
  • Send the required notifications/initialized notification (use the SID obtained above):

    SID="<paste-mcp-session-id-here>"
    # Expect "202 Accepted" response
    curl -v http://localhost:8080/mcp \
      -H "Content-Type: application/json" \
      -H "Accept: application/json, text/event-stream" \
      -H "Mcp-Session-Id: $SID" \
      -d '{"jsonrpc":"2.0","method":"notifications/initialized"}'
    

2. List tools — tools/list

Once you have initialized your MCP session, list all the tools:

curl -s http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Mcp-Session-Id: $SID" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'

This returns all 16 tools: add, subtract, multiply, divide, power, nth_root, modulo, floor_divide, sqrt, absolute, floor, ceil, log10, ln, exp, round_number.

3. Call a tool (e.g. add) — tools/call

curl -s http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Mcp-Session-Id: $SID" \
  -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":
       {"name":"add","arguments":{"a":2,"b":3}}}'

Note: reuse the same Mcp-Session-Id (obtained during initialization) for every subsequent request — the server ties the session to that ID.

Modern Era (2026-07-28 Spec)

The Modern Era MCP server is stateless. Single-shot tools/call, no handshake needed.

NOTE To run the "Modern Era" protocol change the config.yaml server -- > stateless to true.

  • Server discovery:

    curl -sS -X POST http://localhost:8080/mcp \
      -H "Content-Type: application/json" \
      -H "Accept: application/json, text/event-stream" \
      -H "Mcp-Protocol-Version: 2026-07-28" \
      -H "Mcp-Method: server/discover" \
      -d '{
        "jsonrpc": "2.0",
        "id": 1,
        "method": "server/discover",
        "params": {
          "_meta": {
            "io.modelcontextprotocol/protocolVersion": "2026-07-28",
            "io.modelcontextprotocol/clientInfo": {"name": "curl", "version": "1.0"},
            "io.modelcontextprotocol/clientCapabilities": {}
          }
        }
      }'
    
  • List tools:

    curl -sS -X POST http://localhost:8080/mcp \
      -H "Content-Type: application/json" \
      -H "Accept: application/json, text/event-stream" \
      -H "Mcp-Protocol-Version: 2026-07-28" \
      -H "Mcp-Method: tools/list" \
      -d '{
        "jsonrpc": "2.0",
        "id": 2,
        "method": "tools/list",
        "params": {
          "_meta": {
            "io.modelcontextprotocol/protocolVersion": "2026-07-28",
            "io.modelcontextprotocol/clientInfo": {"name": "curl", "version": "1.0"},
            "io.modelcontextprotocol/clientCapabilities": {}
          }
        }
      }'
    

License

The project is licensed under MIT License.


Author: Rubens Gomes

Release files for calculator-mcp-rubens 0.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calculator-mcp-rubens 0.0.18
File Size Uploaded
calculator_mcp_rubens-0.0.18.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for calculator-mcp-rubens 0.0.18
File Interpreter ABI Platform
calculator_mcp_rubens-0.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 28.6 kB

Release files / calculator_mcp_rubens-0.0.18.tar.gz

Download URL calculator_mcp_rubens-0.0.18.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
edf6bdce329b50a485598a3baa2dcf9c78b8cdaba4d9b597e167d16b5b4249db
BLAKE2b-256 checksum
How to use checksums
63e58ed4c2f5782ffd73a561e2118f032f08cfcd7ef804f75c089002aa61f603
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.7 Linux/6.17.0-1022-azure

Release files / calculator_mcp_rubens-0.0.18-py3-none-any.whl

Download URL calculator_mcp_rubens-0.0.18-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f558ecadcd12f3b95e4895e8578b134dcaf72f342da3b28edc52f8c43a938cd
BLAKE2b-256 checksum
How to use checksums
02126948394c2d80390a7acc29be34ff666dbeb1e26ee0ab4d0bbc3e22a27930
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.7 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

This release

0.0.18 This release

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page