Add get_current_time tool and TIMEZONE env variable
This commit is contained in:
@@ -28,6 +28,7 @@ import email.policy
|
|||||||
import imaplib
|
import imaplib
|
||||||
import smtplib
|
import smtplib
|
||||||
import logging
|
import logging
|
||||||
|
import pytz
|
||||||
import threading
|
import threading
|
||||||
import uuid
|
import uuid
|
||||||
from contextvars import ContextVar
|
from contextvars import ContextVar
|
||||||
@@ -156,6 +157,9 @@ class GlobalConfig:
|
|||||||
# Scheduling
|
# Scheduling
|
||||||
SCHEDULED_SEND_INTERVAL: int = int(os.getenv("SCHEDULED_SEND_INTERVAL", "10"))
|
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)
|
# HTML signature (optional)
|
||||||
# Can be:
|
# Can be:
|
||||||
# - Raw HTML string
|
# - Raw HTML string
|
||||||
@@ -1522,6 +1526,15 @@ TOOLS = [
|
|||||||
"required": []
|
"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")
|
logger.info(f"{prefix}call_tool get_triage_config")
|
||||||
return get_triage_config_impl(args)
|
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}")
|
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 --------------------
|
# -------------------- FASTAPI / MCP ENDPOINT --------------------
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
|
|||||||
Reference in New Issue
Block a user