{"record":{"id":"0c45fbf29603777b","repo":"modelcontextprotocol/servers","slug":"invalid-params","errorCode":"INVALID_PARAMS","errorMessage":"Invalid timezone: {str(e)}","messagePattern":"Invalid timezone: (.+?)","errorType":"error_code","errorClass":"McpError","httpStatus":null,"severity":"error","filePath":"src/time/src/mcp_server_time/server.py","lineNumber":57,"sourceCode":"\n\ndef get_local_tz(local_tz_override: str | None = None) -> ZoneInfo:\n    if local_tz_override:\n        return ZoneInfo(local_tz_override)\n\n    # Get local timezone from datetime.now()\n    local_tzname = get_localzone_name()\n    if local_tzname is not None:\n        return ZoneInfo(local_tzname)\n    # Default to UTC if local timezone cannot be determined\n    return ZoneInfo(\"UTC\")\n\n\ndef get_zoneinfo(timezone_name: str) -> ZoneInfo:\n    try:\n        return ZoneInfo(timezone_name)\n    except Exception as e:\n        raise McpError(ErrorData(code=INVALID_PARAMS, message=f\"Invalid timezone: {str(e)}\"))\n\n\nclass TimeServer:\n    def get_current_time(self, timezone_name: str) -> TimeResult:\n        \"\"\"Get current time in specified timezone\"\"\"\n        timezone = get_zoneinfo(timezone_name)\n        current_time = datetime.now(timezone)\n\n        return TimeResult(\n            timezone=timezone_name,\n            datetime=current_time.isoformat(timespec=\"seconds\"),\n            day_of_week=current_time.strftime(\"%A\"),\n            is_dst=bool(current_time.dst()),\n        )\n\n    def convert_time(\n        self, source_tz: str, time_str: str, target_tz: str\n    ) -> TimeConversionResult:","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/76d64c822f5125032f89eb71dbdb94e42b434821/src/time/src/mcp_server_time/server.py#L39-L75","documentation":"get_zoneinfo (server.py:53-57) wraps ZoneInfo(timezone_name); any failure is re-raised as McpError(INVALID_PARAMS, 'Invalid timezone: ...'). ZoneInfo fails on non-IANA names ('PST', 'EST', 'UTC+5'), typos, or when the host lacks tz data (notably Windows without the 'tzdata' package). IMPORTANT: when reached via get_current_time/convert_time this McpError is caught by the outer except Exception (error 49) and downgraded to a plain ValueError, so the structured INVALID_PARAMS code never reaches the client.","triggerScenarios":"Passing a POSIX abbreviation ('PST','EST'), an offset string ('UTC+2'), a typo ('America/LosAngelos'), or running on Windows/a slim container without tzdata installed.","commonSituations":"Users used to tz abbreviations. Windows dev hosts. Minimal Docker images missing the tzdata wheel. LLM-supplied timezone strings.","solutions":["Use a full IANA name: 'America/Los_Angeles', 'Europe/Berlin', 'UTC'.","On Windows or slim images, install tzdata (uv add tzdata / pip install tzdata).","Validate/normalize the timezone client-side against zoneinfo.available_timezones() before sending.","If you maintain the server, narrow the outer except (error 49) so McpError is re-raised unchanged and the code survives."],"exampleFix":"// before\n//   timezone: \"PST\"            -> Invalid timezone\n// after\n//   timezone: \"America/Los_Angeles\"","handlingStrategy":"try-catch","validationCode":"from zoneinfo import ZoneInfo, available_timezones\n\ndef valid_tz(name: str) -> str:\n    if not isinstance(name, str) or name not in available_timezones():\n        raise ValueError(f\"not an IANA timezone: {name!r}\")\n    ZoneInfo(name)  # smoke test; catches missing tzdata on Windows\n    return name","typeGuard":"from zoneinfo import available_timezones\n\ndef is_iana_tz(v: object) -> bool:\n    return isinstance(v, str) and v in available_timezones()","tryCatchPattern":"from mcp.shared.exceptions import McpError\n\ntry:\n    result = time_server.get_current_time(timezone)\nexcept McpError as e:\n    # INVALID_PARAMS; surface to user, suggest an IANA name\n    handle_bad_timezone(e)","preventionTips":["Use full IANA names only (America/Los_Angeles, Europe/Berlin, UTC).","Install tzdata in Windows hosts and slim containers.","Surface available_timezones() to users in the UI prompt."],"tags":["time","timezone","zoneinfo","python","invalid-params"],"backgroundTag":null,"analyzedSha":"76d64c822f5125032f89eb71dbdb94e42b434821","analyzedAt":"2026-08-12T10:02:41.718Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}