calculate
Perform basic mathematical calculations using expressions like '2 + 2' or '10 * 5' on the Algorand MCP Server, facilitating utility tasks within blockchain operations.
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 for the 'calculate' tool that parses the input arguments, evaluates the mathematical expression safely using eval, and returns the result or an error message.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 defining the input structure for the 'calculate' tool, requiring a string 'expression'.const CalculateArgsSchema = z.object({ expression: z.string(), });
- src/index.ts:114-127 (registration)Tool registration in the TOOLS array, defining the name, description, and JSON input schema for the MCP protocol.{ 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'], }, },