get_activities
Retrieve athletic activity data from intervals.icu with date range and sport type filters to analyze training performance and plan workouts.
Instructions
List activities with optional filters.
Args: oldest: Start date in YYYY-MM-DD format (inclusive). newest: End date in YYYY-MM-DD format (inclusive). sport_type: Filter by sport type (e.g. 'Ride', 'Run', 'Swim').
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| oldest | No | ||
| newest | No | ||
| sport_type | No |
Implementation Reference
- main.py:31-52 (handler)The main implementation of the 'get_activities' tool. It lists activities with optional date range filters (oldest/newest) and sport type filtering. Uses the _get helper to make HTTP requests to the intervals.icu API and filters results by sport_type client-side if specified.
@mcp.tool() def get_activities( oldest: str | None = None, newest: str | None = None, sport_type: str | None = None, ) -> list: """List activities with optional filters. Args: oldest: Start date in YYYY-MM-DD format (inclusive). newest: End date in YYYY-MM-DD format (inclusive). sport_type: Filter by sport type (e.g. 'Ride', 'Run', 'Swim'). """ params: dict[str, Any] = {} if oldest: params["oldest"] = oldest if newest: params["newest"] = newest activities = _get(f"/athlete/{ATHLETE_ID}/activities", params) if sport_type: activities = [a for a in activities if a.get("type") == sport_type] return activities - main.py:25-31 (registration)The @mcp.tool() decorator that registers 'get_activities' as an MCP tool. FastMCP uses Python type hints for input validation and the docstring for parameter descriptions.
@mcp.tool() def get_athlete() -> dict: """Get athlete profile including sport zones and thresholds.""" return _get(f"/athlete/{ATHLETE_ID}") @mcp.tool() - main.py:18-22 (helper)Helper function '_get' used by get_activities to make authenticated HTTP GET requests to the intervals.icu API. Returns JSON response.
def _get(path: str, params: dict[str, Any] | None = None) -> Any: with _client() as client: r = client.get(path, params=params) r.raise_for_status() return r.json() - main.py:14-15 (helper)Helper function '_client' that creates an httpx Client with API authentication and base URL configured for intervals.icu API calls.
def _client() -> httpx.Client: return httpx.Client(auth=("API_KEY", API_KEY), base_url=BASE_URL)