get-activity-hr-zones
Retrieve the heart rate time-in-zone breakdown for any Garmin activity. Analyze time spent in each heart rate zone using your activity ID.
Instructions
Get heart rate time-in-zone breakdown for an activity
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| activityId | Yes | The activity ID |
Implementation Reference
- src/tools.ts:211-223 (registration)The tool 'get-activity-hr-zones' is registered via `server.tool()` with a Zod schema expecting 'activityId' (string). The handler calls `client.get('activity-service/activity/${activityId}/hrTimeInZones')` and returns the JSON result.
server.tool( "get-activity-hr-zones", "Get heart rate time-in-zone breakdown for an activity", { activityId: z.string().describe("The activity ID"), }, async ({ activityId }) => { const client = getClient(); const data = await client.get( `activity-service/activity/${activityId}/hrTimeInZones` ); return jsonResult(data); } - src/tools.ts:217-223 (handler)The handler function for 'get-activity-hr-zones': receives { activityId }, calls the Garmin API endpoint 'activity-service/activity/${activityId}/hrTimeInZones' via the shared client, and returns the data as JSON.
async ({ activityId }) => { const client = getClient(); const data = await client.get( `activity-service/activity/${activityId}/hrTimeInZones` ); return jsonResult(data); } - src/tools.ts:214-216 (schema)Input schema: { activityId: z.string() } - a single required string parameter describing the activity ID.
{ activityId: z.string().describe("The activity ID"), }, - src/tools.ts:14-18 (helper)The jsonResult helper function used by the handler to wrap API response data into MCP-compatible content format.
function jsonResult(data: unknown) { return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; } - src/tools.ts:32-39 (helper)The getClient helper function that checks for an existing Garmin session and returns the shared HTTP client used in the handler.
function getClient() { if (!sessionExists()) { throw new Error( "No Garmin session found. The user needs to run: npx garmin-connect-mcp login" ); } return getSharedClient(); }