simple-calculator-mcp-server

simple-calculator-mcp-server

3.5

This document provides a tutorial on building a simple MCP calculator server and connecting it to Claude for Desktop.

The Model Context Protocol (MCP) allows developers to extend AI assistants with custom tools and servers, providing them with additional functionalities. This tutorial guides you through building a simple MCP calculator server that exposes four tools: add, subtract, multiply, and divide. The server is then connected to an MCP host, specifically Claude for Desktop, to demonstrate its capabilities. MCP servers can provide resources, tools, and prompts, but this tutorial focuses on tools. The server is built using Python and requires the Python MCP SDK 1.2.0 or higher. The tutorial includes steps for setting up the environment, implementing tool execution, and running the server. It also provides instructions for configuring Claude for Desktop to use the MCP server.

Features

  • Customizable MCP server for AI assistants
  • Supports basic arithmetic operations: add, subtract, multiply, divide
  • Integration with Claude for Desktop
  • Python-based implementation
  • Utilizes FastMCP for server setup

MCP Tools

  • {'add': 'Adds two numbers.'}
  • {'subtract': 'Subtracts the second number from the first.'}
  • {'multiply': 'Multiplies two numbers.'}
  • {'divide': 'Divides the first number by the second, with error handling for division by zero.'}

Usage with Different Platforms

MacOS/Linux

bash
curl -LsSf https://astral.sh/uv/install.sh | sh
uv init calculator
cd calculator
uv venv
source .venv/bin/activate
uv add "mcp[cli]"
touch calculator.py

Windows

powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
uv init calculator
cd calculator
uv venv
.venv\Scripts\activate
uv add "mcp[cli]"
new-item calculator.py