Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_length

Convert length measurements between units like meters, feet, miles, and nanometers. Enter a value with source and target units for accurate conversion results.

Instructions

Convert length between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesLength value to convert
from_unitYesSource unit
to_unitYesTarget unit

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The @app.tool()-decorated function that implements the 'convert_length' MCP tool, handling input parameters, calling the conversion helper, and returning the formatted result.
    @app.tool()
    def convert_length(
        value: Annotated[float, Field(description="Length value to convert")],
        from_unit: Annotated[LENGTH_UNIT, Field(description="Source unit")],
        to_unit: Annotated[LENGTH_UNIT, Field(description="Target unit")],
    ) -> dict:
        """Convert length between units."""
        converted_value = convert_length_tool(value, from_unit, to_unit)
        return {
            "original_value": value,
            "original_unit": from_unit,
            "converted_value": converted_value,
            "converted_unit": to_unit,
            "conversion_type": "length",
        }
  • Literal type definition for supported LENGTH_UNIT units used in the tool's input schema.
    LENGTH_UNIT = Literal[
        "angstrom",
        "astronomical unit",
        "cable",
        "centimeter",
        "chain (surveyors)",
        "decimeter",
        "em (pica)",
        "fathom",
        "foot",
        "foot (US survey)",
        "furlong",
        "hand",
        "hectometer",
        "inch",
        "kilometer",
        "light year",
        "meter",
        "micrometer",
        "mil",
        "mile",
        "nautical mile",
        "nautical mile (UK)",
        "millimeter",
        "nanometer",
        "parsec",
        "picometer",
        "Scandinavian mile",
        "thou",
        "yard",
    ]
  • Core helper function that performs the actual length unit conversion by converting both units to meters as intermediate.
    def convert_length_tool(
        value: float,
        from_unit: LENGTH_UNIT,
        to_unit: LENGTH_UNIT,
    ) -> float:
        """Convert length between units."""
    
        # Convert to meters first
        to_meters = {
            "angstrom": 1e-10,
            "astronomical unit": 149_598_550_000.0,
            "cable": 182.88,
            "centimeter": 0.01,
            "chain (surveyors)": 20.11684023368,
            "decimeter": 0.1,
            "em (pica)": 0.0042333,
            "fathom": 1.8288,
            "foot": 0.3048,
            "foot (US survey)": 0.304800609601,
            "furlong": 201.168,
            "hand": 0.1016,
            "hectometer": 100.0,
            "inch": 0.0254,
            "kilometer": 1000.0,
            "light year": 9_460_528_405_000_000.0,
            "meter": 1.0,
            "micrometer": 1e-06,
            "mil": 2.54e-05,
            "mile": 1609.344,
            "nautical mile": 1852.0,
            "nautical mile (UK)": 1853.184,
            "millimeter": 0.001,
            "nanometer": 1e-09,
            "parsec": 30_856_776_000_000_000.0,
            "picometer": 1e-12,
            "Scandinavian mile": 10_000.0,
            "thou": 2.54e-05,
            "yard": 0.9144,
        }
    
        meters = value * to_meters[from_unit]
        return meters / to_meters[to_unit]
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. 'Convert length between units' implies a calculation operation but reveals nothing about precision, rounding behavior, error handling for invalid inputs, performance characteristics, or what the output contains. For a tool with 3 parameters and mathematical operations, this is a significant transparency gap.

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, efficient sentence that states the core functionality without unnecessary words. It's perfectly front-loaded with the essential information. Every word earns its place, making this an excellent example of conciseness.

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 that there's an output schema (though not shown here), the description doesn't need to explain return values. However, for a conversion tool with mathematical operations and no annotations, the description should ideally mention something about precision, supported unit types, or common use cases. The current description is minimal but functional for the basic purpose.

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%, with all parameters clearly documented in the schema itself. The description doesn't add any parameter-specific information beyond what's already in the schema descriptions and enum values. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

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 'Convert length between units' clearly states the verb ('convert') and resource ('length'), making the purpose immediately understandable. It distinguishes this tool from siblings like convert_temperature or convert_mass by specifying the measurement type. However, it doesn't mention the specific units available or the conversion scope, which could make it slightly less specific than a perfect 5.

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 doesn't mention sibling tools like convert_batch for multiple conversions or list_supported_units for discovering available units. There's no context about prerequisites, error conditions, or typical use cases, leaving the agent to infer usage from the tool name alone.

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/zazencodes/unit-converter-mcp'

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