Skip to main content
Glama

TypeScript MCP Server Boilerplate

by mazah81-gif

calculator

Perform basic arithmetic operations including addition, subtraction, multiplication, and division with two numbers.

Instructions

Perform basic arithmetic operations

Input Schema

NameRequiredDescriptionDefault
operationYesThe operation to perform
aYesFirst number
bYesSecond number

Input Schema (JSON Schema)

{ "properties": { "a": { "description": "First number", "type": "number" }, "b": { "description": "Second number", "type": "number" }, "operation": { "description": "The operation to perform", "enum": [ "add", "subtract", "multiply", "divide" ], "type": "string" } }, "required": [ "operation", "a", "b" ], "type": "object" }

Implementation Reference

  • Handler function that executes the calculator tool logic: performs add, subtract, multiply, or divide on inputs a and b, handles division by zero, returns result in MCP text content format.
    async ({ operation, a, b }: { operation: 'add' | 'subtract' | 'multiply' | 'divide'; a: number; b: number }) => { 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 { content: [ { type: 'text', text: '오류: 0으로 나눌 수 없습니다.' } ] } } result = a / b break } return { content: [ { type: 'text', text: `결과: ${result}` } ] } }
  • Zod schema defining the input parameters for the calculator tool: operation (enum), a (number), b (number).
    { operation: z.enum(['add', 'subtract', 'multiply', 'divide']).describe('The operation to perform'), a: z.number().describe('First number'), b: z.number().describe('Second number') },
  • src/index.ts:50-96 (registration)
    Registration of the calculator tool on the MCP server using server.tool(), including name, description, schema, and handler.
    // Define calculator tool server.tool( 'calculator', 'Perform basic arithmetic operations', { operation: z.enum(['add', 'subtract', 'multiply', 'divide']).describe('The operation to perform'), a: z.number().describe('First number'), b: z.number().describe('Second number') }, async ({ operation, a, b }: { operation: 'add' | 'subtract' | 'multiply' | 'divide'; a: number; b: number }) => { 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 { content: [ { type: 'text', text: '오류: 0으로 나눌 수 없습니다.' } ] } } result = a / b break } return { content: [ { type: 'text', text: `결과: ${result}` } ] } } )
  • Helper documentation of the calculator tool's capabilities in the server-info resource.
    { name: 'calculator', description: '기본 산술 연산을 수행합니다', supportedOperations: ['add', 'subtract', 'multiply', 'divide'] },

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mazah81-gif/my-mcp-server-2025'

If you have feedback or need assistance with the MCP directory API, please join our Discord server