Skip to content

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

Open

Description

@cliffhall

Problem

get_zoneinfo (src/time/src/mcp_server_time/server.py) turns any exception from loading a zone into ToolError(f"Invalid timezone: {e!s}"). For most bad names that is a clean "No time zone found" message, but a name that is a directory in the tz database (for example America) raises an OSError whose text includes the host's absolute path to the tzdata install, e.g.:

Invalid timezone: [Errno 21] Is a directory: '/Users/<user>/.../site-packages/tzdata/zoneinfo/America'

That leaks host filesystem details (including a home-directory user name) into tool output, and it is inconsistent with startup, where serve() already hides these messages.

Expected behavior

An invalid timezone always produces a fixed, clean message naming the input, such as Invalid timezone: America, with no exception text, whatever exception the zone loader raised.

Acceptance criteria

  • get_current_time and convert_time called with a tz-database directory name (America) return a clean Invalid timezone error containing no filesystem path.
  • Existing error messages for unknown names are unchanged or equally clean.
  • Tests cover the directory case at the protocol level.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingserver-timeReference implementation for the Time MCP server - src/timev2

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions