Skip to content

feat(time): default to configured timezone when omitted - #3740

Closed
Christian-Sidak wants to merge 1 commit into
modelcontextprotocol:mainfrom
Christian-Sidak:feat-time-default-timezone
Closed

feat(time): default to configured timezone when omitted#3740
Christian-Sidak wants to merge 1 commit into
modelcontextprotocol:mainfrom
Christian-Sidak:feat-time-default-timezone

Conversation

@Christian-Sidak

Copy link
Copy Markdown

Summary

When --local-timezone is configured, the time server currently only uses it as a hint in the tool description, hoping the LLM will pass it explicitly. If the LLM omits the timezone argument, the call fails with "Missing required argument."

This PR makes the configured timezone an actual default:

  • get_current_time: timezone is now optional. Defaults to local_tz when not provided.
  • convert_time: source_timezone and target_timezone are now optional, both defaulting to local_tz. Only time remains required.
  • Tool descriptions updated to say "Defaults to X if not provided" instead of "Use X as local timezone if no timezone provided by the user."

This means a user can say "what time is it?" and the LLM can call get_current_time with no arguments, getting the local time. Previously this would error.

Fixes #2853

Test plan

  • All 38 existing tests pass (no regressions)
  • 3 new tests for default timezone behavior:
    • get_current_time with no timezone uses local_tz
    • convert_time with no source_timezone uses local_tz
    • convert_time with no target_timezone uses local_tz
  • 41/41 tests pass total

When --local-timezone is configured, the timezone parameters in
get_current_time and convert_time now default to the local timezone
instead of raising an error. This means LLMs no longer need to
explicitly pass the timezone on every call.

- get_current_time: timezone is now optional, defaults to local_tz
- convert_time: source_timezone and target_timezone are optional,
  default to local_tz. Only time remains required.
- Updated tool descriptions to reflect the default behavior

Fixes modelcontextprotocol#2853
@Christian-Sidak

Copy link
Copy Markdown
Author

Friendly bump -- any chance this could get a look? Happy to make adjustments.

@Christian-Sidak

Copy link
Copy Markdown
Author

Closing due to inactivity. Happy to reopen if there's interest.

@cliffhall cliffhall added enhancement New feature or request server-time Reference implementation for the Time MCP server - src/time labels Apr 20, 2026
@cliffhall

Copy link
Copy Markdown
Member

@claude review

@claude

claude Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Claude finished @cliffhall's task in 2m 3s —— View job


PR Review: feat(time): default to configured timezone when omitted

  • Gather context and read changed files
  • Analyze implementation correctness
  • Check test coverage
  • Review code style and MCP patterns
  • Post final review

The core idea here is solid and the server.py changes are clean. The main concern is that the new tests have structural problems that would prevent them from working correctly.

server.py — Implementation

The changes to call_tool are correct and idiomatic:

# Before
timezone = arguments.get("timezone")
if not timezone:
    raise ValueError("Missing required argument: timezone")

# After
timezone = arguments.get("timezone") or local_tz

The JSON Schema updates are also correct — moving timezone and source/target_timezone out of required and updating descriptions to say "Defaults to X if not provided." The "required": [] in get_current_time is technically valid JSON Schema, though it could be simplified by omitting required entirely.

One minor design note: When a caller omits both source_timezone and target_timezone from convert_time, both will default to local_tz, resulting in a trivial same-timezone conversion with time_difference: "+0.0h". This is correct behavior but could be documented in the description.

time_server_test.py — Test Issues

Issue 1 — Missing pytest-asyncio dependency (blocking)

The 3 new tests are declared as async def with @pytest.mark.asyncio, but pytest-asyncio is not listed in pyproject.toml's [tool.uv] dev-dependencies. Without it, pytest cannot execute async test functions and these tests will either be skipped or error. Since the test functions contain no await calls, the simplest fix is to make them regular synchronous functions. Fix this →

Issue 2 — Tests don't actually test the server handler (significant)

All three tests manually replicate the arguments.get(...) or local_tz logic instead of calling through the actual call_tool handler. For example:

# This tests nothing about the server — it just calls TimeServer.get_current_time directly
timezone = {}.get("timezone") or local_tz   # always resolves to local_tz
result = time_server.get_current_time(timezone)

The tests would pass even if call_tool still raised ValueError("Missing required argument: timezone"). To actually validate the behavior, they should invoke the handler with empty arguments, e.g. by calling serve() and exercising the MCP tool call, or at minimum by directly calling the call_tool closure. Fix this →

Issue 3 — Unused variable and import

In test_get_current_time_defaults_to_local_tz, server_obj = Server("mcp-time") is created but never used.

Summary

The server.py implementation is correct and addresses a real usability gap. The tests need rework before this can merge: they need pytest-asyncio added as a dependency (or the async declaration removed), and the test logic should exercise the actual call_tool handler rather than replicating its internals. The fix to the tests is straightforward — this PR is close.

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

Labels

enhancement New feature or request server-time Reference implementation for the Time MCP server - src/time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp-server-time: Default Time Zone

3 participants