calculate
Evaluate mathematical expressions to perform calculations within the Algorand blockchain environment.
Instructions
Perform basic mathematical calculations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | Mathematical expression to evaluate (e.g., "2 + 2", "10 * 5") |
Implementation Reference
- src/index.ts:433-457 (handler)The handler logic for the 'calculate' tool. Parses input arguments using Zod schema, evaluates the mathematical expression with eval(), and returns the result or an error response.case 'calculate': { const parsed = CalculateArgsSchema.parse(args); try { // Simple math evaluation (in production, use a safer math library) const result = eval(parsed.expression); return { content: [ { type: 'text', text: `Result: ${parsed.expression} = ${result}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error: Invalid mathematical expression - ${error}`, }, ], isError: true, }; } }
- src/index.ts:25-27 (schema)Zod schema used for input validation in the calculate tool handler, defining the 'expression' parameter.const CalculateArgsSchema = z.object({ expression: z.string(), });
- src/index.ts:114-127 (registration)Tool registration in the TOOLS array, defining name, description, and input schema for MCP protocol compliance.{ name: 'calculate', description: 'Perform basic mathematical calculations', inputSchema: { type: 'object', properties: { expression: { type: 'string', description: 'Mathematical expression to evaluate (e.g., "2 + 2", "10 * 5")', }, }, required: ['expression'], }, },
- src/index.ts:117-127 (schema)Input schema defined in the tool registration for MCP tool listing and validation.inputSchema: { type: 'object', properties: { expression: { type: 'string', description: 'Mathematical expression to evaluate (e.g., "2 + 2", "10 * 5")', }, }, required: ['expression'], }, },