Skip to main content
Glama

download_file

Download file content from an Anaplan model. Text files are returned inline; set saveToDownloads=true for binary files to preserve exact bytes.

Instructions

Download file content from a model. Text files are returned inline; for binary files, set saveToDownloads=true to preserve the exact bytes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workspaceIdYesAnaplan workspace ID or name
modelIdYesAnaplan model ID or name
fileIdYesAnaplan file ID or name (from show_files)
saveToDownloadsNoIf true, save the file to ~/Downloads without decoding
fileNameNoOptional local file name when saveToDownloads is true

Implementation Reference

  • Registration of the 'download_file' tool via server.tool() with its schema and handler callback.
    server.tool("download_file", "Download file content from a model. Text files are returned inline; for binary files, set saveToDownloads=true to preserve the exact bytes.", {
      workspaceId: z.string().describe("Anaplan workspace ID or name"),
      modelId: z.string().describe("Anaplan model ID or name"),
      fileId: z.string().describe("Anaplan file ID or name (from show_files)"),
      saveToDownloads: z.boolean().optional().describe("If true, save the file to ~/Downloads without decoding"),
      fileName: z.string().optional().describe("Optional local file name when saveToDownloads is true"),
    }, async ({ workspaceId, modelId, fileId, saveToDownloads, fileName }) => {
  • Input schema for download_file: workspaceId, modelId, fileId (required), saveToDownloads and fileName (optional).
    server.tool("download_file", "Download file content from a model. Text files are returned inline; for binary files, set saveToDownloads=true to preserve the exact bytes.", {
      workspaceId: z.string().describe("Anaplan workspace ID or name"),
      modelId: z.string().describe("Anaplan model ID or name"),
      fileId: z.string().describe("Anaplan file ID or name (from show_files)"),
      saveToDownloads: z.boolean().optional().describe("If true, save the file to ~/Downloads without decoding"),
      fileName: z.string().optional().describe("Optional local file name when saveToDownloads is true"),
  • Handler implementation: resolves IDs, calls apis.files.download(), attempts UTF-8 decode; if saveToDownloads, writes buffer to ~/Downloads; otherwise returns inline text or instructs to use saveToDownloads for binary.
    }, async ({ workspaceId, modelId, fileId, saveToDownloads, fileName }) => {
      const wId = await resolver.resolveWorkspace(workspaceId);
      const mId = await resolver.resolveModel(wId, modelId);
      const fId = await resolver.resolveFile(wId, mId, fileId);
      const content = await apis.files.download(wId, mId, fId);
      const text = tryDecodeUtf8(content);
    
      if (saveToDownloads) {
        const requestedName = fileName?.trim();
        const defaultName = sanitizeFileName(fileId) || `file-${fId}`;
        const resolvedName = sanitizeFileName(requestedName && requestedName.length > 0 ? requestedName : defaultName) || defaultName;
        const outputPath = join(homedir(), "Downloads", resolvedName);
        await writeFile(outputPath, content);
        return {
          content: [{
            type: "text",
            text: text === null
              ? `File saved to ${outputPath} (${content.length} bytes). Inline preview is unavailable for binary content.`
              : `File saved to ${outputPath}\n\nPreview:\n${buildTextPreview(text)}`,
          }],
        };
      }
    
      if (text === null) {
        return {
          content: [{
            type: "text",
            text: "This file contains binary data and cannot be returned inline safely. Set `saveToDownloads` to `true` to save it locally.",
          }],
        };
      }
    
      if (text.length > MAX_INLINE_TEXT_CHARS) {
        return {
          content: [{
            type: "text",
            text: buildTextPreview(text),
          }],
        };
      }
      return { content: [{ type: "text", text }] };
    });
  • Helper function tryDecodeUtf8: checks for null bytes and attempts UTF-8 decoding to determine if content is text or binary.
    function tryDecodeUtf8(buffer: Buffer): string | null {
      if (buffer.includes(0)) return null;
      try {
        return new TextDecoder("utf-8", { fatal: true }).decode(buffer);
      } catch {
        return null;
      }
    }
  • Helper function sanitizeFileName: strips invalid filesystem characters from file names.
    function sanitizeFileName(value: string): string {
      return value
        .replace(/[<>:"/\\|?*\x00-\x1f]/g, "_")
        .replace(/\s+/g, " ")
        .trim();
    }
  • Helper function buildTextPreview: truncates text to MAX_INLINE_TEXT_CHARS (50000) for inline display.
    function buildTextPreview(text: string): string {
      return text.length > MAX_INLINE_TEXT_CHARS
        ? text.slice(0, MAX_INLINE_TEXT_CHARS) + `\n\n[Truncated - showing first ${MAX_INLINE_TEXT_CHARS} of ${text.length} characters]`
        : text;
    }
  • FilesApi.download(): fetches chunk list then concatenates raw bytes from each chunk into a Buffer.
    async download(workspaceId: string, modelId: string, fileId: string): Promise<Buffer> {
      const res = await this.client.get<any>(
        `/workspaces/${workspaceId}/models/${modelId}/files/${fileId}/chunks`
      );
      const chunks: Array<{ id: string; name: string }> = res.chunks ?? [];
      const parts: Buffer[] = [];
      for (const chunk of chunks) {
        const data = await this.client.getRawBytes(
          `/workspaces/${workspaceId}/models/${modelId}/files/${fileId}/chunks/${chunk.id}`
        );
        parts.push(data);
      }
      return Buffer.concat(parts);
    }
Behavior4/5

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

With no annotations, the description carries full burden. It discloses key behaviors: text files returned inline, binary files require saveToDownloads for exact bytes. It lacks mention of potential issues like file size limits or error handling.

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?

Two sentences, front-loaded with the main action, then succinct conditional details. No unnecessary words.

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

Completeness4/5

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

Given the tool's simplicity and no output schema, the description sufficiently explains inline return for text and download for binary. Could be improved by mentioning any response format or error scenarios.

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

Parameters4/5

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

Schema description coverage is 100%, so baseline is 3. The description adds value by explaining the effect of saveToDownloads (preserves exact bytes) and the conditional use of fileName, which goes beyond the schema descriptions.

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 action 'Download file content from a model' and distinguishes between text and binary handling, which sets it apart from sibling tools like upload_file or delete_file.

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

Usage Guidelines4/5

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

The description provides clear usage context: when to use saveToDownloads=true for binary files. However, it does not explicitly mention when not to use this tool or compare it to sibling download tools (e.g., download_importdump).

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/larasrinath/anaplan-mcp'

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