Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_computer_data

Convert computer storage values between units like bits, bytes, gigabytes, and terabytes. Input a value with source and target units for accurate conversion.

Instructions

Convert computer storage between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesComputer storage value to convert
from_unitYesSource unit
to_unitYesTarget unit

Implementation Reference

  • MCP tool handler for 'convert_computer_data' that wraps the core conversion logic and formats the 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", }
  • Literal type defining the supported units for computer data conversions (used in type annotations).
    COMPUTER_DATA_UNIT = Literal[ "bits", "bytes", "kilobytes", "megabytes", "gigabytes", "terabytes", "petabytes", "exabytes", ]
  • Core helper function implementing the computer data unit conversion logic by normalizing 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]
  • Imports the convert_computer_data_tool and COMPUTER_DATA_UNIT, enabling their use in the server tools.
    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, )

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