get_current_time
Retrieve the current time for a specified timezone using IANA timezone names like 'America/New_York' or 'Europe/London'.
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:59-68 (handler)The core handler function that retrieves the current time in the specified timezone using zoneinfo and formats the result as a 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"), is_dst=bool(current_time.dst()), )
- src/mcp_server_time/server.py:22-26 (schema)Pydantic model defining the output schema for the get_current_time tool.class TimeResult(BaseModel): timezone: str datetime: str is_dst: bool
- src/mcp_server_time/server.py:128-141 (registration)Registration of the get_current_time tool in the list_tools handler, including name, description, and input schema.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"], }, ), Tool(
- src/mcp_server_time/server.py:172-178 (registration)Dispatch logic in the call_tool handler that invokes the get_current_time method when the tool is called.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-20 (helper)Enum defining the tool names, including get_current_time.class TimeTools(str, Enum): GET_CURRENT_TIME = "get_current_time" CONVERT_TIME = "convert_time"