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
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | The first number | |
| b | Yes | The second number | |
| operation | Yes | The mathematical operation to perform |
Implementation Reference
- src/index.ts:42-87 (handler)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 }] } })
- src/index.ts:39-41 (schema)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'],