Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_mass

Convert weight values between units like grams, pounds, ounces, and tonnes. Enter a value, source unit, and target unit to get the converted result.

Instructions

Convert weight between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesWeight value to convert
from_unitYesSource unit
to_unitYesTarget unit

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'convert_mass'. Registers the tool via @app.tool() decorator and handles the execution by calling the underlying convert_mass_tool, formatting input/output as a dict.
    @app.tool()
    def convert_mass(
        value: Annotated[float, Field(description="Weight value to convert")],
        from_unit: Annotated[MASS_UNIT, Field(description="Source unit")],
        to_unit: Annotated[MASS_UNIT, Field(description="Target unit")],
    ) -> dict:
        """Convert weight between units."""
        converted_value = convert_mass_tool(value, from_unit, to_unit)
        return {
            "original_value": value,
            "original_unit": from_unit,
            "converted_value": converted_value,
            "converted_unit": to_unit,
            "conversion_type": "mass",
        }
  • Core helper function implementing the mass unit conversion logic by converting to kilograms as intermediate unit.
    def convert_mass_tool(
        value: float,
        from_unit: MASS_UNIT,
        to_unit: MASS_UNIT,
    ) -> float:
        """Convert mass between units."""
    
        # Convert to kilograms first
        to_kilograms = {
            "carat": 0.0002,
            "decagram": 0.01,
            "hectogram": 0.1,
            "gram": 0.001,
            "milligram": 1e-6,
            "microgram": 1e-9,
            "nanogram": 1e-12,
            "picogram": 1e-15,
            "femtogram": 1e-18,
            "grain": 6.479891e-05,
            "ounce": 0.028349523125,
            "troy ounce": 0.0311034768,
            "pound": 0.45359237,
            "stone": 6.35029318,
            "short ton (US)": 907.18474,
            "long ton (UK)": 1_016.0469088,
            "tonne": 1_000.0,
            "kilotonne": 1_000_000.0,
            "megatonne": 1_000_000_000.0,
            "kilogram": 1.0,
        }
    
        kg = value * to_kilograms[from_unit]
        return kg / to_kilograms[to_unit]
  • Type definition for supported mass units, used in tool schema validation.
    MASS_UNIT = Literal[
        "carat",
        "decagram",
        "hectogram",
        "gram",
        "milligram",
        "microgram",
        "nanogram",
        "picogram",
        "femtogram",
        "grain",
        "ounce",
        "troy ounce",
        "pound",
        "stone",
        "short ton (US)",
        "long ton (UK)",
        "tonne",
        "kilotonne",
        "megatonne",
        "kilogram",
    ]
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but only states the basic function without mentioning error handling, precision, rate limits, or output format. It doesn't add meaningful context beyond the minimal operation, leaving gaps in understanding how the tool behaves in practice.

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 extremely concise with a single, direct sentence that front-loads the core purpose without any wasted words. It efficiently communicates the essential function in a minimal format, making it easy to parse and understand 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, 100% schema coverage, and presence of an output schema, the description is adequate but minimal. It covers the basic purpose but lacks context on usage guidelines and behavioral traits, which could be helpful for an agent despite the structured data being comprehensive.

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 clear descriptions and enums for parameters, so the description doesn't need to add parameter details. The description mentions 'weight' and 'units', which aligns with the schema but doesn't provide additional semantic value beyond what's already documented in the structured fields.

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 purpose with a specific verb ('convert') and resource ('weight between units'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'convert_length' or 'convert_temperature' beyond mentioning 'weight' specifically, which is why it doesn't reach a perfect score.

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 like 'convert_batch' or 'list_supported_units'. It lacks context about prerequisites, limitations, or specific scenarios where this tool is preferred over other conversion tools, leaving the agent without usage direction.

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