Skip to main content
Glama

download-fit

Download the original FIT file for a Garmin Connect activity. Returns the saved file path.

Instructions

Download the original FIT file for an activity. Returns the file path.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
activityIdYesThe activity ID
outputDirNoDirectory to save the FIT file./fit_files

Implementation Reference

  • The main handler for the 'download-fit' tool. Downloads the FIT file from Garmin Connect API, extracts it from a zip archive, and saves it to disk.
    async ({ activityId, outputDir }) => {
      const client = getClient();
      const zipBytes = await client.getBytes(
        `download-service/files/activity/${activityId}`
      );
    
      mkdirSync(outputDir, { recursive: true });
    
      // The response is a zip containing the .fit file
      // Use a minimal zip extraction (ZIP local file header parsing)
      const fitFile = extractFitFromZip(zipBytes, activityId);
    
      if (fitFile) {
        const outPath = join(outputDir, fitFile.name);
        writeFileSync(outPath, fitFile.data);
        return textResult(
          `Downloaded FIT file: ${outPath} (${fitFile.data.length} bytes)`
        );
      }
    
      // Fallback: save the raw zip
      const zipPath = join(outputDir, `${activityId}.zip`);
      writeFileSync(zipPath, zipBytes);
      return textResult(
        `No .fit file found in archive. Saved raw zip: ${zipPath}`
      );
    }
  • Input schema for download-fit: requires activityId (string) and optional outputDir (string, default './fit_files').
    {
      activityId: z.string().describe("The activity ID"),
      outputDir: z
        .string()
        .default("./fit_files")
        .describe("Directory to save the FIT file"),
    },
  • src/tools.ts:277-314 (registration)
    Registration of the 'download-fit' tool on the MCP server using server.tool().
    server.tool(
      "download-fit",
      "Download the original FIT file for an activity. Returns the file path.",
      {
        activityId: z.string().describe("The activity ID"),
        outputDir: z
          .string()
          .default("./fit_files")
          .describe("Directory to save the FIT file"),
      },
      async ({ activityId, outputDir }) => {
        const client = getClient();
        const zipBytes = await client.getBytes(
          `download-service/files/activity/${activityId}`
        );
    
        mkdirSync(outputDir, { recursive: true });
    
        // The response is a zip containing the .fit file
        // Use a minimal zip extraction (ZIP local file header parsing)
        const fitFile = extractFitFromZip(zipBytes, activityId);
    
        if (fitFile) {
          const outPath = join(outputDir, fitFile.name);
          writeFileSync(outPath, fitFile.data);
          return textResult(
            `Downloaded FIT file: ${outPath} (${fitFile.data.length} bytes)`
          );
        }
    
        // Fallback: save the raw zip
        const zipPath = join(outputDir, `${activityId}.zip`);
        writeFileSync(zipPath, zipBytes);
        return textResult(
          `No .fit file found in archive. Saved raw zip: ${zipPath}`
        );
      }
    );
  • Helper function extractFitFromZip() that parses a ZIP archive's central directory to find and extract the .fit file, supporting both stored (method 0) and deflated (method 8) compression.
    function extractFitFromZip(
      buf: Buffer,
      activityId: string
    ): { name: string; data: Buffer } | null {
      // Find End of Central Directory (EOCD): PK\x05\x06
      let eocdOffset = buf.length - 22;
      while (eocdOffset >= 0) {
        if (
          buf[eocdOffset] === 0x50 &&
          buf[eocdOffset + 1] === 0x4b &&
          buf[eocdOffset + 2] === 0x05 &&
          buf[eocdOffset + 3] === 0x06
        )
          break;
        eocdOffset--;
      }
      if (eocdOffset < 0) return null;
    
      const cdOffset = buf.readUInt32LE(eocdOffset + 16);
      const cdEntries = buf.readUInt16LE(eocdOffset + 10);
    
      // Walk central directory entries: PK\x01\x02
      let pos = cdOffset;
      for (let i = 0; i < cdEntries; i++) {
        if (
          buf[pos] !== 0x50 ||
          buf[pos + 1] !== 0x4b ||
          buf[pos + 2] !== 0x01 ||
          buf[pos + 3] !== 0x02
        )
          break;
    
        const method = buf.readUInt16LE(pos + 10);
        const compressedSize = buf.readUInt32LE(pos + 20);
        const uncompressedSize = buf.readUInt32LE(pos + 24);
        const nameLength = buf.readUInt16LE(pos + 28);
        const extraLength = buf.readUInt16LE(pos + 30);
        const commentLength = buf.readUInt16LE(pos + 32);
        const localHeaderOffset = buf.readUInt32LE(pos + 42);
        const name = buf.toString("utf-8", pos + 46, pos + 46 + nameLength);
    
        if (name.endsWith(".fit")) {
          // Read local header to find data start
          const localNameLen = buf.readUInt16LE(localHeaderOffset + 26);
          const localExtraLen = buf.readUInt16LE(localHeaderOffset + 28);
          const dataStart = localHeaderOffset + 30 + localNameLen + localExtraLen;
    
          if (method === 0) {
            const data = buf.subarray(dataStart, dataStart + uncompressedSize);
            return { name: `${activityId}.fit`, data: Buffer.from(data) };
          }
          if (method === 8) {
            const compressed = buf.subarray(dataStart, dataStart + compressedSize);
            const data = inflateRawSync(compressed);
            return { name: `${activityId}.fit`, data };
          }
        }
    
        pos += 46 + nameLength + extraLength + commentLength;
      }
      return null;
    }
Behavior2/5

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

No annotations exist, and the description only mentions 'download' and 'returns the file path.' It omits important behavioral details: the tool creates a file on disk (side effect), any permission or authentication requirements, potential overwrite behavior, or error handling. For a download operation, more transparency is needed.

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

Conciseness5/5

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

The description is two sentences, front-loaded with the key action, and contains no unnecessary words. Every sentence serves a purpose, making it highly concise.

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 no output schema, no annotations, and a simple but potentially error-prone operation (file download), the description lacks completeness. It does not cover return value format, file existence handling, error cases (e.g., invalid activityId), or the lifecycle of the saved file. The agent needs more context to use it safely.

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 coverage is 100%, so baseline is 3. The description adds minimal value beyond the schema: it ties the parameters to downloading a FIT file, but does not elaborate on format constraints, validation, or how the outputDir path is used. The 'activityId' and 'outputDir' meaning is clear from the schema already.

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 tool downloads the original FIT file for an activity and returns the file path. This specifies the exact action (download), resource (original FIT file for an activity), and output (file path), distinguishing it from sibling tools like 'download-workout-fit'.

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?

No guidance is provided on when to use this tool versus alternatives, such as 'download-workout-fit' for workouts. The agent receives no context about prerequisites, appropriate scenarios, or exclusions.

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