Repository navigation
Conversation
A timezone that names a tz database directory (`America`) makes zoneinfo raise an OSError whose text quotes the absolute path to the tzdata install, and `get_zoneinfo` passed that text to the client. Every invalid timezone now gets one fixed message that names only the input: `Invalid timezone: '<name>' is not a known IANA timezone name`, the same wording `serve()` already uses for a bad --local-timezone. Closes #5559 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
|
|
| Tools | Prompts | Resources | Resource templates | |
|---|---|---|---|---|
| Base | 3 | 0 | 0 | 0 |
| Head | 3 | 0 | 0 | 0 |
Updated by this run for 55b6e7b040d60cd858ccd291b1e6067209c02ecc.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change that prevents timezone errors from exposing host filesystem paths.
No open issues 🎉
What changed in this PR
Fixes #5559 by preventing invalid-timezone errors from exposing the host’s tzdata filesystem path. The time server now returns a consistent message naming only the supplied timezone, without changing tool schemas or annotations.
Changes:
- Replaces loader exception text with a fixed invalid-timezone message.
- Adds protocol-level regression cases for tzdata directory names across all three time tools and updates existing error assertions.
- Documents the sanitized error format.
| File | Description |
|---|---|
src/time/tests/test_server.py |
Updates unit-test expectations for invalid-timezone errors. |
src/time/tests/test_protocol.py |
Covers directory-name inputs and updates protocol error assertions. |
src/time/tests/test_eras.py |
Updates the expected error message across both protocol eras. |
src/time/src/mcp_server_time/server.py |
Prevents loader exception text from reaching timezone tool errors. |
src/time/README.md |
Documents the fixed, input-only error message. |
Review effort: Balanced
|
Copilot round 1: clean (no findings, no inline or suppressed comments). The review loop ends here on the first clean round. |
Closes #5559
Description
A timezone argument that names a directory in the tz database (
America) makeszoneinforaise anOSErrorwhose text quotes the absolute path to the host's tzdata install.get_zoneinfoturned any exception intoToolError(f"Invalid timezone: {e!s}"), so that path, home-directory user name included, went back to the client in the tool result.get_zoneinfonow raises one fixed message for every invalid timezone, naming only the input:None of zoneinfo's own text reaches the client, whatever exception the loader raised. The wording is the one
serve()already uses for an invalid--local-timezone.Server Details
timeget_current_time,convert_timeandget_time_agofor an invalid timezone; the README's "Results and errors" entry. No tool, schema or annotation changes.Motivation and Context
See #5559. The old message leaked host filesystem details into tool output and was inconsistent with startup, which already hides zoneinfo's messages.
The message for an unknown name changes too, from
Invalid timezone: 'No time zone found with key Nope/Nowhere'toInvalid timezone: 'Nope/Nowhere' is not a known IANA timezone name: one message for every kind of bad key, rather than a fixed one only for the exception types known to leak. It still opens withInvalid timezone:and still names the input.How Has This Been Tested?
Automated:
tests/test_protocol.pydrivesserve()through an MCP client over in-memory streams and asserts the exact result forAmericaonget_current_time,convert_time(as source and as target) andget_time_ago. The existing unknown-name, non-exact-key,../etc/passwdand/etc/localtimecases now pin the fixed message.uv run pytest: 198 passed; per-file coverage 100% lines and branches onserver.py.Inspector CLI 2.12.0, both eras, before (
origin/v2/mainat 7f383a8) and after (this branch). The command, with<era>aslegacy(2025-11-25) andmodern(2026-07-28):Before,
legacy(themodernresult is the same text, plus_meta["io.modelcontextprotocol/serverInfo"]); the path prefix is trimmed here:{"result":{"content":[{"type":"text","text":"Error executing tool get_current_time: Invalid timezone: [Errno 21] Is a directory: '/Users/<user>/…/src/time/.venv/lib/python3.10/site-packages/tzdata/zoneinfo/America'"}],"isError":true}}After,
legacy:{"result":{"content":[{"type":"text","text":"Error executing tool get_current_time: Invalid timezone: 'America' is not a known IANA timezone name"}],"isError":true}}After,
modern:{"result":{"_meta":{"io.modelcontextprotocol/serverInfo":{"name":"mcp-time","version":"2026.11.18"}},"content":[{"type":"text","text":"Error executing tool get_current_time: Invalid timezone: 'America' is not a known IANA timezone name"}],"isError":true}}The same before/after pair was run in both eras for
convert_time({"source_timezone":"UTC","time":"12:00","target_timezone":"America"}) andget_time_ago({"timezone":"America","hours_ago":1}): each leaked the path before and returnsInvalid timezone: 'America' is not a known IANA timezone nameafter. An unknown name (Nope/Nowhere) returnsInvalid timezone: 'Nope/Nowhere' is not a known IANA timezone namein both eras.LLM client: Claude Code 2.1.327, headless, with
--strict-mcp-configpointing at this branch's build. Claude Code has no era switch and does not print the version it negotiated, so the era could not be selected.Error executing tool get_current_time: Invalid timezone: 'America' is not a known IANA timezone nameError executing tool convert_time: Invalid timezone: 'America' is not a known IANA timezone namenpm run local:gateexits 0.Breaking Changes
None. No client configuration changes. A client that string-matched zoneinfo's exception text inside the
Invalid timezone:message would see different text.Types of changes
Checklist
npm run changeset) if this changes what a TypeScript server publishes (not applicable: a Python server)🤖 Generated with Claude Code