get_utc
Retrieve precise UTC time from an NTP server to ensure a universal time reference, independent of local timezone settings. Simplifies time synchronization.
Instructions
Returns accurate UTC time from an NTP server. This provides a universal time reference regardless of local timezone.
:param server: NTP server address (default: pool.ntp.org)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| server | No | pool.ntp.org |
Implementation Reference
- mcp_simple_timeserver/server.py:34-49 (handler)Core handler function for the 'get_utc' tool. Queries the specified NTP server (default 'pool.ntp.org') to retrieve and format the current UTC time.def get_utc(server: str = DEFAULT_NTP_SERVER) -> str: """ Returns accurate UTC time from an NTP server. This provides a universal time reference regardless of local timezone. :param server: NTP server address (default: pool.ntp.org) """ try: ntp_client = ntplib.NTPClient() response = ntp_client.request(server, version=3) utc_time = datetime.fromtimestamp(response.tx_time, tz=UTC) formatted_time = utc_time.strftime("%Y-%m-%d %H:%M:%S") return f"Current UTC Time from {server}: {formatted_time}" except ntplib.NTPException as e: return f"Error getting NTP time: {str(e)}"
- Handler function for the 'get_utc' tool in the web server variant. Identical logic to the main server implementation.def get_utc(server: str = DEFAULT_NTP_SERVER) -> str: """ Returns accurate UTC time from an NTP server. This provides a universal time reference regardless of local timezone. :param server: NTP server address (default: pool.ntp.org) """ try: ntp_client = ntplib.NTPClient() response = ntp_client.request(server, version=3) utc_time = datetime.fromtimestamp(response.tx_time, tz=UTC) formatted_time = utc_time.strftime("%Y-%m-%d %H:%M:%S") return f"Current UTC Time from {server}: {formatted_time}" except ntplib.NTPException as e: return f"Error getting NTP time: {str(e)}"
- mcp_simple_timeserver/server.py:28-33 (registration)Registration of the 'get_utc' tool using FastMCP's @app.tool decorator, including annotations for title and read-only hint.@app.tool( annotations = { "title": "Get UTC Time from an NTP Server", "readOnlyHint": True } )
- mcp_simple_timeserver/web/server.py:32-37 (registration)Registration of the 'get_utc' tool in the web server using FastMCP's @app.tool decorator.@app.tool( annotations = { "title": "Get UTC Time from an NTP Server", "readOnlyHint": True } )
- mcp_simple_timeserver/server.py:6-6 (helper)Default NTP server constant used by the get_utc handler.DEFAULT_NTP_SERVER = 'pool.ntp.org'