Appetizer: Calculator Tool Server
A simple MCP server that exposes basic calculator operations as tools. Perfect for learning how mcp-framework tools work — add, subtract, multiply, divide.
title: "Appetizer: Calculator Tool Server" description: "A simple MCP server that exposes basic calculator operations as tools. Perfect for learning how mcp-framework tools work — add, subtract, multiply, divide." order: 1 category: "appetizer" level: "beginner" duration: "10 min" date: "2026-04-01" tags:
- tools
- math
- beginner keywords:
- mcp calculator server
- mcp-framework tools
- beginner mcp server
- calculator mcp tool
What You Get
A clean, minimal MCP server with a CalculatorTool that handles basic arithmetic. This is the best starting point if you have never built an MCP server before.
Tools included:
calculate— accepts an operation (add,subtract,multiply,divide) and two numbers, returns the result
Quick Start
npx mcp-framework create calculator-server
cd calculator-server
The Code
Create src/tools/CalculatorTool.ts:
import { MCPTool } from "mcp-framework";
import { z } from "zod";
const CalculatorInput = z.object({
operation: z.enum(["add", "subtract", "multiply", "divide"]),
a: z.number().describe("First number"),
b: z.number().describe("Second number"),
});
class CalculatorTool extends MCPTool<typeof CalculatorInput> {
name = "calculate";
description = "Perform basic arithmetic operations";
schema = { input: CalculatorInput };
async execute(input: z.infer<typeof CalculatorInput>) {
const { operation, a, b } = input;
switch (operation) {
case "add":
return { result: a + b };
case "subtract":
return { result: a - b };
case "multiply":
return { result: a * b };
case "divide":
if (b === 0) throw new Error("Division by zero");
return { result: a / b };
}
}
}
export default CalculatorTool;
Build & Run
npm run build
Then add the server to your Claude Desktop config:
{
"mcpServers": {
"calculator": {
"command": "node",
"args": ["./dist/index.js"]
}
}
}
What You Learn
- How to define an MCP tool with
MCPTool - Input validation with Zod schemas
- Returning structured results from tools
- Connecting a server to Claude Desktop
Next Up
Ready for something a bit more involved? Try the Hello World Server or jump straight to the Weather API Server entree.
Built with mcp-framework (3.3M+ downloads) by @QuantGeekDev. Validated by Anthropic.