calc
Perform basic arithmetic calculations by inputting two numbers and an operator (+, -, *, /) to get the result.
Instructions
두 숫자와 연산자를 입력하면 계산 결과를 반환합니다.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | 첫 번째 숫자 | |
| b | Yes | 두 번째 숫자 | |
| operator | Yes | 연산자 (+, -, *, /) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | 계산 결과 |
Implementation Reference
- src/index.ts:82-109 (handler)The implementation of the calc tool's execution logic.
async ({ a, b, operator }) => { let result: number if (operator === '+') result = a + b else if (operator === '-') result = a - b else if (operator === '*') result = a * b else { if (b === 0) { const errorText = '오류: 0으로 나눌 수 없습니다.' return { content: [{ type: 'text' as const, text: errorText }], structuredContent: { content: [{ type: 'text' as const, text: errorText }] } } } result = a / b } const text = `${a} ${operator} ${b} = ${result}` return { content: [{ type: 'text' as const, text }], structuredContent: { content: [{ type: 'text' as const, text }] } } } ) - src/index.ts:60-81 (registration)The registration and schema definition for the calc tool.
server.registerTool( 'calc', { description: '두 숫자와 연산자를 입력하면 계산 결과를 반환합니다.', inputSchema: z.object({ a: z.number().describe('첫 번째 숫자'), b: z.number().describe('두 번째 숫자'), operator: z .enum(['+', '-', '*', '/']) .describe('연산자 (+, -, *, /)') }), outputSchema: z.object({ content: z .array( z.object({ type: z.literal('text'), text: z.string().describe('계산 결과') }) ) .describe('계산 결과') }) },