mcp-calculator

arulrajnet/mcp-calculator

3.2

If you are the rightful owner of mcp-calculator and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The MCP Calculator is a Model Context Protocol server example with calculator tools, built using FastMCP.

Tools
  1. add

    Performs addition of two numbers.

  2. factorial

    Calculates the factorial of a number.

  3. is_prime

    Checks if a number is prime.

MCP Calculator

A Model Context Protocol (MCP) server example with calculator tools, built using FastMCP.

Setup and Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

1. Clone the Repository

git clone https://github.com/arulrajnet/mcp-calculator.git
cd mcp-calculator

2. Create Virtual Environment (Recommended)

python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

3. Install Dependencies

# Install the package in development mode
pip install -e .

# Or install with development dependencies
pip install -e .[dev]

Running the Server

Start the MCP calculator server:

python server.py

The server will start on http://localhost:8000/mcp/calculator using the streamable HTTP transport.

You should see output similar to:

Uvicorn running on http://0.0.0.0:8000

Testing with the Client

1. Run the Test Client

In a new terminal (while the server is running):

python client.py

This will connect to the server and list all available tools.

2. Example Client Usage

You can modify client.py to test specific calculator functions:

from fastmcp import Client
import asyncio

async def main():
    # Connect via SSE
    async with Client("http://localhost:8000/mcp/calculator") as client:
        # List available tools
        tools = await client.list_tools()
        print(f"Available tools: {[tool['name'] for tool in tools]}")

        # Test some calculations
        result = await client.call_tool("add", {"a": 5, "b": 3})
        print(f"5 + 3 = {result}")

        result = await client.call_tool("factorial", {"n": 5})
        print(f"5! = {result}")

        result = await client.call_tool("is_prime", {"n": 17})
        print(f"Is 17 prime? {result}")

if __name__ == "__main__":
    asyncio.run(main())

Development

Code Formatting

black .
isort .

Type Checking

mypy .

Running Tests

pytest

Running Tests with Coverage

pytest --cov=. --cov-report=html

Author

Arulraj V
Arul