Skip to content

Add timezone support to tool prompts for localized time context#2233

Open
gary149 wants to merge 4 commits intohuggingface:mainfrom
gary149:claude/add-time-location-mcp-5AsIw
Open

Add timezone support to tool prompts for localized time context#2233
gary149 wants to merge 4 commits intohuggingface:mainfrom
gary149:claude/add-time-location-mcp-5AsIw

Conversation

@gary149
Copy link
Copy Markdown
Collaborator

@gary149 gary149 commented Apr 12, 2026

Summary

This PR adds timezone awareness to the tool prompt generation system, allowing AI models to have access to the user's local time and timezone information when deciding whether and how to use tools.

Key Changes

  • Tool prompt enhancement: Updated buildToolPreprompt() to accept an optional timezone parameter and include the user's current date/time in their local timezone, along with a timezone identifier
  • Improved tool usage guidance: Refined the tool prompt messaging to encourage more judicious tool use ("Only use a tool if you cannot answer without it")
  • Request handling: Added timezone extraction from client requests in the conversation POST endpoint, storing it in locals for downstream use
  • MCP flow integration: Modified runMcpFlow() to retrieve the user's timezone from locals and pass it to the tool prompt builder
  • Client-side timezone detection: Updated the frontend to automatically detect and send the user's IANA timezone using the Intl API
  • Type definitions: Added timezone field to message update request options for proper type safety

Implementation Details

  • The timezone is detected client-side using Intl.DateTimeFormat().resolvedOptions().timeZone and sent with each message request
  • The timezone is passed through the request validation layer and stored in the locals context
  • Tool prompts now include both the formatted current date/time and the timezone identifier (e.g., "America/New_York")
  • The implementation gracefully handles cases where timezone is not provided, maintaining backward compatibility

https://claude.ai/code/session_01HJmFTn6PDGAJaYRwdairXi

claude and others added 4 commits January 19, 2026 09:13
Add explicit guidance to the system prompt that instructs the model to:
- Prefer direct answers over tool calls for simple tasks
- Only use tools when genuinely needed
- Stop making additional calls when enough info is gathered
- Categorize tools (generative vs search) with specific usage rules

This addresses the issue where models would make excessive tool calls
for simple requests like spelling checks or prompt edits.
Replace complex categorization logic with a single clear instruction:
"Only use a tool if you cannot answer without it."

This follows Anthropic's recommended approach of using simple, direct
instructions rather than elaborate rule systems.
Send the user's IANA timezone from the browser (via
Intl.DateTimeFormat) through the request pipeline so that the MCP
tool system prompt includes the current date/time with weekday and
the user's timezone location instead of just the date.

https://claude.ai/code/session_01HJmFTn6PDGAJaYRwdairXi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants