Skip to main content
Glama
danfmaia

Utility MCP Server

by danfmaia

calculate_time_difference

Calculate time intervals between two datetimes or from a start time to now, returning detailed breakdowns for scheduling and tracking purposes.

Instructions

Calculate the time difference between two datetimes or from a start time to now.

Args:
    start_datetime: Start datetime in ISO format (YYYY-MM-DD HH:MM:SS or YYYY-MM-DDTHH:MM:SS)
    end_datetime: End datetime in ISO format (optional - defaults to current time)
    timezone_name: Timezone for interpretation (default: UTC)

Returns:
    Time difference with detailed breakdown

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_datetimeYes
end_datetimeNo
timezone_nameNoUTC

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'calculate_time_difference' tool, automatically registered via @mcp.tool() decorator. It calculates the time difference between two datetimes (or start to now), handles various ISO formats, timezones via pytz, and returns a detailed formatted breakdown including total seconds, days/hours/mins/secs, and human-readable summary.
    @mcp.tool()
    async def calculate_time_difference(start_datetime: str, end_datetime: str = "", timezone_name: str = "UTC") -> str:
        """
        Calculate the time difference between two datetimes or from a start time to now.
    
        Args:
            start_datetime: Start datetime in ISO format (YYYY-MM-DD HH:MM:SS or YYYY-MM-DDTHH:MM:SS)
            end_datetime: End datetime in ISO format (optional - defaults to current time)
            timezone_name: Timezone for interpretation (default: UTC)
    
        Returns:
            Time difference with detailed breakdown
        """
        try:
            # Parse timezone
            if timezone_name.upper() == "UTC":
                tz = timezone.utc
            else:
                try:
                    tz = pytz.timezone(timezone_name)
                except pytz.UnknownTimeZoneError:
                    return f"āŒ Unknown timezone: {timezone_name}\nšŸ’” Try: UTC, US/Eastern, Europe/London, America/Sao_Paulo, etc."
    
            # Parse start datetime
            try:
                # Handle different datetime formats
                if 'T' in start_datetime:
                    start_dt = datetime.fromisoformat(
                        start_datetime.replace('Z', '+00:00'))
                else:
                    start_dt = datetime.strptime(
                        start_datetime, "%Y-%m-%d %H:%M:%S")
                    start_dt = start_dt.replace(tzinfo=tz)
            except ValueError:
                return f"āŒ Invalid start datetime format: {start_datetime}\nšŸ’” Use: YYYY-MM-DD HH:MM:SS or YYYY-MM-DDTHH:MM:SS"
    
            # Parse end datetime or use current time
            if end_datetime:
                try:
                    if 'T' in end_datetime:
                        end_dt = datetime.fromisoformat(
                            end_datetime.replace('Z', '+00:00'))
                    else:
                        end_dt = datetime.strptime(
                            end_datetime, "%Y-%m-%d %H:%M:%S")
                        end_dt = end_dt.replace(tzinfo=tz)
                except ValueError:
                    return f"āŒ Invalid end datetime format: {end_datetime}\nšŸ’” Use: YYYY-MM-DD HH:MM:SS or YYYY-MM-DDTHH:MM:SS"
            else:
                end_dt = datetime.now(tz)
    
            # Calculate difference
            time_diff = end_dt - start_dt
    
            # Extract components
            total_seconds = abs(time_diff.total_seconds())
            days = int(total_seconds // 86400)
            hours = int((total_seconds % 86400) // 3600)
            minutes = int((total_seconds % 3600) // 60)
            seconds = int(total_seconds % 60)
    
            # Determine direction
            direction = "later" if time_diff.total_seconds() >= 0 else "earlier"
    
            # Format result
            result = f"ā±ļø **Time Difference Calculation**\n"
            result += f"**From:** {start_dt.strftime('%Y-%m-%d %H:%M:%S %Z')}\n"
            result += f"**To:** {end_dt.strftime('%Y-%m-%d %H:%M:%S %Z')}\n"
            result += f"**Timezone:** {timezone_name}\n\n"
    
            result += f"**Total Duration:** {total_seconds:,.0f} seconds\n"
            result += f"**Breakdown:**\n"
            result += f"- Days: {days}\n"
            result += f"- Hours: {hours}\n"
            result += f"- Minutes: {minutes}\n"
            result += f"- Seconds: {seconds}\n\n"
    
            # Human-readable summary
            if days > 0:
                result += f"**Summary:** {days} days, {hours} hours, {minutes} minutes ({direction})\n"
            elif hours > 0:
                result += f"**Summary:** {hours} hours, {minutes} minutes ({direction})\n"
            elif minutes > 0:
                result += f"**Summary:** {minutes} minutes, {seconds} seconds ({direction})\n"
            else:
                result += f"**Summary:** {seconds} seconds ({direction})\n"
    
            return result
    
        except Exception as e:
            return f"āŒ Error calculating time difference: {str(e)}"
  • util_server.py:169-169 (registration)
    The @mcp.tool() decorator registers the calculate_time_difference function as an MCP tool with the name matching the function name.
    @mcp.tool()
  • Input schema defined by function parameters and docstring: start_datetime (str, required), end_datetime (str, optional default empty), timezone_name (str, default UTC). Output: formatted string with time difference details.
    async def calculate_time_difference(start_datetime: str, end_datetime: str = "", timezone_name: str = "UTC") -> str:
        """
        Calculate the time difference between two datetimes or from a start time to now.
    
        Args:
            start_datetime: Start datetime in ISO format (YYYY-MM-DD HH:MM:SS or YYYY-MM-DDTHH:MM:SS)
            end_datetime: End datetime in ISO format (optional - defaults to current time)
            timezone_name: Timezone for interpretation (default: UTC)
    
        Returns:
            Time difference with detailed breakdown
  • Documentation of the tool in the util_server_status tool's output listing available tools.
    status += "2. `calculate_time_difference` - Calculate time differences with detailed breakdown\n"
    status += "3. `download_meeting_data` - Download Read.AI meeting transcripts and summaries\n"
    status += "4. `util_server_status` - Check utility server status and configuration\n"
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses the tool's behavior by describing what it calculates and the return format ('Time difference with detailed breakdown'), but doesn't mention error handling, performance characteristics, or limitations like maximum date ranges.

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 perfectly structured with a clear purpose statement followed by well-organized Args and Returns sections. Every sentence earns its place by providing essential information without redundancy or fluff.

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 moderate complexity, 3 parameters with 0% schema coverage, and the presence of an output schema, the description is quite complete. It explains the tool's purpose, parameters, and return value. The main gap is the lack of behavioral details like error cases or limitations.

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

Parameters5/5

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

The description adds significant value beyond the 0% schema description coverage by explaining each parameter's purpose, format requirements ('ISO format'), and defaults. It clarifies that end_datetime is optional and defaults to current time, and that timezone_name defaults to UTC - information not present in the schema.

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

Purpose5/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 with specific verbs ('calculate the time difference') and resources ('between two datetimes or from a start time to now'). It distinguishes itself from sibling tools like 'get_current_datetime' by focusing on difference calculation rather than current time retrieval.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('between two datetimes or from a start time to now') and mentions the optional end_datetime defaulting to current time. However, it doesn't explicitly state when NOT to use it or mention alternatives among sibling tools.

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/danfmaia/util-mcp'

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