Skip to main content
Glama
zazencodes

Unit Converter MCP

by zazencodes

convert_time

Convert time values between units such as picoseconds, milliseconds, minutes, hours, days, weeks, months, years, and more for precise time measurements.

Instructions

Convert time between units.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_unitYesSource unit
to_unitYesTarget unit
valueYesTime value to convert

Implementation Reference

  • MCP handler for the 'convert_time' tool, registered with @app.tool(). Calls the core convert_time_tool and formats the response.
    @app.tool() def convert_time( value: Annotated[float, Field(description="Time value to convert")], from_unit: Annotated[TIME_UNIT, Field(description="Source unit")], to_unit: Annotated[TIME_UNIT, Field(description="Target unit")], ) -> dict: """Convert time between units.""" converted_value = convert_time_tool(value, from_unit, to_unit) return { "original_value": value, "original_unit": from_unit, "converted_value": converted_value, "converted_unit": to_unit, "conversion_type": "time", }
  • Literal type defining all supported TIME_UNIT values for input validation in convert_time tool.
    TIME_UNIT = Literal[ "picoseconds", "femtoseconds", "nanoseconds", "microseconds", "milliseconds", "seconds", "minutes", "hours", "days", "weeks", "fortnights", "months", "quarters", "synodic months", "years", "decades", "centuries", "millennia", ]
  • Core helper function implementing the time unit conversion logic by normalizing to seconds.
    def convert_time_tool( value: float, from_unit: TIME_UNIT, to_unit: TIME_UNIT, ) -> float: """Convert time between units.""" # Convert to seconds first to_seconds = { # sub‑second "picoseconds": 1e-12, "femtoseconds": 1e-15, "nanoseconds": 1e-09, "microseconds": 1e-06, "milliseconds": 0.001, # second and above "seconds": 1.0, "minutes": 60.0, "hours": 3_600.0, "days": 86_400.0, "weeks": 604_800.0, "fortnights": 1_209_600.0, # calendar averages "months": 2_628_000.0, # 1/12 of avg Gregorian year "quarters": 7_884_000.0, # 3 × avg month # optional lunar unit (keep or drop as you wish) "synodic months": 2_551_442.8896, # mean lunation # years & multiples — now ONE canonical value "years": 31_556_952.0, # average Gregorian (365.2425 d) "decades": 315_569_520.0, # 10 × year "centuries": 3_155_695_200.0, # 100 × year "millennia": 31_556_952_000.0, # 1 000 × year } seconds = value * to_seconds[from_unit] return seconds / to_seconds[to_unit]

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