Skip to main content
Glama
willc121

Garmin Health MCP Server

by willc121

get_sleep

Retrieve sleep statistics like average duration and nights tracked from Garmin health data. Filter results by date range to analyze sleep patterns over time.

Instructions

Get sleep statistics including average duration and total nights tracked. Optionally filter by date range.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateNoStart date (YYYY-MM-DD)
end_dateNoEnd date (YYYY-MM-DD, exclusive recommended)

Implementation Reference

  • The handler function implementing the get_sleep tool logic. It queries sleep data from Supabase, handles overall summary or date-range filtered stats, computing total nights, average, min/max sleep duration in hours.
    async function getSleep(startDate?: string, endDate?: string) {
      console.error("[getSleep] called with", { startDate, endDate });
    
      // If no date range, return the summary
      if (!startDate && !endDate) {
        const { data, error } = await supabase
          .from("sleep_summary")
          .select("*")
          .single();
    
        if (error) throw error;
    
        return {
          total_nights: data?.nights || 0,
          average_duration_hours: data?.avg_duration_hours
            ? Math.round(data.avg_duration_hours * 10) / 10
            : null,
          date_range: {
            first_night: data?.first_night || null,
            last_night: data?.last_night || null,
          },
        };
      }
    
      let query = supabase
        .from("sleep")
        .select("calendar_date, duration_hours")
        .not("duration_hours", "is", null)
        .order("calendar_date", { ascending: true });
    
      if (startDate) query = query.gte("calendar_date", startDate);
      // End date is exclusive (recommended)
      if (endDate) query = query.lt("calendar_date", endDate);
    
      const { data, error } = await query;
      if (error) throw error;
    
      const durations = (data || [])
        .map((s) => s.duration_hours)
        .filter((d): d is number => typeof d === "number" && d > 0 && d < 24);
    
      const avgDuration =
        durations.length > 0
          ? Math.round(
              (durations.reduce((a, b) => a + b, 0) / durations.length) * 10
            ) / 10
          : null;
    
      return {
        total_nights: durations.length,
        average_duration_hours: avgDuration,
        min_hours: durations.length
          ? Math.round(Math.min(...durations) * 10) / 10
          : null,
        max_hours: durations.length
          ? Math.round(Math.max(...durations) * 10) / 10
          : null,
        date_range: {
          start: startDate || data?.[0]?.calendar_date || null,
          end: endDate || data?.[data.length - 1]?.calendar_date || null,
        },
      };
    }
  • The input schema and metadata for the get_sleep tool as registered in the ListTools handler.
    {
      name: "get_sleep",
      description:
        "Get sleep statistics including average duration and total nights tracked. Optionally filter by date range.",
      inputSchema: {
        type: "object",
        properties: {
          start_date: { type: "string", description: "Start date (YYYY-MM-DD)" },
          end_date: { type: "string", description: "End date (YYYY-MM-DD, exclusive recommended)" },
        },
      },
    },
  • src/index.ts:414-416 (registration)
    Registration in the CallToolRequestSchema handler switch statement, routing calls to the getSleep function.
    case "get_sleep":
      result = await getSleep(a.start_date, a.end_date);
      break;
  • src/index.ts:318-393 (registration)
    The ListToolsRequestSchema handler where get_sleep is listed among available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "get_health_summary",
            description:
              "Get an overview of all health data including VO2 max, activities, sleep, and race predictions",
            inputSchema: { type: "object", properties: {} },
          },
          {
            name: "get_vo2max",
            description:
              "Get VO2 max history and trends. VO2 max measures cardiovascular fitness in ml/kg/min.",
            inputSchema: {
              type: "object",
              properties: {
                start_date: { type: "string", description: "Start date (YYYY-MM-DD)" },
                end_date: { type: "string", description: "End date (YYYY-MM-DD, exclusive recommended)" },
                sport: { type: "string", description: "Filter by sport (e.g., 'running', 'cycling')" },
              },
            },
          },
          {
            name: "get_activities",
            description:
              "Get activity breakdown by type, including counts, distances, and durations",
            inputSchema: {
              type: "object",
              properties: {
                start_date: { type: "string", description: "Start date (YYYY-MM-DD)" },
                end_date: { type: "string", description: "End date (YYYY-MM-DD)" },
                activity_type: {
                  type: "string",
                  description: "Filter by activity type (e.g., 'running')",
                },
              },
            },
          },
          {
            name: "get_sleep",
            description:
              "Get sleep statistics including average duration and total nights tracked. Optionally filter by date range.",
            inputSchema: {
              type: "object",
              properties: {
                start_date: { type: "string", description: "Start date (YYYY-MM-DD)" },
                end_date: { type: "string", description: "End date (YYYY-MM-DD, exclusive recommended)" },
              },
            },
          },
          {
            name: "get_race_predictions",
            description:
              "Get predicted race times for 5K, 10K, half marathon, and marathon based on current fitness",
            inputSchema: { type: "object", properties: {} },
          },
          {
            name: "get_heart_rate_zones",
            description:
              "Get personalized heart rate training zones based on max HR and lactate threshold",
            inputSchema: { type: "object", properties: {} },
          },
          {
            name: "get_training_load",
            description:
              "Get training load data including acute/chronic workload ratio to assess overtraining risk",
            inputSchema: {
              type: "object",
              properties: {
                days: { type: "number", description: "Number of days (default: 30)" },
              },
            },
          },
        ],
      };
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'Get sleep statistics' which implies a read-only operation, but doesn't address permissions, rate limits, error conditions, or response format. For a tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, stating the core purpose in the first clause. The second sentence adds optional filtering information. Both sentences earn their place, though it could be slightly more structured (e.g., by explicitly noting parameters are optional).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what 'sleep statistics' includes beyond 'average duration and total nights tracked,' nor does it cover behavioral aspects like permissions or error handling. For a tool with no structured metadata, this leaves significant gaps for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds minimal value beyond the input schema, which has 100% coverage. It mentions 'Optionally filter by date range,' aligning with the two parameters (start_date, end_date) but doesn't provide additional context like default behavior or date format details. With high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get sleep statistics including average duration and total nights tracked.' It specifies the verb ('Get') and resource ('sleep statistics') with concrete metrics. However, it doesn't explicitly differentiate from sibling tools like 'get_health_summary' which might also include sleep data, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal guidance: 'Optionally filter by date range.' It doesn't specify when to use this tool versus alternatives like 'get_health_summary' or other sibling tools, nor does it mention prerequisites or exclusions. This leaves the agent with little context for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/willc121/garmin-mcp-server'

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