Skip to main content
Glama

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
NameRequiredDescriptionDefault
expYes

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)); },
  • 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)); }, });
  • 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); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pwh-pwh/cal-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server