Skip to main content
Glama
islobodan

Crucher MCP

convert_unit

Read-onlyIdempotent

Perform unit conversions across categories: 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, defining parameters: value (number), category (enum of 8 types), from (string), to (string).
    {
        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"],
        },
    },
  • cruncher.js:85-86 (registration)
    Registration of convert_unit in the standard tool tier, making it available by default.
        "convert_unit",
    ],
  • cruncher.js:153-155 (registration)
    convert_unit registered as a main-thread instant tool (no worker overhead) via MAIN_THREAD_TOOLS set.
        // Unit conversion
        "convert_unit",
    ]);
  • Unit conversion factor tables for 8 categories (length, weight, temperature, area, volume, time, speed, digital_storage). Each maps unit keys to their conversion factor to a base unit.
    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,
        },
    };
  • Helper function for temperature conversion (C, F, K) which uses non-linear formulas instead of simple factor multiplication.
    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}`);
        }
    };
  • Main handler function for the convert_unit tool. Looks up the category in UNIT_CONVERSIONS, normalizes units case-insensitively, handles temperature specially via convertTemperature(), and returns a JSON string with the converted result.
    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,
        });
    },
Behavior3/5

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

Annotations already indicate read-only, idempotent behavior. The description adds categories but no further behavioral traits like side effects, authentication needs, or limitations on unit strings.

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?

Two concise sentences front-loading the purpose and categories. No unnecessary words.

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?

Missing details on return value (no output schema), parameter formats, and usage constraints. A tool with 4 required parameters should have more explanatory content.

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?

Schema description coverage is 0%, yet the description only lists categories for the enum parameter. It does not explain the format or meaning of 'from' and 'to' strings or 'value' number, leaving ambiguity.

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 tool converts units and lists all supported categories. This makes it distinct from sibling math functions.

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

Usage Guidelines3/5

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

The description implies use for unit conversion but does not explicitly state when to use or provide alternatives. It offers no exclusions or context for when not to use.

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