Skip to main content
Glama
jaejin0me

TypeScript MCP Server Boilerplate

by jaejin0me

calculator

Perform basic mathematical calculations including addition, subtraction, multiplication, and division using two numbers. This tool handles arithmetic operations for mathematical problem-solving.

Instructions

Perform basic mathematical calculations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aYesThe first number
bYesThe second number
operationYesThe mathematical operation to perform

Implementation Reference

  • The main handler function for the 'calculator' tool. It takes operation ('add', 'subtract', 'multiply', 'divide'), numbers a and b, performs the calculation, handles divide-by-zero and invalid operation errors, and returns the result as text.
    }, async (args) => { const { operation, a, b } = args let result: number let operationSymbol: string switch (operation) { case 'add': result = a + b operationSymbol = '+' break case 'subtract': result = a - b operationSymbol = '-' break case 'multiply': result = a * b operationSymbol = '×' break case 'divide': if (b === 0) { return { content: [{ type: 'text', text: '오류: 0으로 나눌 수 없습니다. (Error: Cannot divide by zero)' }] } } result = a / b operationSymbol = '÷' break default: return { content: [{ type: 'text', text: '오류: 지원되지 않는 연산입니다. (Error: Unsupported operation)' }] } } const calculation = `${a} ${operationSymbol} ${b} = ${result}` return { content: [{ type: 'text', text: calculation }] } })
  • Zod input schema for the calculator tool defining the parameters: operation (enum of math operations), a and b (numbers).
    operation: z.enum(['add', 'subtract', 'multiply', 'divide']).describe('The mathematical operation to perform'), a: z.number().describe('The first number'), b: z.number().describe('The second number')
  • src/index.ts:37-38 (registration)
    Registration of the 'calculator' tool using server.tool(), including name, description, and linking to schema and handler.
    // Add calculator tool server.tool('calculator', 'Perform basic mathematical calculations', {
  • src/index.ts:249-249 (registration)
    The 'calculator' tool is listed in the server capabilities within the server-info resource.
    tools: ['greeting', 'calculator', 'time'],

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/jaejin0me/mcpServer_test'

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