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
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the basic function without mentioning error handling (e.g., for empty arrays, though schema requires minItems:1), performance considerations, or output format. This is inadequate for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's purpose without any unnecessary words. It is front-loaded and efficiently conveys the essential information, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (simple mathematical operation) but lack of annotations and output schema, the description is insufficient. It does not explain the return value (e.g., a single number), handle edge cases, or provide usage context, leaving gaps in completeness for effective agent invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the parameter 'numbers' fully documented in the schema. The description adds no additional semantic context beyond what the schema provides (e.g., no examples or edge cases), so it meets the baseline score of 3 for high schema coverage without extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's function ('Calculates the median') and the resource it operates on ('a list of numbers'), which is specific and unambiguous. However, it does not explicitly differentiate from sibling tools like 'mean' or 'mode', which also operate on lists of numbers, leaving some potential for confusion in sibling selection.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention sibling tools like 'mean' or 'mode' for different statistical measures, nor does it specify scenarios where median is preferred (e.g., for skewed data or outliers), leaving the agent without usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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