Skip to main content
Glama

download-workout-fit

Download a workout from Garmin Connect as a FIT file by providing the workout ID. Optionally specify a directory to save the file.

Instructions

Download a workout as a FIT file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workoutIdYesThe workout ID
outputDirNoDirectory to save the FIT file./fit_files

Implementation Reference

  • The actual handler function for download-workout-fit tool. It calls getBytes on the Garmin API to fetch the FIT file as bytes, creates the output directory, writes the file, and returns a success message with the file path and byte count.
    async ({ workoutId, outputDir }) => {
      const client = getClient();
      const fitBytes = await client.getBytes(
        `workout-service/workout/FIT/${workoutId}`
      );
      mkdirSync(outputDir, { recursive: true });
      const outPath = join(outputDir, `workout_${workoutId}.fit`);
      writeFileSync(outPath, fitBytes);
      return textResult(
        `Downloaded workout FIT: ${outPath} (${fitBytes.length} bytes)`
      );
    }
  • Zod schema for download-workout-fit inputs: workoutId (required string) and outputDir (optional string defaulting to './fit_files').
    {
      workoutId: z.string().describe("The workout ID"),
      outputDir: z
        .string()
        .default("./fit_files")
        .describe("Directory to save the FIT file"),
    },
  • src/tools.ts:747-769 (registration)
    Registration of the 'download-workout-fit' tool on the MCP server using server.tool(), with name, description, schema, and handler.
    server.tool(
      "download-workout-fit",
      "Download a workout as a FIT file",
      {
        workoutId: z.string().describe("The workout ID"),
        outputDir: z
          .string()
          .default("./fit_files")
          .describe("Directory to save the FIT file"),
      },
      async ({ workoutId, outputDir }) => {
        const client = getClient();
        const fitBytes = await client.getBytes(
          `workout-service/workout/FIT/${workoutId}`
        );
        mkdirSync(outputDir, { recursive: true });
        const outPath = join(outputDir, `workout_${workoutId}.fit`);
        writeFileSync(outPath, fitBytes);
        return textResult(
          `Downloaded workout FIT: ${outPath} (${fitBytes.length} bytes)`
        );
      }
    );
  • The getClient() helper that ensures a Garmin session exists before returning the shared GarminClient instance.
    function getClient() {
      if (!sessionExists()) {
        throw new Error(
          "No Garmin session found. The user needs to run: npx garmin-connect-mcp login"
        );
      }
      return getSharedClient();
    }
  • The getBytes() method on GarminClient that fetches binary data via page.evaluate, encodes it as base64 to cross the Playwright boundary, and returns a Node.js Buffer.
    async getBytes(path: string): Promise<Buffer> {
      await this.init();
    
      const url = `/gc-api/${path}`;
      const csrfToken = this.csrfToken;
    
      const result = await this.page.evaluate(
        async ({ url, csrfToken }: { url: string; csrfToken: string }) => {
          const resp = await fetch(url, {
            headers: {
              "connect-csrf-token": csrfToken,
              Accept: "*/*",
            },
          });
          if (!resp.ok) {
            return { status: resp.status, error: await resp.text(), data: null };
          }
          const buf = await resp.arrayBuffer();
          // Convert to base64 to pass through page.evaluate boundary
          const bytes = new Uint8Array(buf);
          let binary = "";
          for (let i = 0; i < bytes.length; i++) {
            binary += String.fromCharCode(bytes[i]);
          }
          return { status: resp.status, error: null, data: btoa(binary) };
        },
        { url, csrfToken }
      );
    
      if (result.status !== 200 || !result.data) {
        throw new Error(
          `Garmin API ${result.status}: ${path} — ${result.error ?? ""}`
        );
      }
      return Buffer.from(result.data, "base64");
    }
Behavior2/5

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

No annotations are provided, and the description does not disclose behavioral traits such as file system writes, network calls, or authentication requirements. The agent only knows it 'downloads' but not the implications.

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 a single sentence with no waste, but it could benefit from additional context about the operation.

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

Completeness3/5

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

Given the lack of output schema and annotations, the description provides only the basic purpose. It does not explain the return value or behavior when outputDir is not specified, leaving gaps for the 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?

Both parameters are described in the input schema (workoutId and outputDir). The description confirms the output format (FIT file) but does not add new information beyond schema descriptions.

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 action 'Download' and the resource 'workout' in FIT format. However, it does not differentiate from the sibling tool 'download-fit', which may have overlapping functionality.

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 no guidance on when to use this tool versus alternatives like 'download-fit' or 'get-workout'. There is no mention of prerequisites or typical scenarios.

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/etweisberg/garmin-connect-mcp'

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