max
Computes the maximum value from a list of numbers. Returns the highest number to identify the peak in a dataset.
Instructions
Maximum of numbers.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| numbers | Yes |
Implementation Reference
- cruncher.js:1579-1587 (handler)The handler function that executes the 'max' tool logic. It iterates through the numbers array to find the maximum value, throwing an error if the array is empty.
max: ({ numbers }) => { if (numbers.length === 0) throw new Error("Cannot find the maximum of an empty list."); let maxVal = -Infinity; for (let i = 0; i < numbers.length; i++) { if (numbers[i] > maxVal) maxVal = numbers[i]; } return maxVal; }, - cruncher.js:628-645 (schema)The input schema for the 'max' tool, defining its name, description, annotations, and input validation (requires a 'numbers' array of type number).
{ name: "max", annotations: { title: "Maximum", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, description: "Maximum of numbers.", inputSchema: { type: "object", properties: { numbers: { type: "array", items: { type: "number" } }, }, required: ["numbers"], }, }, - cruncher.js:136-155 (registration)The 'max' tool is registered as a MAIN_THREAD_TOOL (line 144), meaning it runs on the main thread without worker overhead. It is also included in the 'standard' tool tier (line 82).
const MAIN_THREAD_TOOLS = new Set([ // Angle management "set_angle_mode", "get_angle_mode", // Trigonometry (instant Math calls) "sine", "cosine", "tangent", "asin", "acos", "atan", // Cache management "cache_clear", "cache_info", // Simple stats (zero-cost) "count", "min", "max", "variance", "std_dev", // Percentage "percentage_of", "percentage_change", "percentage_reverse", // Math one-liners "power", "sqrt", "logarithm", "natural_log", "absolute", // Constant lookup "get_constant", // Memory recall (single variable read) "memory_recall", // Unit conversion "convert_unit", ]); - cruncher.js:207-209 (helper)Pre-compiled regex RE_FUNC_MAX_FUNC used in evaluate_expression to convert max() calls to Math.max() in expression strings.
const RE_FUNC_MIN_FUNC = /\bmin\s*\(/g; const RE_FUNC_MAX_FUNC = /\bmax\s*\(/g; // Trigonometric functions (radians only — same as standard math)