Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_volume

Convert volume measurements between units like liters, gallons, cubic meters, and fluid ounces. Input a value with source and target units for accurate conversion results.

Instructions

Convert volume between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesVolume value to convert
from_unitYesSource unit
to_unitYesTarget unit

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP handler for the 'convert_volume' tool. Validates input using VOLUME_UNIT schema, calls convert_volume_tool for conversion, and returns formatted result.
    @app.tool()
    def convert_volume(
        value: Annotated[float, Field(description="Volume value to convert")],
        from_unit: Annotated[VOLUME_UNIT, Field(description="Source unit")],
        to_unit: Annotated[VOLUME_UNIT, Field(description="Target unit")],
    ) -> dict:
        """Convert volume between units."""
        converted_value = convert_volume_tool(value, from_unit, to_unit)
        return {
            "original_value": value,
            "original_unit": from_unit,
            "converted_value": converted_value,
            "converted_unit": to_unit,
            "conversion_type": "volume",
        }
  • Pydantic Literal type defining all supported volume units for input validation in the convert_volume tool.
    VOLUME_UNIT = Literal[
        "acre foot",
        "barrel (oil)",
        "bushel (UK)",
        "bushel (US)",
        "bushel",
        "centiliter",
        "cubic centimeter",
        "cubic decimeter",
        "cubic foot",
        "cubic inch",
        "cubic kilometer",
        "cubic meter",
        "cubic mile",
        "cubic millimeter",
        "cubic yard",
        "cup",
        "deciliter",
        "fluid ounce (imperial)",
        "fluid ounce (US)",
        "fluid ounce",
        "gallon (imperial)",
        "gallon (US)",
        "gallon",
        "kiloliter",
        "liter",
        "milliliter",
        "microliter",
        "nanoliter",
        "picoliter",
        "pint (imperial)",
        "pint (US)",
        "pint",
        "quart (imperial)",
        "quart (US)",
        "quart",
        "tablespoon",
        "teaspoon",
    ]
  • Core helper function implementing volume unit conversion by normalizing all units to liters using predefined conversion factors.
    def convert_volume_tool(
        value: float,
        from_unit: VOLUME_UNIT,
        to_unit: VOLUME_UNIT,
    ) -> float:
        """Convert volume between units."""
    
        # Convert to liters first
        to_liters = {
            "acre foot": 1233481.83754752,
            "barrel (oil)": 158.987294928,
            "bushel (UK)": 36.36872,
            "bushel (US)": 35.23907016688,
            "bushel": 35.23907016688,  # Default to US bushel
            "centiliter": 0.01,
            "cubic centimeter": 0.001,
            "cubic decimeter": 1.0,
            "cubic foot": 28.316846592,
            "cubic inch": 0.016387064,
            "cubic kilometer": 1_000_000_000_000.0,
            "cubic meter": 1000.0,
            "cubic mile": 4_168_181_825_000.0,
            "cubic millimeter": 1e-06,
            "cubic yard": 764.554857984,
            "cup": 0.2365882365,
            "deciliter": 0.1,
            "fluid ounce (imperial)": 0.0284130625,
            "fluid ounce (US)": 0.029573529562,
            "fluid ounce": 0.029573529562,  # Default to US fluid ounce
            "gallon (imperial)": 4.54609,
            "gallon (US)": 3.785411784,
            "gallon": 3.785411784,  # Default to US gallon
            "kiloliter": 1000.0,
            "liter": 1.0,
            "milliliter": 0.001,
            "microliter": 1e-06,
            "nanoliter": 1e-09,
            "picoliter": 1e-12,
            "pint (imperial)": 0.56826125,
            "pint (US)": 0.473176473,
            "pint": 0.473176473,  # Default to US pint
            "quart (imperial)": 1.1365225,
            "quart (US)": 0.946352946,
            "quart": 0.946352946,  # Default to US quart
            "tablespoon": 0.014786764781,
            "teaspoon": 0.004928921594,
        }
    
        liters = value * to_liters[from_unit]
        return liters / to_liters[to_unit]
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool performs a conversion but doesn't describe what happens on success (e.g., returns a numeric result), error conditions (e.g., invalid inputs), or performance aspects (e.g., precision, speed). For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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—a single sentence with no wasted words. It's front-loaded with the core purpose and avoids unnecessary elaboration, making it easy to parse 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 simplicity (basic conversion with three parameters), 100% schema coverage, and the presence of an output schema (which handles return values), the description is minimally adequate. However, it lacks context about sibling tools and behavioral details, which could help an agent use it more effectively in a broader toolset.

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 parameter descriptions and comprehensive enum lists for units. The description adds no additional parameter semantics beyond what the schema provides. According to the rules, when schema coverage is high (>80%), the baseline score 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: converting volume between units. It specifies the verb 'convert' and the resource 'volume', making it understandable. However, it doesn't explicitly differentiate from sibling tools like convert_length or convert_mass, which follow the same pattern but for different measurement types.

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 batch conversions or list_supported_units for discovering available units. There's no context about prerequisites, such as needing valid unit names from the enum lists.

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