divide
Calculate division of two numbers by dividing the first number by the second number. Handles mathematical division operations with proper error checking.
Instructions
Divide first number by second number
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | Dividend (number to be divided) | |
| b | Yes | Divisor (number to divide by) |
Implementation Reference
- src/index.ts:173-195 (handler)Handler function for the 'divide' tool. Extracts arguments 'a' and 'b', checks for division by zero, computes a / b, and returns formatted result or error.case "divide": { const { a, b } = args as { a: number; b: number }; if (b === 0) { return { content: [ { type: "text", text: "Error: Division by zero is not allowed", }, ], isError: true, }; } const result = a / b; return { content: [ { type: "text", text: `${a} ÷ ${b} = ${result}`, }, ], }; }
- src/index.ts:77-90 (schema)Input schema defining parameters for the 'divide' tool: 'a' as dividend and 'b' as divisor, both required numbers.inputSchema: { type: "object", properties: { a: { type: "number", description: "Dividend (number to be divided)", }, b: { type: "number", description: "Divisor (number to divide by)", }, }, required: ["a", "b"], },
- src/index.ts:74-91 (registration)Tool registration in the list of available tools returned by ListToolsRequestHandler, including name, description, and input schema.{ name: "divide", description: "Divide first number by second number", inputSchema: { type: "object", properties: { a: { type: "number", description: "Dividend (number to be divided)", }, b: { type: "number", description: "Divisor (number to divide by)", }, }, required: ["a", "b"], }, },