feat: add get_activities and get_activity_details tools
This commit is contained in:
30
server.py
30
server.py
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user