calculator-mcp-server
by Amankhan1009
Calculator MCP Server
A Model Context Protocol server exposing calculator operations, built as a learning project.
Tools
add(a, b)
subtract(a, b)
multiply(a, b)
divide(a, b)
power(base, exponent)
square_root(number)
modulus(a, b)
Run
uv run mcp dev src/calculator_mcp/server.pyTest
uv run pytest tests/ -vArchitecture
operations.py— pure calculator logic, no MCP dependencyserver.py— FastMCP tool registration, thin wrappers over operations.pyexceptions.py— custom exception hierarchy (CalculatorError base)tests/— pytest unit tests, independent of the MCP layer
Connect to Claude Desktop
Add this to claude_desktop_config.json:
{
"mcpServers": {
"calculator": {
"command": "uv",
"args": ["run", "--directory", "/path/to/calculator-mcp-server", "mcp", "run", "src/calculator_mcp/server.py"]
}
}
}This structure generalizes to any MCP server: keep domain logic separate from protocol code, use typed exceptions per failure mode, annotate tools honestly (readOnly/idempotent/destructive/openWorld), and test the logic layer without needing a live server.