feat: add get_activities and get_activity_details tools

This commit is contained in:
Christophe Vila
2026-05-17 19:46:45 +02:00
parent 6b38f17e9b
commit 3630aa2c42
2 changed files with 91 additions and 0 deletions

View File

@@ -100,6 +100,36 @@ def complete_mfa(code: str) -> str:
return "Timed out waiting for authentication to complete."
@mcp.tool()
def get_activities(start_date: str = "", end_date: str = "", limit: int = 20) -> str:
"""List Garmin activities between two dates (YYYY-MM-DD). Defaults to today."""
if err := _check_auth():
return err
start = start_date or _today()
end = end_date or _today()
try:
result = _client.get_activities_by_date(start, end)
return json.dumps(result[:limit], indent=2)
except GarminConnectAuthenticationError:
return "Authentication error. Call authenticate() again."
except Exception as exc:
return f"Error fetching activities: {exc}"
@mcp.tool()
def get_activity_details(activity_id: str) -> str:
"""Get full details for a single activity by its ID (splits, laps, metrics)."""
if err := _check_auth():
return err
try:
result = _client.get_activity_details(activity_id)
return json.dumps(result, indent=2)
except GarminConnectAuthenticationError:
return "Authentication error. Call authenticate() again."
except Exception as exc:
return f"Error fetching activity details: {exc}"
if __name__ == "__main__":
_startup_login()
mcp.run()