Add get_current_time tool and TIMEZONE env variable

This commit is contained in:
Admin
2026-06-28 05:10:38 +00:00
parent dbea28b742
commit bfacfbfc45
+33
View File
@@ -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(