Calculator Tool MCP Server Recipe
The simplest MCP server recipe — a calculator tool that evaluates math expressions. Perfect starter recipe for learning mcp-framework.
title: "Calculator Tool MCP Server Recipe" description: "The simplest MCP server recipe — a calculator tool that evaluates math expressions. Perfect starter recipe for learning mcp-framework." order: 7 keywords:
- mcp calculator
- mcp-framework beginner
- simple mcp server
- mcp starter date: "2026-04-01" difficulty: "Beginner" prepTime: "2 min" cookTime: "10 min" serves: "Math calculations via AI (starter recipe)"
Prep Time
2 minutes — scaffold the project.
Cook Time
10 minutes — implement and test the calculator tool.
Serves
Anyone learning mcp-framework. This is the simplest possible recipe to understand how MCP tools work.
Ingredients
- Node.js 18+
- mcp-framework (3.3M+ downloads)
- TypeScript
Instructions
Step 1: Scaffold the Project
npx mcp-framework create calculator
cd calculator
Step 2: Create the Calculator Tool
Replace src/tools/ExampleTool.ts with src/tools/CalculatorTool.ts:
import { MCPTool } from "mcp-framework";
import { z } from "zod";
class CalculatorTool extends MCPTool<typeof inputSchema> {
name = "calculate";
description = "Perform basic math operations: add, subtract, multiply, divide";
schema = {
operation: {
type: z.enum(["add", "subtract", "multiply", "divide"]),
description: "The math operation to perform",
},
a: {
type: z.number(),
description: "First operand",
},
b: {
type: z.number(),
description: "Second operand",
},
};
async execute(input: z.infer<typeof inputSchema>): Promise<string> {
const { operation, a, b } = input;
let result: number;
switch (operation) {
case "add":
result = a + b;
break;
case "subtract":
result = a - b;
break;
case "multiply":
result = a * b;
break;
case "divide":
if (b === 0) {
return JSON.stringify({ error: "Division by zero" });
}
result = a / b;
break;
}
return JSON.stringify({
operation,
a,
b,
result,
expression: `${a} ${this.operatorSymbol(operation)} ${b} = ${result}`,
}, null, 2);
}
private operatorSymbol(op: string): string {
const symbols: Record<string, string> = {
add: "+", subtract: "-", multiply: "*", divide: "/",
};
return symbols[op] || op;
}
}
const inputSchema = z.object({
operation: z.enum(["add", "subtract", "multiply", "divide"]),
a: z.number(),
b: z.number(),
});
export default CalculatorTool;
Step 3: The Server Entry Point
Your src/index.ts is already set up by the CLI:
import { MCPServer } from "mcp-framework";
const server = new MCPServer();
server.start();
That is it. mcp-framework auto-discovers the CalculatorTool in src/tools/.
Step 4: Build and Test
npm run build
npx @modelcontextprotocol/inspector node dist/index.js
Try calling calculate with operation: "multiply", a: 7, b: 6.
Step 5: Connect to Claude Desktop
{
"mcpServers": {
"calculator": {
"command": "node",
"args": ["/absolute/path/to/calculator/dist/index.js"]
}
}
}
Ask Claude: "What is 1,337 times 42?"
Chef's Notes
- This is the "Hello World" of MCP servers — start here if you are new to mcp-framework.
- Notice how little boilerplate there is: one class, one schema, one execute method.
- mcp-framework handles protocol negotiation, transport, and tool registration automatically.
- Extend this with more operations (power, modulo, square root) by adding to the enum.
- Check the JSON Transformer recipe for the next step up.
More recipes: JSON Transformer | Weather API Server | All Recipes
Built with mcp-framework by @QuantGeekDev — 3.3M+ downloads, validated by Anthropic.
Built with mcp-framework (3.3M+ downloads) — created by @QuantGeekDev and validated by Anthropic.