Skip to content

ecs-mcp-server: calculate_time_window crashes when start_time/end_time are passed as strings via MCP #2858

@project0

Description

@project0

Describe the bug

When invoking the ecs_troubleshooting_tool via MCP with actions that accept start_time/end_time parameters (fetch_task_failures, fetch_service_events, fetch_task_logs), the call crashes with AttributeError: 'str' object has no attribute 'tzinfo'.

MCP tool parameters are JSON-encoded, so start_time and end_time always arrive as strings (e.g. "2026-04-03T10:00:00Z"). The transformers in ecs_troubleshooting.py pass these strings through to calculate_time_window(), which expects datetime objects.

Expected Behavior

String-valued start_time/end_time parameters should be parsed into datetime objects before being passed to calculate_time_window(), and the troubleshooting action should execute successfully.

Current Behavior

The call fails immediately with:

2026-04-03 11:58:36,184 - awslabs.ecs_mcp_server.api.troubleshooting_tools.fetch_task_failures - ERROR - Error in fetch_task_failures: 'str' object has no attribute 'tzinfo'
Traceback (most recent call last):
  File ".../awslabs/ecs_mcp_server/api/troubleshooting_tools/fetch_task_failures.py", line 218, in fetch_task_failures
    actual_start_time, actual_end_time = calculate_time_window(
        time_window, start_time, end_time
    )
  File ".../awslabs/ecs_mcp_server/utils/time_utils.py", line 54, in calculate_time_window
    end_time if end_time.tzinfo else end_time.replace(tzinfo=datetime.timezone.utc)
AttributeError: 'str' object has no attribute 'tzinfo'

Reproduction Steps

Call the ecs_troubleshooting_tool MCP tool with a string-valued end_time or start_time:

await ecs_troubleshooting_tool(
    action="fetch_task_failures",
    parameters={
        "ecs_cluster_name": "my-cluster",
        "time_window": 3600,
        "end_time": "2026-04-03T12:00:00Z",  # string, as MCP delivers it
    },
)

Possible Solution

Parse string inputs to datetime at the boundary in utils/time_utils.py:

from datetime import datetime, timezone

def _ensure_datetime(value):
    if value is None:
        return None
    if isinstance(value, str):
        return datetime.fromisoformat(value.replace("Z", "+00:00"))
    return value

def calculate_time_window(time_window=3600, start_time=None, end_time=None):
    start_time = _ensure_datetime(start_time)
    end_time = _ensure_datetime(end_time)
    # ... rest unchanged

Alternatively, the transformers in ecs_troubleshooting.py (lines 99-104, 130-134, 164-171) could parse the strings before forwarding.

Additional Information/Context

This affects any MCP client that invokes these actions with explicit time parameters. Since MCP uses JSON serialization, datetime values will always arrive as strings — there is no datetime type in JSON.

OS

Linux

Server

ecs-mcp-server

Server Version

No response

Region experiencing the issue

eu-central-1

Other information

The same bug pattern likely exists in fetch_service_events and fetch_task_logs since they use the same transformer pattern and call calculate_time_window the same way.

Service quota

  • I have reviewed the service quotas for this construct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageThis needs to be handled, it is the first automatically assigned label to issues.

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions