divide
Calculate the division of two numbers with a dividend and divisor. Input two numerical values to get the quotient using this calculation tool from the Demo MCP Server.
Instructions
Divide two numbers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | Dividend | |
| b | Yes | Divisor |
Implementation Reference
- src/tools/calculator-tools.ts:89-110 (handler)Handler function that performs division of two numbers, handling division by zero error by returning an error response.async ({ a, b }) => { if (b === 0) { return { content: [ { type: "text", text: "Error: Division by zero is not allowed" } ], isError: true }; } return { content: [ { type: "text", text: `${a} ÷ ${b} = ${a / b}` } ] }; }
- src/tools/calculator-tools.ts:84-87 (schema)Input schema using Zod for the divide tool, defining 'a' as dividend and 'b' as divisor, both numbers.inputSchema: { a: z.number().describe("Dividend"), b: z.number().describe("Divisor") }
- src/tools/calculator-tools.ts:79-111 (registration)Registration of the 'divide' tool on the MCP server, including title, description, input schema, and handler function.server.registerTool( "divide", { title: "Division Tool", description: "Divide two numbers", inputSchema: { a: z.number().describe("Dividend"), b: z.number().describe("Divisor") } }, async ({ a, b }) => { if (b === 0) { return { content: [ { type: "text", text: "Error: Division by zero is not allowed" } ], isError: true }; } return { content: [ { type: "text", text: `${a} ÷ ${b} = ${a / b}` } ] }; } );