mcp-server-calculator

A simple calculator server that provides basic math operations to a client using the Model Context Protocol (MCP).

Visit Server
Added on 3/28/2025

How to build an MCP server - Calculator Example

⚠️ work in progress ⚠️

About

Model Context Protocol (MCP) is a protocol that enables LLMs to access custom tools and services. An MCP client can make requests to MCP servers to access tools that they provide. This example represents a simple calculator server that provides basic math operations to a client.

"MCP can provide a single, standardized way for AI models to interact with external systems. You write code once and all AI systems can use it." 1

"Servers are the fundamental building block that enriches LLMs with external data and context." 2

Usage

🚧 TODO

Running & Testing the Server locally

  • MCP Inspector is a handy GUI tool that lets you test your custom MCP server via web interface at http://localhost:5173 without integrating it with LLM / AI agents.
mcp dev src/mcp_server_calculator/calculator.py

MCP config

  • Add the following to your mcp config:
{
  "mcpServers": {
    "calculator": {
      "command": "uv",
      "args": [
        "run --with mcp mcp run src/mcp_server_calculator/calculator.py"
      ]
    }
  }
}

Notes

Dev Setup

As we are using Nix in this project for having a reproducible and isolated development environment, there is no need to install Python or any other dependencies. You will get everything you need out of the box. Also there is no need to create a virtual environment in Python using venv or poetry, but you have to be willing to install Nix on your system.

  • Install direnv
  • Install Lix
  • Clone this repository
  • cd into the directory
  • Run direnv allow
  • Run pytest

That's it!

Tech Stack

  • Python3
  • Pytest
  • MCP SDK
  • MCP CLI
  • Nix

Resources

Credits

Nice things to know

Nix