get_event_by_id
Retrieve detailed data for a specific event from Intervals.icu using the event ID. Optional arguments include athlete ID and API key for customized access.
Instructions
Get detailed information for a specific event from Intervals.icu
Args:
event_id: The Intervals.icu event ID
athlete_id: The Intervals.icu athlete ID (optional, will use ATHLETE_ID from .env if not provided)
api_key: The Intervals.icu API key (optional, will use API_KEY from .env if not provided)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_key | No | ||
| athlete_id | No | ||
| event_id | Yes |
Implementation Reference
- The core MCP tool handler for get_event_by_id. It retrieves event details from the Intervals.icu API endpoint /athlete/{athlete_id}/event/{event_id}, handles errors, and formats the output using format_event_details. The @mcp.tool() decorator registers it with the FastMCP server.@mcp.tool() async def get_event_by_id( event_id: str, athlete_id: str | None = None, api_key: str | None = None, ) -> str: """Get detailed information for a specific event from Intervals.icu Args: event_id: The Intervals.icu event ID athlete_id: The Intervals.icu athlete ID (optional, will use ATHLETE_ID from .env if not provided) api_key: The Intervals.icu API key (optional, will use API_KEY from .env if not provided) """ # Use provided athlete_id or fall back to global ATHLETE_ID athlete_id_to_use = athlete_id if athlete_id is not None else ATHLETE_ID if not athlete_id_to_use: return "Error: No athlete ID provided and no default ATHLETE_ID found in environment variables." # Call the Intervals.icu API result = await make_intervals_request( url=f"/athlete/{athlete_id_to_use}/event/{event_id}", api_key=api_key ) if isinstance(result, dict) and "error" in result: error_message = result.get("message", "Unknown error") return f"Error fetching event details: {error_message}" # Format the response if not result: return f"No details found for event {event_id}." if not isinstance(result, dict): return f"Invalid event format for event {event_id}." return format_event_details(result)
- Helper function that formats the raw event data dictionary into a human-readable string, including event details, workout information (if present), race details, and calendar association.def format_event_details(event: dict[str, Any]) -> str: """Format detailed event information into a readable string.""" event_details = f"""Event Details: ID: {event.get("id", "N/A")} Date: {event.get("date", "Unknown")} Name: {event.get("name", "Unnamed")} Description: {event.get("description", "No description")}""" # Check if it's a workout-based event if "workout" in event and event["workout"]: workout = event["workout"] event_details += f""" Workout Information: Workout ID: {workout.get("id", "N/A")} Sport: {workout.get("sport", "Unknown")} Duration: {workout.get("duration", 0)} seconds TSS: {workout.get("tss", "N/A")}""" # Include interval count if available if "intervals" in workout and isinstance(workout["intervals"], list): event_details += f""" Intervals: {len(workout["intervals"])}""" # Check if it's a race if event.get("race"): event_details += f""" Race Information: Priority: {event.get("priority", "N/A")} Result: {event.get("result", "N/A")}""" # Include calendar information if "calendar" in event: cal = event["calendar"] event_details += f""" Calendar: {cal.get("name", "N/A")}""" return event_details