Skip to main content
Glama

apple_health_trends

Analyze daily health trends from Apple Health data to track metrics like steps, heart rate, sleep, and weight over time.

Instructions

Get daily health metrics for a date range (steps, HR, HRV, sleep, weight)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daysNoNumber of days to look back (default 7)

Implementation Reference

  • The 'apple_health_trends' tool is registered and implemented in src/mcp.ts. It calculates daily health metrics (steps, active energy, resting heart rate, HRV, sleep, and weight) over a specified number of days.
    server.registerTool("apple_health_trends", {
      title: "Multi-day Trends",
      description: "Get daily health metrics for a date range (steps, HR, HRV, sleep, weight)",
      inputSchema: z.object({
        days: z.number().optional().describe("Number of days to look back (default 7)"),
      }),
    }, async ({ days }) => {
      const n = days ?? 7;
      const results: Array<Record<string, unknown>> = [];
    
      for (let i = n - 1; i >= 0; i--) {
        const dt = new Date();
        dt.setDate(dt.getDate() - i);
        const d = dt.toISOString().split("T")[0];
        const metrics = parseMetrics(d);
        if (metrics) {
          const rhr = avg(metrics.resting_hr);
          const hrv = avg(metrics.hrv);
          results.push({
            date: d,
            steps: Math.round(metrics.steps),
            active_energy: Math.round(metrics.active_energy),
            resting_hr: rhr ? Math.round(rhr) : null,
            hrv: hrv ? Math.round(hrv) : null,
            sleep_total_hrs: +metrics.sleep_total.toFixed(1),
            weight: avg(metrics.weight),
          });
        }
      }
    
      return text(results);
    });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daveremy/apple-health-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server