get_current_time
Retrieve the current time and date for a specified IANA timezone using the Time MCP Server. Input the timezone name to get accurate local time information for global applications.
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-69 (handler)The main handler function for the 'get_current_time' tool. It takes a timezone_name, retrieves the ZoneInfo object, gets the current datetime in that timezone, and returns a TimeResult object containing the timezone, ISO-formatted datetime string, and DST status.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 structured output for the get_current_time tool response.class TimeResult(BaseModel): timezone: str datetime: str is_dst: bool
- src/mcp_server_time/server.py:127-140 (registration)Tool registration in the MCP server's list_tools pipeline, defining the tool's name, description, and input schema which requires a 'timezone' parameter as a string.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:51-56 (helper)Utility function to create a ZoneInfo object from a timezone name string, with error handling for invalid timezones. Called by the get_current_time handler.def get_zoneinfo(timezone_name: str) -> ZoneInfo: try: return ZoneInfo(timezone_name) except Exception as e: raise McpError(f"Invalid timezone: {str(e)}")
- src/mcp_server_time/server.py:17-19 (helper)String enum defining the canonical names for time-related tools, used in registration and dispatch.class TimeTools(str, Enum): GET_CURRENT_TIME = "get_current_time" CONVERT_TIME = "convert_time"