divide
Calculate the quotient of two numbers by dividing the dividend by the divisor to obtain the result.
Instructions
计算两个数字的商
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | 被除数 | |
| b | Yes | 除数 |
Implementation Reference
- src/index.ts:162-184 (handler)The switch case handler for the 'divide' tool. It extracts arguments a and b, checks if b is zero and returns an error if so, otherwise computes and returns the division result.case "divide": { const { a, b } = args as { a: number; b: number }; if (b === 0) { return { content: [ { type: "text", text: "错误:除数不能为零", }, ], isError: true, }; } const result = a / b; return { content: [ { type: "text", text: `${a} ÷ ${b} = ${result}`, }, ], }; }
- src/index.ts:72-89 (schema)The tool definition in the tools list, including name, description, and input schema for parameters a (dividend) and b (divisor).{ name: "divide", description: "计算两个数字的商", inputSchema: { type: "object", properties: { a: { type: "number", description: "被除数", }, b: { type: "number", description: "除数", }, }, required: ["a", "b"], }, },
- src/index.ts:111-115 (registration)Registers the handler for ListToolsRequestSchema, which returns the list of tools including 'divide'.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools, }; });