calculate
Perform arithmetic operations (add, subtract, multiply, divide) using a cloud-based, authless server. Submit numerical inputs to compute results instantly without authentication.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes | ||
| operation | Yes |
Implementation Reference
- src/index.ts:30-56 (handler)Handler function for the 'calculate' tool. Performs add, subtract, multiply, or divide operations on inputs a and b based on the operation parameter, handling division by zero error.async ({ operation, a, b }) => { let result: number; switch (operation) { case "add": result = a + b; break; case "subtract": result = a - b; break; case "multiply": result = a * b; break; case "divide": if (b === 0) return { content: [ { type: "text", text: "Error: Cannot divide by zero", }, ], }; result = a / b; break; } return { content: [{ type: "text", text: String(result) }] }; }
- src/index.ts:25-29 (schema)Input schema for the 'calculate' tool, defining operation as an enum of arithmetic operations and a, b as numbers.{ operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number(), b: z.number(), },
- src/index.ts:23-57 (registration)Registration of the 'calculate' tool using this.server.tool(), including name, schema, and handler.this.server.tool( "calculate", { operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number(), b: z.number(), }, async ({ operation, a, b }) => { let result: number; switch (operation) { case "add": result = a + b; break; case "subtract": result = a - b; break; case "multiply": result = a * b; break; case "divide": if (b === 0) return { content: [ { type: "text", text: "Error: Cannot divide by zero", }, ], }; result = a / b; break; } return { content: [{ type: "text", text: String(result) }] }; } );