get_timezone_info
Retrieve current time and UTC offset for any IANA timezone to coordinate schedules and activities across different regions.
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
- The run_tool method executes the tool logic: validates input, retrieves timezone object, computes current local and UTC times, UTC offset, DST status, and timezone abbreviation, then returns formatted JSON response.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)}" ) ]
- The get_tool_description method provides the Tool schema definition, including inputSchema requiring 'timezone_name' parameter.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)The tool handler is instantiated and registered via add_tool_handler in the register_all_tools function.add_tool_handler(GetTimeZoneInfoToolHandler())