Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_energy

Convert energy values between units like joules, kilowatt-hours, BTUs, and calories using the Unit Converter MCP server.

Instructions

Convert energy between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesEnergy value to convert
from_unitYesSource unit
to_unitYesTarget unit

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP handler for the 'convert_energy' tool using @app.tool() decorator. Validates inputs with ENERGY_UNIT types, delegates to convert_energy_tool, and returns a structured dictionary response.
    @app.tool()
    def convert_energy(
        value: Annotated[float, Field(description="Energy value to convert")],
        from_unit: Annotated[ENERGY_UNIT, Field(description="Source unit")],
        to_unit: Annotated[ENERGY_UNIT, Field(description="Target unit")],
    ) -> dict:
        """Convert energy between units."""
        converted_value = convert_energy_tool(value, from_unit, to_unit)
        return {
            "original_value": value,
            "original_unit": from_unit,
            "converted_value": converted_value,
            "converted_unit": to_unit,
            "conversion_type": "energy",
        }
  • Pydantic/Literal type definition for all supported energy units, used for input validation in the handler.
    ENERGY_UNIT = Literal[
        "joule",
        "kilojoule",
        "megajoule",
        "gigajoule",
        "terajoule",
        "petajoule",
        "exajoule",
        "watt hour",
        "kilowatt hour",
        "megawatt hour",
        "gigawatt hour",
        "terawatt hour",
        "Btu",
        "calorie",
        "kilocalorie",
        "therm",
        "foot‑pound force",
        "inch‑pound force",
        "erg",
        "electron volt",
    ]
  • Core helper function implementing energy unit conversion by normalizing to joules using predefined conversion factors from each unit to joules.
    def convert_energy_tool(
        value: float,
        from_unit: ENERGY_UNIT,
        to_unit: ENERGY_UNIT,
    ) -> float:
        """Convert energy between units."""
    
        # Convert to joules first
        to_joules = {
            # SI and metric prefixes
            "joule": 1.0,
            "kilojoule": 1_000.0,
            "megajoule": 1_000_000.0,
            "gigajoule": 1_000_000_000.0,
            "terajoule": 1_000_000_000_000.0,
            "petajoule": 1_000_000_000_000_000.0,
            "exajoule": 1_000_000_000_000_000_000.0,
            # Electrical‑energy units
            "watt hour": 3_600.0,
            "kilowatt hour": 3_600_000.0,
            "megawatt hour": 3_600_000_000.0,
            "gigawatt hour": 3_600_000_000_000.0,
            "terawatt hour": 3_600_000_000_000_000.0,
            # Heat / nutrition
            "Btu": 1_054.35,
            "calorie": 4.184,
            "kilocalorie": 4_184.0,
            "therm": 105_505_585.257348,
            # Mechanical & particle‑physics units
            "foot‑pound force": 1.355_817_948_331,
            "inch‑pound force": 0.112_984_829_028,
            "erg": 1e-7,
            "electron volt": 1.602_176_634e-19,
        }
    
        joules = value * to_joules[from_unit]
        return joules / to_joules[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. It only states the basic function without mentioning important behavioral aspects: whether it's read-only or has side effects, precision/rounding behavior, error handling for invalid units, rate limits, or authentication requirements. For a conversion tool with no annotation coverage, this is insufficient.

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 ('Convert energy between units') - a single sentence that efficiently communicates the core purpose without any wasted words. It's appropriately sized for this straightforward conversion tool and gets directly to the point.

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

Completeness4/5

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

Given that this is a simple conversion tool with complete input schema (100% coverage, clear enums) and an output schema exists (per context signals), the description is reasonably complete. The output schema will handle return value documentation, so the description doesn't need to explain return values. However, it could better address behavioral aspects given the lack of annotations.

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 all three parameters with clear descriptions and complete enum lists. The description adds no additional parameter semantics beyond what's in the schema. According to guidelines, 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 clearly states the tool's purpose ('Convert energy between units'), specifying both the verb ('convert') and resource ('energy'). It distinguishes from siblings by focusing on energy conversion rather than other measurement types like angle, area, etc. However, it doesn't explicitly differentiate from 'convert_batch' which might handle multiple conversions.

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 when to choose this over 'convert_batch' for single vs. multiple conversions, or when to use 'list_supported_units' first. There's no context about prerequisites, limitations, or comparison with 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

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