Skip to main content
Glama

mode

Identifies the most frequently occurring number in a given list of numbers, enabling quick and accurate statistical analysis for data-driven tasks.

Instructions

Finds the most common number in a list of numbers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
numbersYesArray of numbers to find the mode of

Implementation Reference

  • Handler function that executes the 'mode' tool: invokes Statistics.mode on input numbers and returns MCP-formatted text response with mode values and frequency.
    }, async ({ numbers }) => {
        const value = Statistics.mode(numbers);
        return {
            content: [{
                    type: "text",
                    text: `Entries (${value.modeResult.join(', ')}) appeared ${value.maxFrequency} times`
                }]
        };
    });
  • build/index.js:148-158 (registration)
    Registration of the 'mode' MCP tool on the mathServer, including name, description, input schema, and handler function.
    mathServer.tool("mode", "Finds the most common number in a list of numbers", {
        numbers: z.array(z.number()).describe("Array of numbers to find the mode of")
    }, async ({ numbers }) => {
        const value = Statistics.mode(numbers);
        return {
            content: [{
                    type: "text",
                    text: `Entries (${value.modeResult.join(', ')}) appeared ${value.maxFrequency} times`
                }]
        };
    });
  • Zod input schema for the 'mode' tool: requires an array of numbers.
    numbers: z.array(z.number()).describe("Array of numbers to find the mode of")
  • Helper function Statistics.mode that computes the mode(s) of an array: uses Map for frequency count, identifies max frequency, collects all values with that frequency.
    static mode(numbers) {
        const modeMap = new Map();
        //Set each entry parameter into the map and assign it the number of times it appears in the list
        numbers.forEach((value) => {
            if (modeMap.has(value)) {
                modeMap.set(value, modeMap.get(value) + 1);
            }
            else {
                modeMap.set(value, 1);
            }
        });
        //Find the max frequency in the map
        let maxFrequency = 0;
        for (const numberFrequency of modeMap.values()) {
            if (numberFrequency > maxFrequency) {
                maxFrequency = numberFrequency;
            }
        }
        const modeResult = [];
        //Find the entries with the highest frequency
        for (const [key, value] of modeMap.entries()) {
            if (value === maxFrequency) {
                modeResult.push(key);
            }
        }
        return {
            modeResult: modeResult,
            maxFrequency: maxFrequency
        };
    }
Behavior3/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. It describes the core behavior (finding the mode) but doesn't disclose important traits like how it handles ties (multiple modes), empty arrays, non-numeric inputs, or the return format. The description is accurate but lacks behavioral details that would help an agent use it correctly.

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 with zero wasted words. It's front-loaded with the core purpose and appropriately sized for a simple mathematical tool, making it easy for an agent to parse quickly.

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

Completeness3/5

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

Given the tool's low complexity (single parameter, no annotations, no output schema), the description is minimally complete. It states what the tool does but lacks details on behavior (e.g., tie-breaking) and output format, which are important for correct usage. It's adequate but has clear gaps in contextual information.

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?

Schema description coverage is 100%, so the schema already fully documents the single parameter ('numbers' as an array of numbers). The description adds no additional meaning beyond what the schema provides—it doesn't explain parameter constraints, examples, or edge cases. Baseline 3 is appropriate when the schema does all the work.

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

Purpose5/5

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

The description clearly states the specific verb ('finds') and resource ('most common number in a list of numbers'), making the purpose immediately understandable. It distinguishes this tool from its siblings (like mean, median, max, min) by specifying it calculates the statistical mode rather than other mathematical operations.

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

Usage Guidelines4/5

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

The description implies usage context by stating it finds 'the most common number,' which suggests it should be used when frequency analysis is needed rather than other statistical measures. However, it doesn't explicitly state when not to use it or name specific alternatives among the sibling tools.

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