mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-02-19 11:54:58 -05:00
Fix time server to default to UTC when tzinfo is unavailable (#2738)
When get_localzone_name() returns None, the server now defaults to UTC instead of raising an error. This makes the server more robust in environments where the local timezone cannot be determined.
This commit is contained in:
@@ -46,7 +46,8 @@ def get_local_tz(local_tz_override: str | None = None) -> ZoneInfo:
|
||||
local_tzname = get_localzone_name()
|
||||
if local_tzname is not None:
|
||||
return ZoneInfo(local_tzname)
|
||||
raise McpError("Could not determine local timezone - tzinfo is None")
|
||||
# Default to UTC if local timezone cannot be determined
|
||||
return ZoneInfo("UTC")
|
||||
|
||||
|
||||
def get_zoneinfo(timezone_name: str) -> ZoneInfo:
|
||||
|
||||
@@ -486,10 +486,10 @@ def test_get_local_tz_with_valid_iana_name(mock_get_localzone):
|
||||
|
||||
@patch('mcp_server_time.server.get_localzone_name')
|
||||
def test_get_local_tz_when_none_returned(mock_get_localzone):
|
||||
"""Test error when tzlocal returns None."""
|
||||
"""Test default to UTC when tzlocal returns None."""
|
||||
mock_get_localzone.return_value = None
|
||||
with pytest.raises(McpError, match="Could not determine local timezone"):
|
||||
get_local_tz()
|
||||
result = get_local_tz()
|
||||
assert str(result) == "UTC"
|
||||
|
||||
|
||||
@patch('mcp_server_time.server.get_localzone_name')
|
||||
|
||||
Reference in New Issue
Block a user