calc
Perform basic arithmetic operations (addition, subtraction, multiplication, division) on two numbers using the TypeScript MCP Server Boilerplate tool.
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:95-114 (handler)Handler implementation for the 'calc' tool, performing basic arithmetic operations.
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) throw new Error('0으로 나눌 수 없습니다.') 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:73-115 (registration)Registration of the 'calc' tool in the MCP server.
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('계산 결과') }) }, 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) throw new Error('0으로 나눌 수 없습니다.') result = a / b } const text = `${a} ${operator} ${b} = ${result}` return { content: [{ type: 'text' as const, text }], structuredContent: { content: [{ type: 'text' as const, text }] } } } )