list_supported_units
Discover available measurement units for conversion types like length, temperature, and volume to ensure compatibility before performing calculations.
Instructions
List all supported units for each conversion type or for a specific type.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| unit_type | No | Specific unit type to get supported units for. If not specified, returns all supported units. |
Implementation Reference
- src/unit_converter_mcp/server.py:338-369 (handler)The handler function for the 'list_supported_units' tool. It lists all supported units for unit conversion categories or for a specific category if provided. Uses get_args on imported unit type literals to dynamically retrieve the list of units.def list_supported_units( unit_type: Annotated[ UNIT_TYPE | None, Field( description="Specific unit type to get supported units for. If not specified, returns all supported units.", default=None, ), ], ) -> dict: """List all supported units for each conversion type or for a specific type.""" all_units = { "angle": get_args(ANGLE_UNIT), "area": get_args(AREA_UNIT), "computer_data": get_args(COMPUTER_DATA_UNIT), "density": get_args(DENSITY_UNIT), "energy": get_args(ENERGY_UNIT), "force": get_args(FORCE_UNIT), "temperature": get_args(TEMPERATURE_UNIT), "length": get_args(LENGTH_UNIT), "mass": get_args(MASS_UNIT), "power": get_args(POWER_UNIT), "pressure": get_args(PRESSURE_UNIT), "speed": get_args(SPEED_UNIT), "time": get_args(TIME_UNIT), "volume": get_args(VOLUME_UNIT), } if unit_type is not None: return {unit_type: all_units[unit_type]} return all_units
- Pydantic/Literal type definition for the 'unit_type' parameter in list_supported_units, enumerating all supported unit categories.# Unit type literal for list_supported_units function UNIT_TYPE = Literal[ "angle", "area", "computer_data", "density", "energy", "force", "length", "mass", "power", "pressure", "speed", "temperature", "time", "volume", ]
- src/unit_converter_mcp/server.py:337-337 (registration)FastMCP decorator that registers the list_supported_units function as a tool in the MCP server.@app.tool()