get_current_datetime
Retrieve the current date and time in your preferred timezone and format, including ISO, readable, timestamp, or custom options.
Instructions
Get the current date and time in the specified timezone and format.
Args:
timezone_name: Timezone name (e.g., "UTC", "US/Eastern", "Europe/London", "America/Sao_Paulo")
format_type: Format type ("iso", "readable", "timestamp", "custom")
Returns:
Current datetime in the requested format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone_name | No | UTC | |
| format_type | No | iso |
Implementation Reference
- util_server.py:121-167 (handler)The core handler function for the 'get_current_datetime' MCP tool. It is decorated with @mcp.tool(), which registers the tool with the FastMCP server and automatically generates the input/output schema from the type hints and docstring. The function fetches the current datetime in the specified timezone and formats it as requested.async def get_current_datetime(timezone_name: str = "UTC", format_type: str = "iso") -> str: """ Get the current date and time in the specified timezone and format. Args: timezone_name: Timezone name (e.g., "UTC", "US/Eastern", "Europe/London", "America/Sao_Paulo") format_type: Format type ("iso", "readable", "timestamp", "custom") Returns: Current datetime in the requested format """ try: # Get current UTC time now_utc = datetime.now(timezone.utc) # Convert to requested timezone if timezone_name.upper() == "UTC": target_time = now_utc else: try: tz = pytz.timezone(timezone_name) target_time = now_utc.astimezone(tz) except pytz.UnknownTimeZoneError: return f"β Unknown timezone: {timezone_name}\nπ‘ Try: UTC, US/Eastern, Europe/London, America/Sao_Paulo, etc." # Format the datetime if format_type.lower() == "iso": formatted_time = target_time.isoformat() elif format_type.lower() == "readable": formatted_time = target_time.strftime( "%A, %B %d, %Y at %I:%M:%S %p %Z") elif format_type.lower() == "timestamp": formatted_time = str(int(target_time.timestamp())) else: # custom or other formatted_time = target_time.strftime("%Y-%m-%d %H:%M:%S %Z") result = f"π **Current DateTime**\n" result += f"**Timezone:** {timezone_name}\n" result += f"**Format:** {format_type}\n" result += f"**DateTime:** {formatted_time}\n" result += f"**UTC Offset:** {target_time.strftime('%z')}\n" return result except Exception as e: return f"β Error getting current datetime: {str(e)}"
- util_server.py:121-121 (registration)The @mcp.tool() decorator registers the get_current_datetime function as an MCP tool on the FastMCP server instance 'mcp'.async def get_current_datetime(timezone_name: str = "UTC", format_type: str = "iso") -> str:
- util_server.py:122-131 (schema)The docstring provides the description used by FastMCP to generate the tool's JSON schema, along with type hints in the function signature (timezone_name: str = "UTC", format_type: str = "iso") -> str.""" Get the current date and time in the specified timezone and format. Args: timezone_name: Timezone name (e.g., "UTC", "US/Eastern", "Europe/London", "America/Sao_Paulo") format_type: Format type ("iso", "readable", "timestamp", "custom") Returns: Current datetime in the requested format """