Skip to main content
Glama

download_file

Transfer files from remote servers via SFTP using SSH configurations. Specify server name, remote file path, and local destination to download files securely.

Instructions

Download a file from a remote server via SFTP.

Args: server: Server name (e.g. 'pro-dicentra'). remote_path: Absolute path to remote file. local_path: Absolute local destination path.

Returns: Confirmation message with file size.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serverYes
remote_pathYes
local_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'download_file' MCP tool handler function. Decorated with @mcp.tool() to register it as an MCP tool. Takes server name, remote_path, and local_path parameters, initializes the SSH manager, and delegates to _ssh.download() for the actual SFTP transfer.
    @mcp.tool()
    async def download_file(
        server: str,
        remote_path: str,
        local_path: str,
    ) -> str:
        """Download a file from a remote server via SFTP.
    
        Args:
            server: Server name (e.g. 'pro-dicentra').
            remote_path: Absolute path to remote file.
            local_path: Absolute local destination path.
    
        Returns:
            Confirmation message with file size.
        """
        try:
            _init()
    
            result = await _ssh.download(server, remote_path, local_path)
            return result
    
        except Exception as e:
            logger.error(f"Error downloading file from {server}: {e}")
            return f"Error downloading file from {server}: {e}"
  • The core implementation of the download functionality in SSHManager.download(). Validates the remote path, establishes an SSH connection, uses SFTP to download the file, logs the operation for audit purposes, and returns a confirmation message with file size.
    async def download(
        self, server_name: str, remote_path: str, local_path: str
    ) -> str:
        """Download file from remote server via SFTP.
    
        Args:
            server_name: Server name from registry
            remote_path: Remote file path
            local_path: Local destination path
    
        Returns:
            Confirmation message with file size
        """
        try:
            # Validate remote path
            _validate_remote_path(remote_path)
    
            start_time = time.monotonic()
            conn = await self._get_connection(server_name)
    
            # Start SFTP client
            async with conn.start_sftp_client() as sftp:
                # Download file
                await sftp.get(remote_path, local_path)
    
                # Get file size for confirmation
                local_size = Path(local_path).stat().st_size
                duration_ms = int((time.monotonic() - start_time) * 1000)
    
                # Audit log download
                self._audit.info(
                    "server=%s operation=download remote_path=%s local_path=%s bytes=%s duration_ms=%s",
                    server_name,
                    remote_path,
                    local_path,
                    local_size,
                    duration_ms,
                )
    
                return f"Downloaded {server_name}:{remote_path} to {local_path} ({local_size} bytes)"
    
        except (
            asyncssh.DisconnectError,
            asyncssh.PermissionDenied,
            asyncssh.SFTPError,
            OSError,
        ) as e:
            error_msg = f"Download failed from {server_name}: {e}"
            logger.error(error_msg)
            raise RuntimeError(error_msg) from e
  • Path validation helper function that blocks parent directory traversal (..) and access to sensitive paths for SFTP operations, providing security controls for the download_file tool.
    def _validate_remote_path(path: str) -> None:
        """Validate remote path for SFTP operations.
    
        Args:
            path: Remote path to validate
    
        Raises:
            ValueError: If path contains parent traversal or sensitive paths
        """
        # Block parent directory traversal
        if ".." in path:
            raise ValueError(f"Path traversal detected: {path}")
    
        # Block access to sensitive paths
        normalized_path = path.lower()
        for sensitive in _SENSITIVE_PATHS:
            if sensitive in normalized_path:
                raise ValueError(f"Access to sensitive path blocked: {path}")
  • Defines sensitive paths that are blocked in SFTP operations (like /etc/shadow, .ssh/id_rsa, etc.) as a security measure to prevent downloading sensitive files.
    # Sensitive paths that should be blocked in SFTP operations
    _SENSITIVE_PATHS = [
        "/etc/shadow",
        "/etc/passwd",
        ".ssh/authorized_keys",
        ".ssh/id_rsa",
        ".ssh/id_ed25519",
        ".ssh/id_ecdsa",
        ".ssh/id_dsa",
    ]
Behavior3/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 mentions the SFTP protocol and describes the return value, but doesn't cover important behavioral aspects like error conditions, timeout behavior, authentication requirements, file size limitations, or whether the operation is idempotent. The description provides basic operational context but lacks comprehensive behavioral transparency.

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 well-structured with clear sections (purpose, Args, Returns) and uses minimal sentences. Each sentence earns its place by providing essential information. The formatting is efficient, though the 'Args:' and 'Returns:' labels could be slightly more concise.

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 has an output schema (which handles return value documentation), no annotations, and 3 parameters with good description coverage, the description is reasonably complete. It covers the core operation, all parameters, and return format. The main gap is lack of behavioral context like error handling and authentication requirements, but the presence of output schema reduces the completeness burden.

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?

With 0% schema description coverage, the description compensates by clearly explaining all three parameters with examples and context. The Args section provides meaningful semantics: 'server' is explained with an example format, 'remote_path' specifies it must be absolute, and 'local_path' clarifies it's the destination. This adds substantial value beyond the bare schema.

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 ('Download a file') and resource ('from a remote server via SFTP'), distinguishing it from sibling tools like upload_file. It provides a complete verb+resource+protocol combination that leaves no ambiguity about what the tool does.

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 upload_file or other sibling tools. It mentions SFTP protocol but doesn't specify prerequisites, authentication requirements, or when this tool is appropriate versus other file transfer methods. No exclusions or alternative scenarios are mentioned.

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/blackaxgit/ssh-mcp'

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