Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

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
NameRequiredDescriptionDefault
unit_typeNoSpecific unit type to get supported units for. If not specified, returns all supported units.

Implementation Reference

  • 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",
    ]
  • FastMCP decorator that registers the list_supported_units function as a tool in the MCP server.
    @app.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