add
Calculates the sum of two numbers.
Instructions
Adds two numbers.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- cruncher.js:1324-1324 (handler)The handler function for the 'add' tool. It delegates to safeMath.add(a, b) to perform the addition.
add: ({ a, b }) => safeMath.add(a, b), - cruncher.js:1239-1248 (helper)The safeMath.add helper that performs integer-scaling arithmetic to avoid floating-point precision errors.
add: (a, b) => { const d1 = countDecimals(a); const d2 = countDecimals(b); const maxDecimals = Math.max(d1, d2); const multiplier = Math.pow(10, maxDecimals); return ( (Math.round(a * multiplier) + Math.round(b * multiplier)) / multiplier ); }, - cruncher.js:229-244 (schema)The tool definition/schema for 'add', defining its inputSchema with required 'a' and 'b' numeric parameters.
{ name: "add", annotations: { title: "Add", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, description: "Adds two numbers.", inputSchema: { type: "object", properties: { a: { type: "number" }, b: { type: "number" } }, required: ["a", "b"], }, - cruncher.js:1045-1045 (registration)The 'add' tool is registered by being included in the toolsAll array, then filtered by tier, and built into the TOOL_LOOKUP_MAP for O(1) lookup.
const TOOLS = filterToolsByTier(toolsAll, TOOL_SET);