Skip to content

fix(time): keep the host's tzdata path out of invalid-timezone errors - #5615

Open
cliffhall wants to merge 1 commit into
v2/mainfrom
v2/fix/5559-time-invalid-timezone-path-leak
Open

cliffhall wants to merge 1 commit into
v2/mainfrom
v2/fix/5559-time-invalid-timezone-path-leak

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #5559

Description

A timezone argument that names a directory in the tz database (America) makes zoneinfo raise an OSError whose text quotes the absolute path to the host's tzdata install. get_zoneinfo turned any exception into ToolError(f"Invalid timezone: {e!s}"), so that path, home-directory user name included, went back to the client in the tool result.

get_zoneinfo now raises one fixed message for every invalid timezone, naming only the input:

Invalid timezone: '<name>' is not a known IANA timezone name

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

  • Server: time
  • Changes to: the error text of get_current_time, convert_time and get_time_ago for 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' to Invalid 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 with Invalid timezone: and still names the input.

How Has This Been Tested?

Automated: tests/test_protocol.py drives serve() through an MCP client over in-memory streams and asserts the exact result for America on get_current_time, convert_time (as source and as target) and get_time_ago. The existing unknown-name, non-exact-key, ../etc/passwd and /etc/localtime cases now pin the fixed message. uv run pytest: 198 passed; per-file coverage 100% lines and branches on server.py.

Inspector CLI 2.12.0, both eras, before (origin/v2/main at 7f383a8) and after (this branch). The command, with <era> as legacy (2025-11-25) and modern (2026-07-28):

npx -y @modelcontextprotocol/inspector@2.12.0 --cli uv --directory src/time run mcp-server-time -- \
  --protocol-era <era> --method tools/call --tool-name get_current_time --tool-arg timezone=America --format json

Before, legacy (the modern result 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"}) and get_time_ago ({"timezone":"America","hours_ago":1}): each leaked the path before and returns Invalid timezone: 'America' is not a known IANA timezone name after. An unknown name (Nope/Nowhere) returns Invalid timezone: 'Nope/Nowhere' is not a known IANA timezone name in both eras.

LLM client: Claude Code 2.1.327, headless, with --strict-mcp-config pointing 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.

  • Prompt: "Call the get_current_time tool of the time server with timezone 'America' and reply with exactly the text it returned, nothing else." → Error executing tool get_current_time: Invalid timezone: 'America' is not a known IANA timezone name
  • Prompt: "Use the time server's convert_time tool to convert 12:00 from UTC to the timezone 'America'. Reply with exactly the text the tool returned, nothing else." → Error executing tool convert_time: Invalid timezone: 'America' is not a known IANA timezone name

npm run local:gate exits 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follow MCP security best practices
  • I have updated the server's README accordingly
  • I have added a changeset (npm run changeset) if this changes what a TypeScript server publishes (not applicable: a Python server)
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options (not applicable: none added or changed)

🤖 Generated with Claude Code

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>
@cliffhall cliffhall added the v2 label Nov 18, 2026
@cliffhall cliffhall self-assigned this Nov 18, 2026
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 55b6e7b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

time: MCP interface diff

Base: 7f383a8e0f34 (Merge pull request #5597 from modelcontextprotocol/changeset-release/v2/main)
Head: the build in this checkout, at cc8fdbdfa30c (Merge 55b6e7b into 7f383a8)

Diffed because it was named (--server).

✅ No interface changes detected.

Tools Prompts Resources Resource templates
Base 3 0 0 0
Head 3 0 0 0

Updated by this run for 55b6e7b040d60cd858ccd291b1e6067209c02ecc.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: clean (no findings, no inline or suppressed comments). The review loop ends here on the first clean round.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

time: an invalid timezone that names a tzdata directory returns an error with the host's filesystem path

2 participants