Skip to main content
Glama
islobodan

Crucher MCP

convert_unit

Read-onlyIdempotent

Convert values between different units across categories such as length, weight, temperature, area, volume, time, speed, and digital storage.

Instructions

Convert between common units. Categories: length, weight, temperature, area, volume, time, speed, digital_storage.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYes
categoryYes
fromYes
toYes

Implementation Reference

  • Input schema/definition for the convert_unit tool in the toolsAll array. Defines name, description, inputSchema (value, category with enum of 8 categories, from, to), and all required fields.
        name: "convert_unit",
        annotations: {
            title: "Convert Unit",
            readOnlyHint: true,
            destructiveHint: false,
            idempotentHint: true,
            openWorldHint: false,
        },
        description:
            "Convert between common units. Categories: length, weight, temperature, area, volume, time, speed, digital_storage.",
        inputSchema: {
            type: "object",
            properties: {
                value: { type: "number" },
                category: {
                    type: "string",
                    enum: ["length", "weight", "temperature", "area", "volume", "time", "speed", "digital_storage"],
                },
                from: { type: "string" },
                to: { type: "string" },
            },
            required: ["value", "category", "from", "to"],
        },
    },
  • UNIT_CONVERSIONS lookup table mapping 8 categories (length, weight, temperature, area, volume, time, speed, digital_storage) and their unit keys to base-unit conversion factors.
    // --- Unit Conversion Tables ---
    // Each entry stores: { unit_key: factor_to_base_unit }
    // For temperature (special case), handled separately.
    const UNIT_CONVERSIONS = {
        // Length → meters
        length: {
            m: 1,
            km: 1000,
            cm: 0.01,
            mm: 0.001,
            um: 1e-6,
            nm: 1e-9,
            in: 0.0254,
            ft: 0.3048,
            yd: 0.9144,
            mi: 1609.344,
            nmi: 1852, // nautical mile
        },
        // Weight → kilograms
        weight: {
            kg: 1,
            g: 0.001,
            mg: 1e-6,
            ug: 1e-9,
            lb: 0.45359237,
            oz: 0.028349523125,
            st: 6.35029318, // stone
            t: 1000, // metric ton
        },
        // Temperature — special handling (not linear)
        temperature: {
            C: null,
            F: null,
            K: null,
        },
        // Area → square meters
        area: {
            m2: 1,
            km2: 1e6,
            cm2: 1e-4,
            ft2: 0.09290304,
            ac: 4046.8564224,
            ha: 1e4,
            in2: 0.00064516,
            yd2: 0.83612736,
            mi2: 2589988.110336,
        },
        // Volume → liters
        volume: {
            L: 1,
            mL: 0.001,
            m3: 1000,
            cm3: 0.001,
            gal: 3.785411784, // US gallon
            qt: 0.946352946, // US quart
            pt: 0.473176473, // US pint
            cup: 0.2365882365, // US cup
            floz: 0.029573529563, // US fluid ounce
            tbsp: 0.014786764782, // US tablespoon
            tsp: 0.004928921594, // US teaspoon
            imp_gal: 4.54609, // Imperial gallon
        },
        // Time → seconds
        time: {
            s: 1,
            ms: 0.001,
            us: 1e-6,
            ns: 1e-9,
            min: 60,
            hr: 3600,
            day: 86400,
            week: 604800,
            month: 2629746, // average month (30.44 days)
            year: 31556952, // Julian year
        },
        // Speed → meters per second
        speed: {
            "m/s": 1,
            "km/h": 1 / 3.6,
            mph: 0.44704,
            kn: 0.514444, // knots
            "ft/s": 0.3048,
            mach: 343, // at sea level, 20°C
            c: 299792458, // speed of light
        },
        // Digital storage → bytes
        digital_storage: {
            B: 1,
            KB: 1024,
            MB: 1048576,
            GB: 1073741824,
            TB: 1099511627776,
            PB: 1125899906842624,
            b: 0.125, // bits
            Kb: 128,
            Mb: 131072,
            Gb: 134217728,
        },
    };
  • convertTemperature helper function handling non-linear temperature conversion between Celsius, Fahrenheit, and Kelvin.
    /**
     * Convert temperature between C, F, and K.
     * @param {number} value - The source value.
     * @param {string} from - Source unit (C, F, or K).
     * @param {string} to - Target unit (C, F, or K).
     * @returns {number} The converted value.
     */
    const convertTemperature = (value, from, to) => {
        // Convert to Celsius first
        let celsius;
        switch (from) {
            case 'C': celsius = value; break;
            case 'F': celsius = (value - 32) * 5 / 9; break;
            case 'K': celsius = value - 273.15; break;
            default: throw new Error(`Unknown temperature unit: ${from}`);
        }
        // Convert from Celsius to target
        switch (to) {
            case 'C': return celsius;
            case 'F': return celsius * 9 / 5 + 32;
            case 'K': return celsius + 273.15;
            default: throw new Error(`Unknown temperature unit: ${to}`);
        }
    };
  • The tool handler function for convert_unit. Implements unit conversion logic: looks up the category in UNIT_CONVERSIONS, performs case-insensitive unit key matching, delegates temperature to convertTemperature, and computes linear conversions via base-unit scaling.
    /**
     * Converts between common units of measurement.
     * Categories: length, weight, temperature, area, volume, time, speed, digital_storage.
     * @param {Object} args - The arguments object.
     * @param {number} args.value - The numeric value to convert.
     * @param {string} args.category - Unit category.
     * @param {string} args.from - Source unit.
     * @param {string} args.to - Target unit.
     * @returns {string} JSON string with converted value, labels, and formula.
     */
    convert_unit: ({ value, category, from, to }) => {
        const conversions = UNIT_CONVERSIONS[category];
        if (!conversions) {
            throw new Error(`Unknown unit category: ${category}. Valid: ${Object.keys(UNIT_CONVERSIONS).join(', ')}`);
        }
    
        const fromLower = from.toLowerCase();
        const toLower = to.toLowerCase();
    
        // Normalize keys (match case-insensitively)
        const fromKey = Object.keys(conversions).find(k => k.toLowerCase() === fromLower);
        const toKey = Object.keys(conversions).find(k => k.toLowerCase() === toLower);
    
        if (!fromKey) {
            throw new Error(`Unknown ${category} unit: ${from}. Available: ${Object.keys(conversions).filter(k => conversions[k] !== null).join(', ')}`);
        }
        if (!toKey) {
            throw new Error(`Unknown ${category} unit: ${to}. Available: ${Object.keys(conversions).filter(k => conversions[k] !== null).join(', ')}`);
        }
    
        // Same unit, trivial
        if (fromKey === toKey) {
            return JSON.stringify({ value, from: fromKey, to: toKey, result: value });
        }
    
        let result;
    
        // Temperature needs special handling (non-linear)
        if (category === 'temperature') {
            result = convertTemperature(value, fromKey, toKey);
        } else {
            // Convert: source → base unit → target
            const sourceToBase = conversions[fromKey];
            const targetToBase = conversions[toKey];
            // Value in base unit = value * sourceToBase
            // Target value = valueInBase / targetToBase
            result = (value * sourceToBase) / targetToBase;
        }
    
        return JSON.stringify({
            value,
            from: fromKey,
            to: toKey,
            result: parseFloat(result.toPrecision(15)),
            category,
        });
    },
  • cruncher.js:77-80 (registration)
    Registration of convert_unit in the 'standard' tool tier, making it available by default.
        "percentage_of", "percentage_change", "percentage_reverse",
        "median", "range",
        "convert_unit",
    ],
Behavior2/5

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

The description adds no behavioral information beyond what annotations already convey (readOnlyHint, destructiveHint, idempotentHint). It does not explain conversion behavior, such as unit formats or potential edge cases.

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

Conciseness4/5

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

The description is a single sentence that efficiently conveys the core purpose and lists categories. It is front-loaded and contains no unnecessary words, but it omits crucial parameter details.

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 no output schema and four required parameters with no descriptions, the description is incomplete. It does not clarify the output format nor the acceptable unit strings, leaving significant gaps for an agent.

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

Parameters2/5

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

With 0% schema description coverage, the description only enumerates categories but fails to explain the meaning or expected format of the 'from' and 'to' parameters. This leaves ambiguity about unit names or abbreviations.

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 'Convert between common units' with a specific verb and resource, and lists eight categories, effectively distinguishing the tool from sibling math and expression tools. It explicitly defines the scope of conversion types supported.

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, nor does it set expectations for prerequisites or exclusions. It merely states the function without contextual usage advice.

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

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/islobodan/cruncher-mcp'

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