Skip to main content
Glama

create_garmin_workout

Convert natural language workout descriptions into structured Garmin Connect workouts for running, cycling, or swimming with automatic device sync.

Instructions

Create a workout in Garmin Connect from structured workout data. Claude should parse the natural language description and pass structured workout steps.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the workout
sportYesSport type (defaults to running)
stepsYesArray of workout steps

Implementation Reference

  • Core handler function that executes the Garmin workout creation: parses workout data, converts to Garmin API payload, makes authenticated POST request to Garmin Connect API, and returns success/error with workout URL.
    export async function createGarminWorkout(
      description: string,
      authToken: string,
      cookies: string,
      customName?: string,
      sport: string = "running",
      llmParser?: (
        description: string,
        sport: string,
        customName?: string
      ) => Promise<WorkoutData>
    ): Promise<WorkoutResult> {
      try {
        // Parse the description into workout data using LLM
        const workoutData = llmParser
          ? await llmParser(description, sport, customName)
          : await parseWorkoutDescriptionWithLLM(description, sport, customName);
    
        // Convert to Garmin API format
        const payload = convertToGarminPayload(workoutData);
    
        console.error(`šŸƒ Creating workout: ${workoutData.name}`);
        console.error(`šŸ“Š Workout has ${workoutData.steps.length} steps:`);
        workoutData.steps.forEach((step, i) => {
          console.error(
            `  ${i + 1}. ${step.name}: ${step.duration} at ${step.target} (${
              step.intensity
            })`
          );
        });
        console.error(
          `šŸ“¤ Garmin payload has ${payload.workoutSegments[0].workoutSteps.length} steps`
        );
    
        // Write debug info to file for inspection
        try {
          const fs = require("fs");
          const debugInfo = {
            workoutName: workoutData.name,
            inputSteps: workoutData.steps,
            outputSteps: payload.workoutSegments[0].workoutSteps,
            fullPayload: payload,
          };
          fs.writeFileSync(
            "/tmp/garmin-debug.json",
            JSON.stringify(debugInfo, null, 2)
          );
          console.error(`šŸ“ Debug info written to /tmp/garmin-debug.json`);
        } catch (e) {
          console.error("Failed to write debug file:", e);
        }
    
        // Make API call to Garmin
        const response = await fetch(
          "https://connect.garmin.com/workout-service/workout",
          {
            method: "POST",
            headers: {
              accept: "application/json, text/plain, */*",
              "accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
              authorization: authToken,
              "content-type": "application/json;charset=UTF-8",
              cookie: cookies,
              "di-backend": "connectapi.garmin.com",
              nk: "NT",
              origin: "https://connect.garmin.com",
              referer: `https://connect.garmin.com/modern/workout/create/${sport}`,
              "user-agent":
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
              "x-app-ver": "5.14.1.2",
              "x-lang": "en-US",
            },
            body: JSON.stringify(payload),
          }
        );
    
        if (response.ok) {
          const result = (await response.json()) as GarminApiResponse;
          const workoutId = result.workoutId.toString();
          return {
            success: true,
            workoutId,
            name: result.workoutName,
            url: `https://connect.garmin.com/modern/workout/${workoutId}`,
          };
        } else {
          const errorText = await response.text();
          console.error("API Error:", response.status, errorText);
    
          if (response.status === 401) {
            return {
              success: false,
              error:
                "Authentication expired. Please re-authenticate with Garmin Connect.",
            };
          }
    
          return {
            success: false,
            error: `API error: ${response.status} ${response.statusText}`,
          };
        }
      } catch (error) {
        console.error("Workout creation error:", error);
        return {
          success: false,
          error: error instanceof Error ? error.message : String(error),
        };
      }
    }
  • MCP server request handler for the 'create_garmin_workout' tool call: handles authentication check, constructs workout data from tool arguments, invokes the core createGarminWorkout function, and formats the MCP response.
    case "create_garmin_workout": {
      const { name: workoutName, sport = "running", steps } = args as {
        name: string;
        sport?: string;
        steps: WorkoutStep[];
      };
    
      try {
        // Check auth first
        const authData = await garminAuth.getValidAuth();
        if (!authData) {
          return {
            content: [
              {
                type: "text",
                text: "āŒ Authentication required. Please run the 'authenticate_garmin' tool to authenticate with Garmin Connect.",
              },
            ],
          };
        }
    
        // Create workout data from structured input
        const workoutData: WorkoutData = {
          name: workoutName,
          sport: sport as 'running' | 'cycling' | 'swimming',
          steps
        };
    
        // Create LLM parser that just returns the structured data
        const llmParser = async () => workoutData;
    
        // Create workout with structured data
        const result = await createGarminWorkout(
          workoutName, // description not needed anymore
          authData.authToken,
          authData.cookies,
          workoutName,
          sport,
          llmParser
        );
    
        if (result.success) {
          return {
            content: [
              {
                type: "text",
                text: `āœ… Workout created successfully!\n\n**${result.name}** (ID: ${result.workoutId})\n\nšŸ”— **View in Garmin Connect:** ${result.url}\n\nThe workout is now available in your Garmin Connect account and ready to sync to your device.`,
              },
            ],
          };
        } else {
          return {
            content: [
              {
                type: "text",
                text: `āŒ Failed to create workout: ${result.error}`,
              },
            ],
          };
        }
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `āŒ Error creating workout: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    }
  • JSON schema defining the input parameters for the 'create_garmin_workout' tool: workout name, sport, and array of steps with name, duration, target, and intensity.
    inputSchema: {
      type: "object",
      properties: {
        name: {
          type: "string",
          description: "Name of the workout",
        },
        sport: {
          type: "string",
          enum: ["running", "cycling", "swimming"],
          description: "Sport type (defaults to running)",
        },
        steps: {
          type: "array",
          description: "Array of workout steps",
          items: {
            type: "object",
            properties: {
              name: {
                type: "string",
                description: "Step name (e.g., 'Warm-up', 'Sprint 1', 'Recovery 1')",
              },
              duration: {
                type: "string", 
                description: "Duration in MM:SS format (e.g., '10:00') or distance (e.g., '1.5 km')",
              },
              target: {
                type: "string",
                description: "Target zone or intensity. Use 'Zone 1' for recovery/easy, 'Zone 2' for aerobic/base, 'Zone 3' for tempo, 'Zone 4' for threshold, 'Zone 5' for VO2 max/all-out efforts. IMPORTANT: Default warmup and cooldown steps to 'Zone 2' unless user specifically requests otherwise. Use 'Open' only when no specific target is mentioned.",
              },
              intensity: {
                type: "string",
                enum: ["warmup", "active", "rest", "cooldown"],
                description: "Step intensity type",
              },
            },
            required: ["name", "duration", "target", "intensity"],
          },
        },
      },
      required: ["name", "sport", "steps"],
    },
  • Registration of the 'create_garmin_workout' tool in the MCP server's listTools response, including name, description, and input schema reference.
      name: "create_garmin_workout",
      description: "Create a workout in Garmin Connect from structured workout data. Claude should parse the natural language description and pass structured workout steps.",
      inputSchema: {
        type: "object",
        properties: {
          name: {
            type: "string",
            description: "Name of the workout",
          },
          sport: {
            type: "string",
            enum: ["running", "cycling", "swimming"],
            description: "Sport type (defaults to running)",
          },
          steps: {
            type: "array",
            description: "Array of workout steps",
            items: {
              type: "object",
              properties: {
                name: {
                  type: "string",
                  description: "Step name (e.g., 'Warm-up', 'Sprint 1', 'Recovery 1')",
                },
                duration: {
                  type: "string", 
                  description: "Duration in MM:SS format (e.g., '10:00') or distance (e.g., '1.5 km')",
                },
                target: {
                  type: "string",
                  description: "Target zone or intensity. Use 'Zone 1' for recovery/easy, 'Zone 2' for aerobic/base, 'Zone 3' for tempo, 'Zone 4' for threshold, 'Zone 5' for VO2 max/all-out efforts. IMPORTANT: Default warmup and cooldown steps to 'Zone 2' unless user specifically requests otherwise. Use 'Open' only when no specific target is mentioned.",
                },
                intensity: {
                  type: "string",
                  enum: ["warmup", "active", "rest", "cooldown"],
                  description: "Step intensity type",
                },
              },
              required: ["name", "duration", "target", "intensity"],
            },
          },
        },
        required: ["name", "sport", "steps"],
      },
    },
  • Helper function that converts the parsed workout data into the exact JSON payload format required by Garmin Connect's workout creation API.
    function convertToGarminPayload(workoutData: WorkoutData) {
      // Sport type mapping
      const sportMapping: {
        [key: string]: { id: number; key: string; order: number };
      } = {
        running: { id: 1, key: "running", order: 1 },
        cycling: { id: 2, key: "cycling", order: 2 },
        swimming: { id: 5, key: "swimming", order: 5 },
      };
    
      const sport = sportMapping[workoutData.sport] || sportMapping["running"];
    
      // Convert workout steps
      const workoutSteps = workoutData.steps.map((step, index) => {
        return convertWorkoutStep(step, index + 1);
      });
    
      return {
        sportType: {
          sportTypeId: sport.id,
          sportTypeKey: sport.key,
          displayOrder: sport.order,
        },
        subSportType: null,
        workoutName: workoutData.name,
        estimatedDistanceUnit: { unitKey: null },
        workoutSegments: [
          {
            segmentOrder: 1,
            sportType: {
              sportTypeId: sport.id,
              sportTypeKey: sport.key,
              displayOrder: sport.order,
            },
            workoutSteps,
          },
        ],
        avgTrainingSpeed: 3.0727914832080057,
        estimatedDurationInSecs: 0,
        estimatedDistanceInMeters: 0,
        estimateType: null,
        isWheelchair: false,
      };
    }
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. While it mentions the creation action, it doesn't disclose critical behavioral traits such as authentication requirements (implied by sibling tools but not stated), potential side effects (e.g., whether this persists data or requires confirmation), error handling, or rate limits. The description is minimal and lacks necessary operational context.

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 appropriately sized with two sentences that are front-loaded with the main purpose. Every sentence earns its place by stating the tool's function and its role in the workflow, though it could be slightly more structured for clarity.

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 complexity of a creation tool with no annotations and no output schema, the description is incomplete. It lacks details on authentication needs (implied by siblings but not stated), behavioral traits, error responses, or what happens post-creation. For a mutation tool, this leaves significant gaps in understanding how to use it effectively.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description doesn't add any additional meaning beyond what's in the schema (e.g., it doesn't explain parameter interactions or provide examples not in the schema). Baseline 3 is appropriate as the schema does the heavy lifting, but no extra value is added.

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

Purpose5/5

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

The description clearly states the specific action ('Create a workout in Garmin Connect') and resource ('from structured workout data'), distinguishing it from sibling tools like authenticate_garmin and check_garmin_auth. It explicitly mentions the tool's role in the workflow: Claude should parse natural language and pass structured data.

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

Usage Guidelines3/5

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

The description implies usage by stating 'Claude should parse the natural language description and pass structured workout steps,' suggesting this tool is used after natural language processing. However, it doesn't explicitly state when to use this tool versus alternatives or provide exclusions, leaving some ambiguity about its specific context in relation to sibling tools.

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/charlesfrisbee/garmin-workouts-mcp'

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