get_current_time
Retrieve the current time for a specified IANA timezone using the Time MCP Server. Input a valid timezone (e.g., 'America/New_York') to return accurate local time information.
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 in TimeServer class that implements the get_current_time tool logic: retrieves the current datetime in the specified timezone and formats it into 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 response.class TimeResult(BaseModel): timezone: str datetime: str is_dst: bool
- src/mcp_server_time/server.py:127-140 (registration)Tool registration in list_tools() decorator, defining the name, description, and input JSON 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:172-178 (handler)Dispatcher logic in call_tool() that handles invocation of get_current_time by extracting timezone argument and calling the TimeServer handler.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:51-56 (helper)Helper function used by get_current_time to validate and create ZoneInfo object from timezone name.def get_zoneinfo(timezone_name: str) -> ZoneInfo: try: return ZoneInfo(timezone_name) except Exception as e: raise McpError(f"Invalid timezone: {str(e)}")