Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_power

Convert power values between units like horsepower, watt, and kilowatt for accurate measurements. Simplify calculations with precise unit conversions for diverse power measurement needs.

Instructions

Convert power between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_unitYesSource unit
to_unitYesTarget unit
valueYesPower value to convert

Implementation Reference

  • MCP tool handler for 'convert_power'. Registers the tool via @app.tool() and handles the conversion by calling the core logic function, formatting input/output.
    @app.tool() def convert_power( value: Annotated[float, Field(description="Power value to convert")], from_unit: Annotated[POWER_UNIT, Field(description="Source unit")], to_unit: Annotated[POWER_UNIT, Field(description="Target unit")], ) -> dict: """Convert power between units.""" converted_value = convert_power_tool(value, from_unit, to_unit) return { "original_value": value, "original_unit": from_unit, "converted_value": converted_value, "converted_unit": to_unit, "conversion_type": "power", }
  • Core conversion logic for power units. Converts any power unit to watts as base, then to target unit using predefined conversion factors.
    def convert_power_tool( value: float, from_unit: POWER_UNIT, to_unit: POWER_UNIT, ) -> float: """Convert power between units.""" # Convert to watts first to_watts = { # Anglo‑American & HVAC "Btu per hour": 0.2930711, "foot pound‑force per second": 1.35582, "ton of refrigeration": 3_516.853, # Nutrition / chemistry "calorie per hour": 0.001162222222, "kilocalorie per hour": 1.162222222222, # Mechanical power "horsepower": 745.69987158227, # international / mechanical "horsepower (metric)": 735.4988, "kilogram‑force meter per second": 9.80665, # SI and metric multiples "watt": 1.0, "kilowatt": 1_000.0, "megawatt": 1_000_000.0, "gigawatt": 1_000_000_000.0, "terawatt": 1_000_000_000_000.0, "petawatt": 1_000_000_000_000_000.0, } watts = value * to_watts[from_unit] return watts / to_watts[to_unit]
  • Pydantic/Literal type defining all supported power units for input validation in the tool.
    POWER_UNIT = Literal[ "Btu per hour", "foot pound‑force per second", "ton of refrigeration", "calorie per hour", "kilocalorie per hour", "horsepower", "horsepower (metric)", "kilogram‑force meter per second", "watt", "kilowatt", "megawatt", "gigawatt", "terawatt", "petawatt", ]

Other Tools

Related Tools

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