Skip to main content
Glama
batteryshark

DateTime MCP Server

by batteryshark

get_current_date

Retrieve the current date in ISO format (YYYY-MM-DD) with an option to include the day of the week for accurate date referencing and time-sensitive operations.

Instructions

Get the current date in ISO format (YYYY-MM-DD).

Args: include_weekday: Whether to append the day of the week

Returns: ISO date string, optionally with weekday

Examples: get_current_date() -> "2024-01-15" get_current_date(include_weekday=True) -> "2024-01-15 (Monday)"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_weekdayNo

Implementation Reference

  • server.py:67-96 (handler)
    Handler function for the 'get_current_date' tool. It retrieves the current date in the configured timezone, optionally including the weekday name. Uses helper functions load_config and get_timezone. Returns a ToolResult with plain text content. The @mcp.tool decorator registers it as an MCP tool.
    def get_current_date(include_weekday: bool = False, ctx: Context = None) -> ToolResult: """ Get the current date in ISO format (YYYY-MM-DD). Args: include_weekday: Whether to append the day of the week Returns: ISO date string, optionally with weekday Examples: get_current_date() -> "2024-01-15" get_current_date(include_weekday=True) -> "2024-01-15 (Monday)" """ tz_string, _ = load_config(ctx) timezone = get_timezone(tz_string) # Get current date in the specified timezone now = datetime.now(timezone) date_str = now.strftime("%Y-%m-%d") if include_weekday: weekday = now.strftime("%A") result_text = f"{date_str} ({weekday})" else: result_text = date_str # Return raw text without JSON wrapping - more efficient per policy return ToolResult(content=[TextContent(type="text", text=result_text)])
  • Helper function to load timezone and time format from context headers (HTTP) or environment variables (stdio), with defaults.
    def load_config(context: Optional[Context] = None) -> tuple[str, str]: """ Load timezone and time format configuration. For HTTP transport, configuration comes from headers. For stdio transport, configuration comes from environment variables. Returns: tuple: (timezone_string, time_format) """ # Default values default_tz = "UTC" default_timefmt = "24" # Try to get from context headers first (HTTP transport) if context and hasattr(context, 'meta') and context.meta: headers = context.meta.get('headers', {}) tz_string = headers.get('DEFAULT_TZ', headers.get('default_tz')) time_format = headers.get('TIMEFMT', headers.get('timefmt')) if tz_string and time_format: return tz_string, time_format # Fall back to environment variables (stdio transport) tz_string = os.getenv('DEFAULT_TZ', default_tz) time_format = os.getenv('TIMEFMT', default_timefmt) return tz_string, time_format
  • Helper function to safely convert timezone string to ZoneInfo object, falling back to UTC on error.
    def get_timezone(tz_string: str) -> ZoneInfo: """ Convert timezone string to ZoneInfo object. Args: tz_string: Timezone identifier (e.g., "America/New_York", "UTC") Returns: ZoneInfo object, defaults to UTC if invalid timezone """ try: return ZoneInfo(tz_string) except Exception: # Graceful fallback to UTC for invalid timezones return ZoneInfo("UTC")

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/batteryshark/mcp-datetime'

If you have feedback or need assistance with the MCP directory API, please join our Discord server