what_time_is_it
Get the current time based on your IP address using World Time API. This tool provides accurate local time information for your location.
Instructions
Returns the current time string based on the client's IP using World Time API.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:9-26 (handler)The handler function for the 'what_time_is_it' tool. It is decorated with @mcp.tool(), which registers the tool. Fetches the current datetime from World Time API using the client's IP address and returns it as a string, with error handling.@mcp.tool() async def what_time_is_it() -> str: """Returns the current time string based on the client's IP using World Time API.""" url = "https://worldtimeapi.org/api/ip" # World Time API endpoint for IP-based time async with httpx.AsyncClient() as client: try: # Make an asynchronous GET request to the API response = await client.get(url) # Raise an exception if the HTTP request fails response.raise_for_status() # Extract and return only the 'datetime' field from the JSON response return response.json()["datetime"] except httpx.HTTPStatusError as e: # Handle HTTP errors and return an error message return f"Error: Failed to fetch time - {str(e)}" except Exception as e: # Handle unexpected errors and return an error message return f"Error: Unexpected issue - {str(e)}"