Skip to main content
Glama

Unit Converter MCP

by zazencodes
MIT License
5
  • Apple
energy.py1.63 kB
"""Energy conversion functions.""" from typing import Literal ENERGY_UNIT = Literal[ "joule", "kilojoule", "megajoule", "gigajoule", "terajoule", "petajoule", "exajoule", "watt hour", "kilowatt hour", "megawatt hour", "gigawatt hour", "terawatt hour", "Btu", "calorie", "kilocalorie", "therm", "foot‑pound force", "inch‑pound force", "erg", "electron volt", ] def convert_energy_tool( value: float, from_unit: ENERGY_UNIT, to_unit: ENERGY_UNIT, ) -> float: """Convert energy between units.""" # Convert to joules first to_joules = { # SI and metric prefixes "joule": 1.0, "kilojoule": 1_000.0, "megajoule": 1_000_000.0, "gigajoule": 1_000_000_000.0, "terajoule": 1_000_000_000_000.0, "petajoule": 1_000_000_000_000_000.0, "exajoule": 1_000_000_000_000_000_000.0, # Electrical‑energy units "watt hour": 3_600.0, "kilowatt hour": 3_600_000.0, "megawatt hour": 3_600_000_000.0, "gigawatt hour": 3_600_000_000_000.0, "terawatt hour": 3_600_000_000_000_000.0, # Heat / nutrition "Btu": 1_054.35, "calorie": 4.184, "kilocalorie": 4_184.0, "therm": 105_505_585.257348, # Mechanical & particle‑physics units "foot‑pound force": 1.355_817_948_331, "inch‑pound force": 0.112_984_829_028, "erg": 1e-7, "electron volt": 1.602_176_634e-19, } joules = value * to_joules[from_unit] return joules / to_joules[to_unit]

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