convert_area
Convert area measurements between units like acres, hectares, square meters, and more using precise calculations for accurate results.
Instructions
Convert area between units.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_unit | Yes | Source unit | |
| to_unit | Yes | Target unit | |
| value | Yes | Area value to convert |
Implementation Reference
- src/unit_converter_mcp/server.py:198-212 (handler)MCP tool handler for 'convert_area' that wraps the core conversion logic 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 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 conversion function that performs the actual area unit conversion 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]
- src/unit_converter_mcp/server.py:8-38 (registration)Imports the convert_area_tool and AREA_UNIT for use in the MCP server registration.from .tools import ( ANGLE_UNIT, AREA_UNIT, COMPUTER_DATA_UNIT, DENSITY_UNIT, ENERGY_UNIT, FORCE_UNIT, LENGTH_UNIT, MASS_UNIT, POWER_UNIT, PRESSURE_UNIT, SPEED_UNIT, TEMPERATURE_UNIT, TIME_UNIT, VOLUME_UNIT, convert_angle_tool, convert_area_tool, convert_batch_tool, convert_computer_data_tool, convert_density_tool, convert_energy_tool, convert_force_tool, convert_length_tool, convert_mass_tool, convert_power_tool, convert_pressure_tool, convert_speed_tool, convert_temperature_tool, convert_time_tool, convert_volume_tool, )