Skip to main content
Glama
isdaniel

Weather MCP Server

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
NameRequiredDescriptionDefault
timezone_nameYesIANA 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"]
            }
        )
  • The tool handler is instantiated and registered via add_tool_handler in the register_all_tools function.
    add_tool_handler(GetTimeZoneInfoToolHandler())

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/isdaniel/mcp_weather_server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server