Skip to main content
Glama
batteryshark

DateTime MCP Server

by batteryshark

get_current_time

Retrieve the current time in your preferred 12-hour or 24-hour format using the DateTime MCP Server's configurable time settings.

Instructions

Get the current time in the configured format.

Returns: Time string in 12-hour or 24-hour format based on TIMEFMT setting

Examples: With TIMEFMT="12": "2:30 PM" With TIMEFMT="24": "14:30"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'get_current_time' tool. It is registered via the @mcp.tool decorator. Loads timezone and format from configuration, computes current time, formats it (12h or 24h), and returns as ToolResult.
    @mcp.tool
    def get_current_time(ctx: Context = None) -> ToolResult:
        """
        Get the current time in the configured format.
        
        Returns:
            Time string in 12-hour or 24-hour format based on TIMEFMT setting
            
        Examples:
            With TIMEFMT="12": "2:30 PM"
            With TIMEFMT="24": "14:30"
        """
        tz_string, time_format = load_config(ctx)
        timezone = get_timezone(tz_string)
        
        # Get current time in the specified timezone
        now = datetime.now(timezone)
        
        if time_format == "12":
            # 12-hour format with AM/PM
            result_text = now.strftime("%I:%M %p").lstrip('0')
        else:
            # 24-hour format (default)
            result_text = now.strftime("%H:%M")
        
        # Return raw text without JSON wrapping - more efficient per policy
        return ToolResult(content=[TextContent(type="text", text=result_text)])
  • Helper function to load timezone string and time format from context headers or environment variables, 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 resolve 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")
  • server.py:98-98 (registration)
    The @mcp.tool decorator registers the get_current_time function as an MCP tool.
    @mcp.tool
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the output format depends on a TIMEFMT setting, which is useful behavioral context. However, it does not mention other traits like whether this is a read-only operation, potential errors, or performance considerations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and concise, with a clear purpose statement followed by returns and examples sections. Every sentence adds value without waste, and it is front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (0 parameters, no output schema, no annotations), the description is reasonably complete. It explains what the tool does, the output format dependency, and provides examples. However, it could be more explicit about sibling tool differentiation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description appropriately focuses on output behavior without redundant parameter info, earning a baseline score of 4 for zero-parameter tools.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get the current time in the configured format.' It specifies the verb ('Get') and resource ('current time'), but does not explicitly differentiate from its sibling tool 'get_current_date'. The distinction is implied but not stated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through the mention of 'configured format' and TIMEFMT setting, but does not provide explicit guidance on when to use this tool versus alternatives (e.g., 'get_current_date'). No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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