sum
Add multiple numbers together with precision using Math-MCP's sum function. Ideal for quick and accurate numerical calculations in any workflow.
Instructions
Adds any number of numbers together
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| numbers | Yes | Array of numbers to sum |
Implementation Reference
- src/index.ts:100-108 (handler)Handler function for the "sum" tool. It takes an array of numbers, calls Arithmetic.sum to compute the sum, and returns the result as MCP text content.}, async ({ numbers }) => { const value = Arithmetic.sum(numbers) return { content: [{ type: "text", text: `${value}` }] } })
- src/index.ts:99-99 (schema)Input schema for the "sum" tool using Zod: requires an array of at least one number.numbers: z.array(z.number()).min(1).describe("Array of numbers to sum")
- src/index.ts:98-108 (registration)Registration of the "sum" tool on the MCP server, including description, schema, and handler.mathServer.tool("sum", "Adds any number of numbers together", { numbers: z.array(z.number()).min(1).describe("Array of numbers to sum") }, async ({ numbers }) => { const value = Arithmetic.sum(numbers) return { content: [{ type: "text", text: `${value}` }] } })
- src/Classes/Arithmetic.ts:51-55 (helper)Arithmetic.sum static method: computes the sum of an array of numbers using Array.reduce.static sum(numbers: number[]) { // Use reduce to accumulate the sum, starting with 0 const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0); return sum }