Skip to main content
Glama

cal

Evaluate mathematical expressions with support for basic operations and constants like PI and E using the expr-eval library.

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 handler for the 'cal' tool, which evaluates the mathematical expression by calling the calculate helper function.
    execute: async (args) => { return String(calculate(args.exp)); },
  • Input schema for the 'cal' tool, defining the 'exp' parameter as a string.
    parameters: z.object({ exp: z.string(), }),
  • index.ts:10-24 (registration)
    Registration of the 'cal' tool with FastMCP server, 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); }

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