Skip to main content

A calculator MCP server

Project description

Calculator MCP Server

An MCP (Model Context Protocol) server that exposes calculator operations as tools. Each tool delegates computation to the calculator-lib-rubens library.

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)

Prerequisites

  • Python 3.14+
  • Poetry for dependency management

Installation

poetry install

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 two sections:

server:
    transport: "http"     # "stdio" or "http"
    host: "127.0.0.1"     # Host for HTTP transport
    port: 9000            # Port for HTTP transport
    timeout: 10           # Tool execution timeout in seconds

client:
    is_oauth: false                        # Enable OAuth authentication
    url: "http://127.0.0.1:9000/mcp"       # Server URL for HTTP transport
    token_dir: "/home/user/.fastmcp"       # OAuth token storage directory
    callback_port: 10000                   # OAuth callback server port

The logging section controls Python logging via dictConfig. The default configuration logs calculator_mcp messages at INFO level to stderr.

Running the Server

There are three ways to start the server:

Console script (installed by Poetry):

# requires poetry to be installed
poetry install # only needed once
poetry run calculator-mcp

As a Python module:

# requires poetry to be installed
poetry install # only needed once
eval $(poetry env activate)
python -m calculator_mcp
deactivate

With a custom configuration:

# requires poetry to be installed
poetry install # only needed once
export CALCULATOR_MCP_CONFIG=/path/to/your/config.yaml
poetry run calculator-mcp

Running the Client

A sample integration test client is provided in tests/integration/client.py to demonstrate the MCP protocol with the server. It lists all available tools and calls each one with sample arguments.

Important: The server must be running before you start the client. See Running the Server above.

Run the client:

# requires poetry to be installed
poetry install # only needed once
eval $(poetry env activate)
python tests/integration/client.py
deactivate

Add MCP Server to Claude Code

  • Add the MCP server to Claude Code using project scope. The file .mcp.json is added to the project root folder:

    # It is assumed that the MCP server is running on http://127.0.0.1:9000
    cd $(git rev-parse --show-toplevel) || exit
    claude mcp add \
        --scope project \
        --transport http \
        calculator-mcp http://127.0.0.1:9000/mcp
    

Style Guide

This project follows the Google Python Style Guide. All docstrings use the Google format with Args:, Returns:, and Raises: sections where applicable. Compliance is enforced via pylint, black, isort, and mypy.

Development

# Run tests
poetry run pytest

# Run tests with coverage
poetry run pytest --cov

# Lint
poetry run pylint src/calculator_mcp

# Format code
poetry run black src tests
poetry run isort src tests

# Type check
poetry run mypy src/calculator_mcp

Project Structure

calculator-mcp/
├── pyproject.toml                 # Project metadata, dependencies, tool config
├── src/calculator_mcp/
│   ├── __init__.py
│   ├── __main__.py                # python -m calculator_mcp entry point
│   ├── config.py                  # Loads config.yaml, configures logging
│   ├── config.yaml                # Bundled default runtime config
│   ├── main.py                    # CLI entry point, signal handling
│   └── server.py                  # FastMCP server with 16 @mcp.tool functions
└── tests/
    ├── __init__.py
    ├── test_config.py             # Unit tests for config module
    ├── test_main.py               # Unit tests for main module
    ├── test_server.py             # Integration tests via MCP Client
    ├── test_tools.py              # Unit tests for tool functions
    └── integration/
        ├── __init__.py
        └── client.py              # Sample MCP client with OAuth support

License

See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

calculator_mcp_rubens-0.2.16.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

calculator_mcp_rubens-0.2.16-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file calculator_mcp_rubens-0.2.16.tar.gz.

File metadata

  • Download URL: calculator_mcp_rubens-0.2.16.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for calculator_mcp_rubens-0.2.16.tar.gz
Algorithm Hash digest
SHA256 ad8c28e80fe20f837e5e4d5c13a986af87d0e6a7e2d1b58d1b2b8462b252f242
MD5 f21db0bf975a24224c9f0b0d5fd97954
BLAKE2b-256 b69d219023181edf46e92d65f960d53efaa5eefe8a8f984614c1363b7bda5c99

See more details on using hashes here.

File details

Details for the file calculator_mcp_rubens-0.2.16-py3-none-any.whl.

File metadata

  • Download URL: calculator_mcp_rubens-0.2.16-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for calculator_mcp_rubens-0.2.16-py3-none-any.whl
Algorithm Hash digest
SHA256 66f2d35b1df1ec7773d925374988d2979853516ba5e641df4be6448edd20ac82
MD5 ad97f8abd213f92f8cb2df9442044c37
BLAKE2b-256 e25d41bfa1f13f2d744d41d6348f142e62084f5483183c8ba3bfd1d447b8979b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page