cal
Evaluate mathematical expressions using the expr-eval library, supporting basic operations and constants like PI and E. Input a valid expression to receive computed results quickly.
Instructions
Use the expr-eval library to evaluate the input mathematical expression and return the result.
Constant Description E The value of Math.E from your JavaScript runtime PI The value of Math.PI from your JavaScript runtime true Logical true value false Logical false value
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exp | Yes |
Implementation Reference
- index.ts:21-23 (handler)The execute function for the 'cal' tool, which calls the calculate helper with the input expression and returns the string result.execute: async (args) => { return String(calculate(args.exp)); },
- index.ts:18-20 (schema)Zod schema defining the input parameter 'exp' as a string for the 'cal' tool.parameters: z.object({ exp: z.string(), }),
- index.ts:10-24 (registration)Registration of the 'cal' tool using server.addTool, including name, description, schema, and handler.server.addTool({ name: "cal", description: "Use the expr-eval library to evaluate the input mathematical expression and return the result." + "\n\nConstant \tDescription\n" + "E \tThe value of Math.E from your JavaScript runtime\n" + "PI \tThe value of Math.PI from your JavaScript runtime\n" + "true \tLogical true value\n" + "false \tLogical false value", parameters: z.object({ exp: z.string(), }), execute: async (args) => { return String(calculate(args.exp)); }, });
- index.ts:66-69 (helper)Helper function that parses and evaluates the mathematical expression using expr-eval's Parser.function calculate(expression: string): number { const parser = new Parser(); return parser.evaluate(expression); }