get_current_time
Retrieve the current time for any specified timezone, defaulting to system time. Supports IANA timezone names like 'America/New_York' or 'UTC' for accurate timezone management.
Instructions
Get current time (defaults to system time, supports any timezone)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone | Yes | Timezone to display. Use 'system' or 'local' for user's local time (Etc/UTC). Use IANA names like 'America/New_York', 'Europe/London', or 'UTC' for other timezones. System time is the default and most practical choice. |
Implementation Reference
- src/chronos_protocol/server.py:321-356 (handler)The core handler function in the TimeServer class that computes and returns the current time in the specified timezone as a TimeResult object. Handles system/local time and IANA timezones.def get_current_time(self, timezone_name: str) -> TimeResult: """Get current time in specified timezone (defaults to system time)""" # Get local system time first (this is the primary time) local_time = datetime.now() local_tz_name = str(get_local_tz()) # If no specific timezone requested or if requesting system timezone, use local time if timezone_name.lower() in ["system", "local", local_tz_name.lower()]: current_time = local_time display_timezone = f"System ({local_tz_name})" actual_timezone = local_tz_name else: # Use requested timezone timezone = get_zoneinfo(timezone_name) current_time = datetime.now(timezone) display_timezone = timezone_name actual_timezone = timezone_name # Create formatted timezone display formatted_timezone = current_time.strftime("%B %d, %Y at %I:%M:%S %p") if timezone_name.lower() == "utc": formatted_timezone += " UTC" elif timezone_name.lower() in ["system", "local"]: formatted_timezone += f" (System Time - {local_tz_name})" else: formatted_timezone += f" ({timezone_name})" result = TimeResult( timezone=actual_timezone, datetime=current_time.isoformat(timespec="seconds"), formatted_timezone=formatted_timezone, day_of_week=current_time.strftime("%A"), is_dst=bool(current_time.dst()), ) return result
- Pydantic model defining the structured output schema for the get_current_time tool response.class TimeResult(BaseModel): timezone: str datetime: str formatted_timezone: str day_of_week: str is_dst: bool
- src/chronos_protocol/server.py:642-654 (registration)Tool registration in the list_tools() handler, defining name, description, and input schema for MCP client discovery.name=TimeTools.GET_CURRENT_TIME.value, description="Get current time (defaults to system time, supports any timezone)", inputSchema={ "type": "object", "properties": { "timezone": { "type": "string", "description": f"Timezone to display. Use 'system' or 'local' for user's local time ({local_tz}). Use IANA names like 'America/New_York', 'Europe/London', or 'UTC' for other timezones. System time is the default and most practical choice.", } }, "required": ["timezone"], }, ),
- src/chronos_protocol/server.py:855-863 (registration)Dispatch logic in _execute_tool where the tool name is matched via pattern matching and the handler is invoked with validated arguments.case TimeTools.GET_CURRENT_TIME.value: timezone = arguments.get("timezone") if not timezone: raise ValueError("Missing required argument: timezone") # Validate timezone with helpful error messages validated_timezone = validate_timezone(timezone) result = time_server.get_current_time(validated_timezone)
- src/chronos_protocol/server.py:76-86 (helper)Enum defining the tool names as constants, used for registration and dispatch.class TimeTools(str, Enum): GET_CURRENT_TIME = "get_current_time" CONVERT_TIME = "convert_time" START_ACTIVITY_LOG = "start_activity_log" END_ACTIVITY_LOG = "end_activity_log" GET_ELAPSED_TIME = "get_elapsed_time" GET_ACTIVITY_LOGS = "get_activity_logs" UPDATE_ACTIVITY_LOG = "update_activity_log" CREATE_TIME_REMINDER = "create_time_reminder" CHECK_TIME_REMINDERS = "check_time_reminders"