Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_power

Convert power measurements between units like watts, horsepower, and kilowatts for engineering, physics, and energy calculations.

Instructions

Convert power between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYesPower value to convert
from_unitYesSource unit
to_unitYesTarget unit

Implementation Reference

  • MCP tool handler for 'convert_power'. Registers the tool with FastMCP and wraps the core convert_power_tool function, formatting the response with original and converted values.
    @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 implementation of power unit conversion. Converts any power unit to watts 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]
  • Type definition (Literal) for all supported power units, used in tool signatures for input validation.
    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", ]
  • Import of convert_power_tool from tools package into server for use in MCP tool handlers.
    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,
  • Registration of convert_power_tool in the batch conversion tool's dispatcher dictionary.
    "power": convert_power_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