Skip to main content
Glama

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
NameRequiredDescriptionDefault
ipNo

Implementation Reference

  • 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
  • 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", ""))
  • 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

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/NimbleBrainInc/mcp-ipinfo'

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