convert_time
Convert time values between units like seconds, minutes, hours, days, and years using the Unit Converter MCP server. Enter a value with source and target units for precise conversion.
Instructions
Convert time between units.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| value | Yes | Time value to convert | |
| from_unit | Yes | Source unit | |
| to_unit | Yes | Target unit |
Implementation Reference
- src/unit_converter_mcp/server.py:283-298 (handler)MCP tool handler named 'convert_time' that executes the tool logic by calling the core convert_time_tool and formatting 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", }
- Core helper function implementing the time 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]
- Pydantic/Literal type schema defining valid time units for input validation in the 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", ]