Skip to content

Fix CST timezone ambiguity error in get_local_tz function #2097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zhouruiliangxian
Copy link

Description

Fixed "No time zone found with key CST" error in the get_local_tz function. Enhanced timezone handling logic to intelligently identify ambiguous timezone abbreviations (like CST) and added mapping for common timezone abbreviations to IANA timezone names.

Server Details

  • Server: time
  • Changes to: tools (get_local_tz function enhancement)

Motivation and Context

CST is an ambiguous timezone abbreviation that can represent multiple different timezones:

  • China Standard Time (UTC+8)
  • Central Standard Time (UTC-6)
  • Cuba Standard Time (UTC-5)

When the system returns "CST" as the timezone name, directly using ZoneInfo("CST") throws a "No time zone found with key CST" error because CST is not a valid IANA timezone identifier.

This fix resolves the issue by:

  1. Intelligently determining the specific CST timezone based on UTC offset
  2. Adding mappings for other common ambiguous timezone abbreviations
  3. Providing graceful fallback handling

How Has This Been Tested?

  • Tested CST timezone recognition under different UTC offsets
  • Verified correct mapping of other common timezone abbreviations (EST, PST, MST, JST, KST)
  • Tested UTC fallback handling when timezone cannot be recognized
  • Tested normal operation of MCP server in local environment

Breaking Changes

No breaking changes. This is a backward-compatible bug fix that does not require users to update their MCP client configurations.

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 https://modelcontextprotocol.io
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • 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

Additional context

Implementation Details

  1. Intelligent CST Detection: Determines specific CST timezone by checking UTC offset of current time
  2. Timezone Mapping Table: Added mappings for common timezone abbreviations to improve compatibility
  3. Error Handling: Maintains original error handling logic while adding graceful fallback to UTC
  4. Performance Considerations: Uses simple dictionary lookup without affecting performance

Design Decisions

  • Chose Asia/Shanghai for UTC+8 CST as it's the most commonly used UTC+8 timezone
  • Chose America/Chicago for UTC-6 CST as it represents US Central Standard Time's primary city
  • Chose America/Havana for UTC-5 CST corresponding to Cuba Standard Time
  • When unable to determine specific timezone, fallback to UTC instead of throwing exception for better user experience

This fix addresses a real user pain point, especially for users on Chinese systems or US Central timezone.

- Add intelligent CST timezone detection based on UTC offset
- Map CST to appropriate IANA timezone names:
  * UTC+8: Asia/Shanghai (China Standard Time)
  * UTC-6: America/Chicago (Central Standard Time)
  * UTC-5: America/Havana (Cuba Standard Time)
- Add mapping for other common timezone abbreviations
- Implement graceful fallback to UTC for unrecognized timezones

Fixes: 'No time zone found with key CST' error
@olaservo olaservo added server-time Reference implementation for the Time MCP server - src/time bug Something isn't working labels Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server-time Reference implementation for the Time MCP server - src/time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants