Skip to main content
Glama
REMnux

REMnux MCP Server

Official
by REMnux

download_file

Retrieve analysis results from the REMnux MCP Server by downloading files from the output directory. Files are automatically protected in password-secured archives to prevent security system triggers during transfer.

Instructions

Download a file from the output directory (returns base64-encoded content). Use this to retrieve analysis results. Files are wrapped in a password-protected archive by default to prevent AV/EDR triggers. Pass archive: false for harmless files like text reports. Provide output_path to save directly to the host filesystem.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesFile path relative to the output directory
output_pathYesDirectory on host to save the downloaded file
archiveNoWrap the file in a password-protected archive before transfer (default: true). Protects against AV/EDR triggers on the host. Pass false for harmless files like text reports.

Implementation Reference

  • Main handler function `handleDownloadFile` that implements the download_file tool. It validates file paths, checks file size (200MB limit), optionally creates password-protected archives (zip/7z/rar), transfers files from REMnux to the host filesystem, and returns formatted responses with file metadata (path, size, SHA256, archive info).
    export async function handleDownloadFile(
      deps: HandlerDeps,
      args: DownloadFileArgs
    ) {
      const startTime = Date.now();
      const { connector, config } = deps;
      const shouldArchive = args.archive !== false;
    
      // Validate file path (skip unless --sandbox)
      if (!config.noSandbox) {
        const validation = validateFilePath(args.file_path, config.outputDir);
        if (!validation.safe) {
          return formatError("download_file", new REMnuxError(
            validation.error || "Invalid file path",
            "INVALID_PATH",
            "validation",
            "Use a relative path within the output directory",
          ), startTime);
        }
      }
    
      // Validate outputPath
      const pathValidation = validateHostPath(args.output_path);
      if (!pathValidation.valid) {
        return formatError("download_file", new REMnuxError(
          pathValidation.error || "Invalid output path",
          "INVALID_PATH",
          "validation",
          "Provide an absolute path to a directory on the host filesystem",
        ), startTime);
      }
    
      // Verify output directory exists and is a directory
      if (!existsSync(args.output_path) || !statSync(args.output_path).isDirectory()) {
        return formatError("download_file", new REMnuxError(
          `Output path does not exist or is not a directory: ${args.output_path}`,
          "INVALID_PATH",
          "validation",
          "Provide an absolute path to an existing directory",
        ), startTime);
      }
    
      const fullPath = `${config.outputDir}/${args.file_path}`;
    
      try {
        // Get file size and hash (separate calls to avoid shell interpolation)
        const statResult = await connector.execute(
          ["stat", "-c", "%s", fullPath],
          { timeout: 30000 }
        );
        const hashResult = await connector.execute(
          ["sha256sum", fullPath],
          { timeout: 30000 }
        );
    
        const sizeBytes = parseInt((statResult.stdout || "0").trim(), 10);
    
        // Guard against oversized downloads
        if (sizeBytes > MAX_DOWNLOAD_SIZE) {
          return formatError("download_file", new REMnuxError(
            `File exceeds ${MAX_DOWNLOAD_SIZE / 1024 / 1024}MB download limit (got ${(sizeBytes / 1024 / 1024).toFixed(2)}MB)`,
            "FILE_TOO_LARGE",
            "validation",
            "Use run_tool with 'split' to break the file into smaller parts first",
          ), startTime);
        }
    
        const sha256 = (hashResult.stdout || "").trim().split(/\s+/)[0] || "unknown";
        const filename = basename(args.file_path);
    
        if (shouldArchive) {
          // Determine archive format and password from session state
          const archiveMeta = deps.sessionState.getArchiveInfo(filename);
          const archiveFormat = archiveMeta?.format ?? DEFAULT_ARCHIVE_FORMAT;
          const archivePassword = archiveMeta?.password ?? DEFAULT_ARCHIVE_PASSWORD;
    
          // Defense-in-depth: reject passwords with shell metacharacters
          if (/[;&|`$\n\r'"\\]/.test(archivePassword)) {
            return formatError("download_file", new REMnuxError(
              "Archive password contains unsafe characters",
              "INVALID_PASSWORD",
              "validation",
              "Try downloading with archive: false",
            ), startTime);
          }
    
          // Create temp archive path inside REMnux
          const timestamp = Date.now();
          const archiveName = `${filename}${archiveExtension(archiveFormat)}`;
          const remoteTmpArchive = `/tmp/dl_${timestamp}_${archiveName}`;
    
          // Create password-protected archive
          const archiveCmd = getArchiveCommand(archiveFormat, remoteTmpArchive, fullPath, archivePassword);
          const archiveResult = await connector.execute(archiveCmd, {
            timeout: Math.max(60000, sizeBytes / 1024),
          });
    
          if (archiveResult.exitCode !== 0) {
            return formatError("download_file", new REMnuxError(
              `Failed to create archive: ${archiveResult.stderr || archiveResult.stdout}`,
              "ARCHIVE_FAILED",
              "tool_failure",
              "Try downloading with archive: false",
            ), startTime);
          }
    
          // Transfer archive to host
          const hostPath = join(args.output_path, archiveName);
          try {
            await connector.readFileToPath(remoteTmpArchive, hostPath);
          } finally {
            // Clean up temp archive inside REMnux
            await connector.execute(["rm", "-f", remoteTmpArchive], { timeout: 10000 }).catch(() => {});
          }
    
          return formatResponse("download_file", {
            file_path: args.file_path,
            size_bytes: sizeBytes,
            sha256,
            host_path: hostPath,
            archived: true,
            archive_format: archiveFormat,
            archive_password: archivePassword,
          }, startTime);
        }
    
        // No archiving — transfer raw file
        const hostPath = join(args.output_path, filename);
        await connector.readFileToPath(fullPath, hostPath);
    
        return formatResponse("download_file", {
          file_path: args.file_path,
          size_bytes: sizeBytes,
          sha256,
          host_path: hostPath,
          archived: false,
        }, startTime);
      } catch (error) {
        return formatError("download_file", toREMnuxError(error, deps.config.mode), startTime);
      }
    }
  • Zod schema `downloadFileSchema` defining the tool's input parameters: file_path (relative path in output directory), output_path (host directory to save to), and archive (optional boolean, default true) to control password-protected archive wrapping. Also exports the TypeScript type `DownloadFileArgs`.
    export const downloadFileSchema = z.object({
      file_path: z.string().describe("File path relative to the output directory"),
      output_path: z.string().describe("Directory on host to save the downloaded file"),
      archive: z.boolean().optional().default(true).describe(
        "Wrap the file in a password-protected archive before transfer (default: true). " +
        "Protects against AV/EDR triggers on the host. Pass false for harmless files like text reports."
      ),
    });
    export type DownloadFileArgs = z.input<typeof downloadFileSchema>;
  • src/index.ts:168-177 (registration)
    Tool registration where `download_file` is registered with the MCP server using `server.tool()`. Includes tool description explaining archiving behavior to prevent AV/EDR triggers, and wires up the schema and handler function.
    // Tool: download_file - Download a file from the output directory
    server.tool(
      "download_file",
      "Download a file from the output directory (returns base64-encoded content). Use this to retrieve analysis results. " +
      "Files are wrapped in a password-protected archive by default to prevent AV/EDR triggers. " +
      "Pass archive: false for harmless files like text reports. " +
      "Provide output_path to save directly to the host filesystem.",
      downloadFileSchema.shape,
      (args) => handleDownloadFile(deps, args)
    );
  • Helper functions for archive creation: `getArchiveCommand()` builds command-line arguments for zip/7z/rar formats with password protection, and `archiveExtension()` returns the appropriate file extension (.zip, .7z, .rar) for each format.
    function getArchiveCommand(
      format: "zip" | "7z" | "rar",
      archivePath: string,
      sourcePath: string,
      password: string
    ): string[] {
      switch (format) {
        case "zip":
          return ["zip", "-j", "-P", password, archivePath, sourcePath];
        case "7z":
          return ["7z", "a", `-p${password}`, "-mhe=on", archivePath, sourcePath];
        case "rar":
          return ["rar", "a", `-p${password}`, "-hp", archivePath, sourcePath];
      }
    }
    
    function archiveExtension(format: "zip" | "7z" | "rar"): string {
      return `.${format}`;
    }
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: the tool returns base64-encoded content, files are wrapped in password-protected archives by default to prevent AV/EDR triggers, and it can save directly to the host filesystem. This covers security implications and output handling well, though it doesn't mention error conditions or performance characteristics.

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 perfectly structured and concise. The first sentence states the core purpose and return format. Subsequent sentences provide essential behavioral context and parameter guidance. Every sentence earns its place with no wasted words, and information is front-loaded appropriately.

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?

For a 3-parameter tool with no annotations and no output schema, the description does an excellent job covering the tool's behavior, security implications, and parameter usage. The main gap is the lack of information about return values beyond 'base64-encoded content' - no details about error responses, success indicators, or output structure. This prevents a perfect score.

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 the baseline is 3. The description adds meaningful context beyond the schema: it explains WHY the archive parameter exists ('to prevent AV/EDR triggers'), provides usage guidance ('Pass false for harmless files like text reports'), and clarifies the purpose of output_path ('to save directly to the host filesystem'). This elevates the score above baseline.

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 a file') and resource ('from the output directory'), distinguishing it from sibling tools like 'download_from_url' (which downloads from URLs) and 'list_files' (which only lists files). The specific verb+resource combination makes the purpose unambiguous.

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 context for when to use the tool ('to retrieve analysis results') and guidance on when to modify default behavior ('Pass archive: false for harmless files like text reports'). However, it doesn't explicitly state when NOT to use it or name specific alternatives among siblings, keeping it from a perfect score.

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/REMnux/remnux-mcp-server'

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