get_ip_timezone
Retrieve the IANA timezone string for any IP address to determine geographic location timezone information for network analysis or geolocation purposes.
Instructions
Get just the timezone for an IP address.
Args: ip: IP address to lookup. If None, returns current timezone.
Returns: IANA timezone string.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | No |
Implementation Reference
- src/mcp_ipinfo/server.py:477-496 (handler)The primary handler function for the MCP tool 'get_ip_timezone'. Decorated with @mcp.tool() for automatic registration and schema inference from signature/docstring. Handles input validation, retrieves the IPInfoClient instance, calls the appropriate client method based on whether IP is provided, and propagates errors via context.@mcp.tool() async def get_ip_timezone(ctx: Context[Any, Any, Any], ip: str | None = None) -> str: """Get just the timezone for an IP address. Args: ip: IP address to lookup. If None, returns current timezone. Returns: IANA timezone string. """ client = get_client(ctx) try: if ip: return await client.get_timezone_by_ip(ip) else: return await client.get_current_timezone() except IPInfoAPIError as e: ctx.error(f"API error: {e.message}") raise
- src/mcp_ipinfo/api_client.py:393-396 (helper)Supporting utility in IPInfoClient that makes the HTTP GET request to the IPInfo API's /{ip}/timezone endpoint to fetch the timezone data and extracts the 'result' field as a string.async def get_timezone_by_ip(self, ip: str) -> str: """Get timezone for an IP.""" data = await self._request("GET", f"/{ip}/timezone") return str(data.get("result", ""))
- src/mcp_ipinfo/server.py:29-38 (helper)Utility function shared across all tools to lazily initialize and retrieve the singleton IPInfoClient instance, checking for API token and warning via context if missing.def get_client(ctx: Context[Any, Any, Any]) -> IPInfoClient: """Get or create the API client instance.""" global _client if _client is None: api_token = os.environ.get("IPINFO_API_TOKEN") if not api_token: ctx.warning("IPINFO_API_TOKEN is not set - some features may be limited") _client = IPInfoClient(api_token=api_token) return _client