convert_angle
Convert angles between degrees, radians, arcmin, arcsec, turns, and gons to ensure accurate measurements for technical or scientific applications.
Instructions
Convert angle between units.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_unit | Yes | Source unit | |
| to_unit | Yes | Target unit | |
| value | Yes | Angle value to convert |
Implementation Reference
- src/unit_converter_mcp/server.py:79-96 (handler)The primary MCP tool handler for 'convert_angle'. This is the function executed when the tool is called, handling input validation via type annotations and returning a formatted response dictionary.@app.tool() def convert_angle( value: Annotated[float, Field(description="Angle value to convert")], from_unit: Annotated[ANGLE_UNIT, Field(description="Source unit")], to_unit: Annotated[ANGLE_UNIT, Field(description="Target unit")], ) -> dict: """Convert angle between units.""" converted_value = convert_angle_tool(value, from_unit, to_unit) return { "original_value": value, "original_unit": from_unit, "converted_value": converted_value, "converted_unit": to_unit, "conversion_type": "angle", } @app.tool()
- Core helper function containing the exact conversion logic for angle units, converting via an intermediate degrees value using lookup dictionaries for to/from degrees conversions.def convert_angle_tool( value: float, from_unit: ANGLE_UNIT, to_unit: ANGLE_UNIT, ) -> float: """Convert angle between units.""" # Dictionary mapping units to their conversion functions to degrees to_degrees: dict[ANGLE_UNIT, Callable[[float], float]] = { "radians": _radians_to_degrees, "arcmin": _arcmin_to_degrees, "arcsec": _arcsec_to_degrees, "turns": _turns_to_degrees, "gons": _gons_to_degrees, "degrees": lambda x: x, } # Dictionary mapping units to their conversion functions from degrees from_degrees: dict[ANGLE_UNIT, Callable[[float], float]] = { "radians": _degrees_to_radians, "arcmin": _degrees_to_arcmin, "arcsec": _degrees_to_arcsec, "turns": _degrees_to_turns, "gons": _degrees_to_gons, "degrees": lambda x: x, } # Convert to degrees first degrees = to_degrees[from_unit](value) # Convert from degrees to target unit return from_degrees[to_unit](degrees)
- Type schema defining valid angle units as a Literal union type, used for input validation in the tool signatures.ANGLE_UNIT = Literal["degrees", "radians", "arcmin", "arcsec", "turns", "gons"]
- Helper mapping that registers convert_angle_tool for batch conversions under the 'angle' key.CONVERSION_FUNCTIONS: dict[str, Callable[..., float]] = { "angle": convert_angle_tool, "area": convert_area_tool, "computer_data": convert_computer_data_tool, "density": convert_density_tool, "energy": convert_energy_tool, "force": convert_force_tool, "length": convert_length_tool, "mass": convert_mass_tool, "power": convert_power_tool, "pressure": convert_pressure_tool, "speed": convert_speed_tool, "temperature": convert_temperature_tool, "time": convert_time_tool, "volume": convert_volume_tool, }