Skip to main content

License: MIT AI Assisted

Calculator MCP Server

calculator-mcp is a small 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:

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

The calculator-mcp can be installed by running pip install calculator-mcp-rubens. It requires python 3.14+ and pip to run.

  • To install locally into the user's home environment:

    # install "calculator-mcp" and depdencies into user local pip environment
    pip install --user calculator-mcp-rubens --verbose
    

Usage

Running the MCP Server

  • Launch calculator-mcp locally with sensible defaults:

    # Launches the Streamable HTTP MCP server locally at:
    # http://0.0.0.0:9000/mcp
    # The "0.0.0.0" is used because this application is meant to run from
    # within a Docker container, which requires the wildcard address, or
    # INADDR_ANY, to accept HTTP connections from outside the container.
    calculator-mcp
    

Exercise the MCP Server Endpoints

  1. Health check

    curl -v http://localhost:9000/health
    # Expect: OK
    
  2. Initialize MCP session

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

  • a) Store 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
    
  • b) MCP client initializes session — grab the Mcp-Session-Id from the response headers

    # Look for the "mcp-session-id: <SID>" header in the output
    curl -i http://localhost:9000/mcp \
    -H "Content-Type: application/json" \
    -H "Accept: application/json, text/event-stream" \
    -d @/tmp/initialize.json
    
  • c) MCP client sends the required "initialized" notification (use the SID from step b)

    SID="<paste-mcp-session-id-here>"
    # Expect "202 Accepted" response
    curl -v http://localhost:9000/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"}'
    
  1. List tools
  • Once you have initialized your MCP session, list all the tools:

    curl -s http://localhost:9000/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.

  1. Call a tool (e.g. add)
  • To call one of the tools (e.g., add)

    curl -s http://localhost:9000/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}}}'
    

Returns {"result": 5.0} in structuredContent. Swap name and arguments to call any other tool, e.g. {"name": "divide", "arguments": {"a": 15, "b": 4}} or {"name": "sqrt", "arguments": {"a": 16}}.

Note: the same Mcp-Session-Id must be reused across steps b, c, 3, and 4 — the server ties the session to that ID.

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.

The configuration file has three sections. The logging section controls Python logging via dictConfig. The default configuration logs calculator_mcp messages at DEBUG level to stderr.

# =============================================================================
# Server Configuration
# =============================================================================
server:
    # the home page of this project
    homepage: "https://github.com/rubensgomes-org/calculator-mcp"
    # MCP transport: "stdio" or "http"
    # http: for web services using the Streamable HTTP protocol
    transport: "http"
    # Host IP address for the HTTP/MCP server.
    # 0.0.0.0 binds all interfaces, which is required inside a container.
    # Use 127.0.0.1 to restrict the server to localhost only.
    host: "0.0.0.0"
    # Port for the HTTP/MCP server.
    port: 9000
    # timeout in seconds
    timeout: 10

# =============================================================================
# Client Configuration
# =============================================================================
client:
    # the URL the client should use when the server transport is "http"
    #    is_oauth: false
    #    url: "http://127.0.0.1:9000/mcp"
    is_oauth: true
    url: "https://rubens-calculator-mcp.fastmcp.app/mcp"
    # location to store OAuth token
    token_dir: "~/.fastmcp"
    # fixed port for the OAuth callback server
    callback_port: 10000

# =============================================================================
# Logging Configuration
# =============================================================================
logging:
    version: 1
    disable_existing_loggers: false
    formatters:
        standard:
            format: "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
    handlers:
        console:
            class: logging.StreamHandler
            formatter: standard
            stream: ext://sys.stderr
    loggers:
        calculator_mcp:
            level: DEBUG
            handlers:
                - console
            propagate: false
        # MCP protocol tracing — set to DEBUG to see full JSON-RPC messages
        mcp.client.streamable_http:
            level: INFO
            handlers:
                - console
            propagate: false
        # HTTP request/response summaries — set to DEBUG for detail
        httpx:
            level: DEBUG
            handlers:
                - console
            propagate: false
        # HTTP wire-level tracing (headers, TCP) — set to DEBUG for detail
        httpcore:
            level: INFO
            handlers:
                - console
            propagate: false
        # Server: inbound JSON-RPC messages — set to DEBUG to see parsed requests
        mcp.server.lowlevel.server:
            level: INFO
            handlers:
                - console
            propagate: false
        # Server: StreamableHTTP transport — set to DEBUG for method-level tracing
        mcp.server.streamable_http:
            level: INFO
            handlers:
                - console
            propagate: false
        # Server: session/transport lifecycle — set to DEBUG for session details
        mcp.server.streamable_http_manager:
            level: INFO
            handlers:
                - console
            propagate: false
        # Server: HTTP request lines (method, path, status)
        uvicorn.access:
            level: INFO
            handlers:
                - console
            propagate: false
    root:
        level: WARNING
        handlers:
            - console

License

The project is licensed under MIT License.


Author: Rubens Gomes

Release files for calculator-mcp-rubens 0.0.2

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.2
File Size Uploaded
calculator_mcp_rubens-0.0.2.tar.gz 11.1 kB Details

Built distribution (wheel)

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

Total release size: 26.4 kB

Release files / calculator_mcp_rubens-0.0.2.tar.gz

Download URL calculator_mcp_rubens-0.0.2.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
468c713437bd362a71d4d82a655e972490eb5713875ffc6d73364f5f3412aa36
BLAKE2b-256 checksum
How to use checksums
cd10bda566bbe8d1784567bb329e60c1ca6060f0ae351cf23225910542eed9b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.7 Darwin/27.0.0

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

Download URL calculator_mcp_rubens-0.0.2-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f865482cee211b43e3647da7c6b94e938803b068b498d99bdb3503550bf264fa
BLAKE2b-256 checksum
How to use checksums
cd546d36cba6e05ad5c436808ea1b10784fd13bec0351ac886969b258742963f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.7 Darwin/27.0.0

Release history Release notifications | RSS feed

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

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

This release

0.0.2 This release

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