get_timezone_info
Retrieve current time and UTC offset for any IANA timezone to coordinate schedules and manage global time differences.
Instructions
Get information about a specific timezone including current time and UTC offset.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone_name | Yes | IANA timezone name (e.g., 'America/New_York', 'Europe/London') |
Implementation Reference
- Implements the core execution logic for the 'get_timezone_info' tool: validates input, retrieves timezone object, computes current times, UTC offset, DST status, and abbreviation, then returns JSON-formatted info.async def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: """ Execute the timezone info tool. """ try: self.validate_required_args(args, ["timezone_name"]) timezone_name = args["timezone_name"] logger.info(f"Getting timezone info for: {timezone_name}") # Get timezone info timezone = utils.get_zoneinfo(timezone_name) current_time = datetime.now(timezone) utc_time = datetime.utcnow() # Calculate UTC offset offset = current_time.utcoffset() offset_hours = offset.total_seconds() / 3600 if offset else 0 timezone_info = { "timezone_name": timezone_name, "current_local_time": current_time.isoformat(timespec="seconds"), "current_utc_time": utc_time.isoformat(timespec="seconds"), "utc_offset_hours": offset_hours, "is_dst": current_time.dst() is not None and current_time.dst().total_seconds() > 0, "timezone_abbreviation": current_time.strftime("%Z"), } return [ TextContent( type="text", text=json.dumps(timezone_info, indent=2) ) ] except Exception as e: logger.exception(f"Error in get_timezone_info: {str(e)}") return [ TextContent( type="text", text=f"Error getting timezone info: {str(e)}" ) ]
- Defines the tool metadata including name 'get_timezone_info', description, and input schema requiring 'timezone_name' (IANA timezone string).def get_tool_description(self) -> Tool: """ Return the tool description for timezone information lookup. """ return Tool( name=self.name, description="""Get information about a specific timezone including current time and UTC offset.""", inputSchema={ "type": "object", "properties": { "timezone_name": { "type": "string", "description": "IANA timezone name (e.g., 'America/New_York', 'Europe/London')" } }, "required": ["timezone_name"] } )
- src/mcp_weather_server/server.py:92-92 (registration)Registers the GetTimeZoneInfoToolHandler instance with the server's tool registry during initialization.add_tool_handler(GetTimeZoneInfoToolHandler())