Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_area

Convert area measurements between units like acres, hectares, square meters, and square feet. Input a value with source and target units for accurate conversion.

Instructions

Convert area between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesArea value to convert
from_unitYesSource unit
to_unitYesTarget unit

Implementation Reference

  • MCP tool handler function 'convert_area' that performs the area unit conversion by calling the core convert_area_tool and formats the response.
    @app.tool()
    def convert_area(
        value: Annotated[float, Field(description="Area value to convert")],
        from_unit: Annotated[AREA_UNIT, Field(description="Source unit")],
        to_unit: Annotated[AREA_UNIT, Field(description="Target unit")],
    ) -> dict:
        """Convert area between units."""
        converted_value = convert_area_tool(value, from_unit, to_unit)
        return {
            "original_value": value,
            "original_unit": from_unit,
            "converted_value": converted_value,
            "converted_unit": to_unit,
            "conversion_type": "area",
        }
  • Type definition (Literal) for supported area units used in input validation.
    AREA_UNIT = Literal[
        "acre",
        "are",
        "hectare",
        "square centimeter",
        "square foot",
        "square inch",
        "square kilometer",
        "square meter",
        "square mile",
        "square millimeter",
        "square yard",
    ]
  • Core helper function implementing the area conversion logic by normalizing to square meters.
    def convert_area_tool(
        value: float,
        from_unit: AREA_UNIT,
        to_unit: AREA_UNIT,
    ) -> float:
        """Convert area between units."""
    
        # Convert to square meters first
        to_square_meters = {
            "acre": 4046.8564224,
            "are": 100.0,
            "hectare": 10_000.0,
            "square centimeter": 0.0001,
            "square foot": 0.09290304,
            "square inch": 0.00064516,
            "square kilometer": 1_000_000.0,
            "square meter": 1.0,
            "square mile": 2_589_988.110336,
            "square millimeter": 1e-6,
            "square yard": 0.83612736,
        }
    
        square_meters = value * to_square_meters[from_unit]
        return square_meters / to_square_meters[to_unit]

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