calc
Perform basic arithmetic operations (addition, subtraction, multiplication, division) on two numbers using this calculator tool.
Instructions
두 숫자와 연산자(+,-,*,/)를 입력받아 사칙연산 결과를 반환합니다.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| left | Yes | 첫 번째 숫자 | |
| operator | Yes | 연산자 (+, -, *, /) | |
| right | Yes | 두 번째 숫자 |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes | 계산 결과값 | |
| content | Yes |
Implementation Reference
- src/index.ts:60-115 (handler)The "calc" tool is registered and implemented in src/index.ts. It takes two numbers and an operator, performs the arithmetic calculation, and returns the result.
server.registerTool( 'calc', { description: '두 숫자와 연산자(+,-,*,/)를 입력받아 사칙연산 결과를 반환합니다.', inputSchema: z.object({ left: z.number().describe('첫 번째 숫자'), operator: z .enum(['+', '-', '*', '/']) .describe('연산자 (+, -, *, /)'), right: z.number().describe('두 번째 숫자') }), outputSchema: z.object({ content: z.array( z.object({ type: z.literal('text'), text: z.string().describe('계산 결과 메시지') }) ), result: z.number().describe('계산 결과값') }) }, async ({ left, operator, right }) => { if (operator === '/' && right === 0) { throw new Error('0으로 나눌 수 없습니다.') } const result = operator === '+' ? left + right : operator === '-' ? left - right : operator === '*' ? left * right : left / right const message = `${left} ${operator} ${right} = ${result}` return { content: [ { type: 'text' as const, text: message } ], structuredContent: { content: [ { type: 'text' as const, text: message } ], result } } } )