get_current_time
Retrieve the current time for any IANA timezone, enabling accurate time queries across global locations with automatic system timezone detection.
Instructions
Get current time in a specific timezones
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone | Yes | IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use 'Etc/UTC' as local timezone if no timezone provided by the user. |
Implementation Reference
- src/mcp_server_time/server.py:61-72 (handler)The core handler function implementing the get_current_time tool logic. It retrieves the current datetime in the specified timezone using zoneinfo.ZoneInfo, formats it, determines the day of the week and DST status, and returns a structured TimeResult object.def get_current_time(self, timezone_name: str) -> TimeResult: """Get current time in specified timezone""" timezone = get_zoneinfo(timezone_name) current_time = datetime.now(timezone) return TimeResult( timezone=timezone_name, datetime=current_time.isoformat(timespec="seconds"), day_of_week=current_time.strftime("%A"), is_dst=bool(current_time.dst()), )
- src/mcp_server_time/server.py:22-27 (schema)Pydantic BaseModel defining the output schema for the get_current_time tool response, including timezone, ISO-formatted datetime, day of week, and DST status.class TimeResult(BaseModel): timezone: str datetime: str day_of_week: str is_dst: bool
- src/mcp_server_time/server.py:132-145 (registration)Tool registration within the MCP server's list_tools() method, defining the tool name, description, and input schema requiring a 'timezone' parameter.Tool( name=TimeTools.GET_CURRENT_TIME.value, description="Get current time in a specific timezones", inputSchema={ "type": "object", "properties": { "timezone": { "type": "string", "description": f"IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use '{local_tz}' as local timezone if no timezone provided by the user.", } }, "required": ["timezone"], }, ),
- src/mcp_server_time/server.py:176-183 (registration)Dispatch logic in the MCP server's call_tool() method that handles invocation of get_current_time by extracting the timezone argument and calling the handler.match name: case TimeTools.GET_CURRENT_TIME.value: timezone = arguments.get("timezone") if not timezone: raise ValueError("Missing required argument: timezone") result = time_server.get_current_time(timezone)
- src/mcp_server_time/server.py:17-19 (helper)Enum defining tool names as constants, used for registration and dispatching the get_current_time tool.class TimeTools(str, Enum): GET_CURRENT_TIME = "get_current_time" CONVERT_TIME = "convert_time"