convert_computer_data
Convert computer storage values between units like bits, bytes, kilobytes, and more using an easy-to-use tool for accurate data measurement transformations.
Instructions
Convert computer storage between units.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_unit | Yes | Source unit | |
| to_unit | Yes | Target unit | |
| value | Yes | Computer storage value to convert |
Implementation Reference
- src/unit_converter_mcp/server.py:249-263 (handler)MCP tool handler and registration for 'convert_computer_data'. Wraps the core conversion tool, handles input validation via Annotated types, performs conversion, and returns formatted response.@app.tool() def convert_computer_data( value: Annotated[float, Field(description="Computer storage value to convert")], from_unit: Annotated[COMPUTER_DATA_UNIT, Field(description="Source unit")], to_unit: Annotated[COMPUTER_DATA_UNIT, Field(description="Target unit")], ) -> dict: """Convert computer storage between units.""" converted_value = convert_computer_data_tool(value, from_unit, to_unit) return { "original_value": value, "original_unit": from_unit, "converted_value": converted_value, "converted_unit": to_unit, "conversion_type": "computer_data", }
- Core handler function implementing the computer data unit conversion logic using a pivot to megabytes.def convert_computer_data_tool( value: float, from_unit: COMPUTER_DATA_UNIT, to_unit: COMPUTER_DATA_UNIT, ) -> float: """Convert computer storage between units.""" # Convert to megabytes first to_megabytes = { "bits": 1.19209e-07, "bytes": 9.53674e-07, "kilobytes": 0.0009765625, "megabytes": 1.0, "gigabytes": 1024.0, "terabytes": 1048576.0, "petabytes": 1073741824.0, "exabytes": 1099511627776.0, } megabytes = value * to_megabytes[from_unit] return megabytes / to_megabytes[to_unit]
- Schema definition: Literal type for valid computer data units used in tool parameters.COMPUTER_DATA_UNIT = Literal[ "bits", "bytes", "kilobytes", "megabytes", "gigabytes", "terabytes", "petabytes", "exabytes", ]
- Helper: Mapping in batch conversion tool that registers convert_computer_data_tool for 'computer_data' type.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, }