sqrt
Calculate the square root of any positive number using this mathematical tool. Enter a number to get its square root value with proper error handling for invalid inputs.
Instructions
Calculate square root of a number
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| number | Yes | Number to calculate square root of |
Implementation Reference
- src/index.ts:210-232 (handler)The handler for the 'sqrt' tool. Extracts the 'number' argument, checks if it's negative (returns error if so), computes Math.sqrt(number), and returns a text response with the result.case "sqrt": { const { number } = args as { number: number }; if (number < 0) { return { content: [ { type: "text", text: "Error: Cannot calculate square root of negative number", }, ], isError: true, }; } const result = Math.sqrt(number); return { content: [ { type: "text", text: `√${number} = ${result}`, }, ], }; }
- src/index.ts:110-123 (registration)Registration of the 'sqrt' tool in the listTools response, including name, description, and input schema.{ name: "sqrt", description: "Calculate square root of a number", inputSchema: { type: "object", properties: { number: { type: "number", description: "Number to calculate square root of", }, }, required: ["number"], }, },
- src/index.ts:113-122 (schema)Input schema definition for the 'sqrt' tool, specifying a required 'number' property of type number.inputSchema: { type: "object", properties: { number: { type: "number", description: "Number to calculate square root of", }, }, required: ["number"], },