what_time_is_it
Get the current time string tailored to your location using your IP address. Simplifies time checks with automatic time zone detection.
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:10-26 (handler)The asynchronous handler function that implements the 'what_time_is_it' tool. It fetches the current datetime from the World Time API using the client's IP address and returns it as a string, with comprehensive error handling for HTTP status errors and unexpected exceptions.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)}"
- main.py:9-9 (registration)The @mcp.tool() decorator registers the 'what_time_is_it' function as a tool in the FastMCP server.@mcp.tool()