Files
mars-mcp/mars_toolkit/misc/misc_tools.py

30 lines
976 B
Python

"""
General Tools Module
This module provides basic utility functions that are not specific to materials science.
"""
import asyncio
from datetime import datetime
import pytz
from typing import Annotated
from mars_toolkit.core.llm_tools import llm_tool
@llm_tool(name="get_current_time", description="Get current date and time in specified timezone")
async def get_current_time(timezone: str = "UTC") -> str:
"""Returns the current date and time in the specified timezone.
Args:
timezone: Timezone name (e.g., UTC, Asia/Shanghai, America/New_York)
Returns:
Formatted date and time string
"""
try:
tz = pytz.timezone(timezone)
current_time = datetime.now(tz)
return f"The current {timezone} time is: {current_time.strftime('%Y-%m-%d %H:%M:%S %Z')}"
except pytz.exceptions.UnknownTimeZoneError:
return f"Unknown timezone: {timezone}. Please use a valid timezone such as 'UTC', 'Asia/Shanghai', etc."