mean
Calculate the arithmetic mean of a list of numbers to determine their average value. This tool helps simplify statistical analysis by providing accurate results for numerical data sets.
Instructions
Calculates the arithmetic mean of a list of numbers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| numbers | Yes | Array of numbers to find the mean of |
Implementation Reference
- src/index.ts:133-142 (handler)The handler function for the 'mean' MCP tool. It calls Statistics.mean on the input numbers and returns the result as a text content response.}, async ({ numbers }) => { const value = Statistics.mean(numbers) return { content: [{ type: "text", text: `${value}` }] } })
- src/index.ts:132-132 (schema)Input schema for the 'mean' tool using Zod, requiring a non-empty array of numbers.numbers: z.array(z.number()).min(1).describe("Array of numbers to find the mean of")
- src/index.ts:131-131 (registration)Registration of the 'mean' tool on the MCP mathServer, specifying name, description, and schema.mathServer.tool("mean", "Calculates the arithmetic mean of a list of numbers", {
- src/Classes/Statistics.ts:8-14 (helper)The Statistics.mean static method that implements the arithmetic mean calculation logic used by the tool handler.static mean(numbers: number[]) { // Calculate sum and divide by the count of numbers const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0); const mean = sum / numbers.length; return mean }