From bfacfbfc45fdd1bff3173da07dfd5bdfaf4b899f Mon Sep 17 00:00:00 2001 From: Admin Date: Sun, 28 Jun 2026 05:10:38 +0000 Subject: [PATCH] Add get_current_time tool and TIMEZONE env variable --- server.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/server.py b/server.py index f090db4..08089c5 100644 --- a/server.py +++ b/server.py @@ -28,6 +28,7 @@ import email.policy import imaplib import smtplib import logging +import pytz import threading import uuid from contextvars import ContextVar @@ -156,6 +157,9 @@ class GlobalConfig: # Scheduling SCHEDULED_SEND_INTERVAL: int = int(os.getenv("SCHEDULED_SEND_INTERVAL", "10")) + # Timezone (used by get_current_time) + TIMEZONE: str = os.getenv("TIMEZONE", "UTC").strip() or "UTC" + # HTML signature (optional) # Can be: # - Raw HTML string @@ -1522,6 +1526,15 @@ TOOLS = [ "required": [] } }, + { + "name": "get_current_time", + "description": "Return the current date and time in the configured timezone. Use this to understand relative dates like 'today', 'yesterday', or 'last week' when reviewing emails.", + "inputSchema": { + "type": "object", + "properties": {}, + "required": [] + } + }, ] @@ -1714,6 +1727,10 @@ def call_tool(name, args): logger.info(f"{prefix}call_tool get_triage_config") return get_triage_config_impl(args) + if name == "get_current_time": + logger.info(f"{prefix}call_tool get_current_time") + return get_current_time_impl(args) + raise ValueError(f"Unknown tool: {name}") @@ -2405,6 +2422,22 @@ def get_triage_config_impl(args): } +def get_current_time_impl(args): + """ + Return the current date and time in the configured timezone. + """ + tz_name = config.TIMEZONE or "UTC" + try: + tz = pytz.timezone(tz_name) + except Exception: + tz = pytz.utc + now = datetime.now(tz) + return { + "iso": now.isoformat(), + "timezone": tz_name, + } + + # -------------------- FASTAPI / MCP ENDPOINT -------------------- app = FastAPI(