Skip to main content
Glama

median

Calculate the median of a list of numbers for accurate statistical analysis. Input an array of numerical values to derive the central value in the dataset.

Instructions

Calculates the median of a list of numbers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
numbersYesArray of numbers to find the median of

Implementation Reference

  • Handler function that executes the median tool logic by calling Statistics.median(numbers) and returning the result as text content.
    }, async ({ numbers }) => { const value = Statistics.median(numbers) return { content: [{ type: "text", text: `${value}` }] } })
  • Input schema using Zod: requires an array of at least one number.
    numbers: z.array(z.number()).min(1).describe("Array of numbers to find the median of")
  • src/index.ts:148-148 (registration)
    Registration of the 'median' tool on the mathServer with description, schema, and handler.
    mathServer.tool("median", "Calculates the median of a list of numbers", {
  • Core implementation of median calculation: sorts the array, handles odd/even length to find middle value(s).
    static median(numbers: number[]) { //Sort numbers numbers.sort() //Find the median index const medianIndex = numbers.length / 2 let medianValue: number; if (numbers.length % 2 !== 0) { //If number is odd medianValue = numbers[Math.floor(medianIndex)] } else { //If number is even medianValue = (numbers[medianIndex] + numbers[medianIndex - 1]) / 2 } return medianValue }

Other Tools

Related Tools

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/EthanHenrickson/math-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server