Skip to main content
Glama

download_file

Retrieve files from the container's /app directory to the host filesystem. Specify the source path in the container and the destination path on the host for automatic file transfer.

Instructions

Download a file from the container's /app directory to the host filesystem.

Retrieves files created or modified during code execution from the container. The file at '/app/{relpath}' in the container will be saved to the specified location on the host.

Parent directories are created automatically if they don't exist.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
local_pathYesAbsolute path on host filesystem where the file will be saved
relpathYesSource path relative to container's /app directory (e.g., 'output/results.csv' reads from /app/output/results.csv)

Implementation Reference

  • The primary MCP tool handler for 'download_file'. Performs path validation and delegates the download to the ResourceClient.download_file method.
    async def download_file(
        self,
        relpath: Annotated[
            str,
            Field(
                description="Source path relative to container's /app directory (e.g., 'output/results.csv' reads from /app/output/results.csv)"
            ),
        ],
        local_path: Annotated[str, Field(description="Absolute path on host filesystem where the file will be saved")],
    ):
        """Download a file from the container's /app directory to the host filesystem.
    
        Retrieves files created or modified during code execution from the container.
        The file at '/app/{relpath}' in the container will be saved to the specified
        location on the host.
    
        Parent directories are created automatically if they don't exist.
        """
        await self.setup_task
        assert self.resource_client is not None
    
        local_path_obj = Path(local_path)
        self.path_validator.validate(local_path_obj, "download")
        local_path_obj.parent.mkdir(parents=True, exist_ok=True)
    
        await self.resource_client.download_file(relpath, local_path_obj)
  • Registers the download_file method as an MCP tool using FastMCP's tool decorator.
    self.mcp.tool()(self.download_file)
  • Pydantic schema definitions for the tool's input parameters using Annotated and Field.
    relpath: Annotated[
        str,
        Field(
            description="Source path relative to container's /app directory (e.g., 'output/results.csv' reads from /app/output/results.csv)"
        ),
    ],
    local_path: Annotated[str, Field(description="Absolute path on host filesystem where the file will be saved")],
  • Helper method in ResourceClient that performs the actual HTTP download from the resource server to the local filesystem.
    async def download_file(self, relpath: str, local_path: Path) -> None:
        """Download a file from the container.
    
        Args:
            relpath: Path relative to the container's `/app` directory
            local_path: Local file path to save to
    
        Raises:
            HTTPError: If the file doesn't exist or download fails
        """
        # Create parent directories if needed
        local_path.parent.mkdir(parents=True, exist_ok=True)
    
        url = f"{self._base_url}/files/{relpath}"
        async with self._session.get(url) as response:
            response.raise_for_status()
    
            # Stream content to file
            async with aiofiles.open(local_path, mode="wb") as f:
                async for chunk in response.content.iter_chunked(1024 * 1024):  # 1MB chunks
                    await f.write(chunk)
    
    async def delete_file(self, relpath: str) -> None:
  • The resource server's HTTP endpoint handler for downloading files, serving as the backend for the client helper.
    async def download_file(self, relpath: Path):
        """Download a file from the container."""
        full_path = self._validate_path(relpath)
    
        if not full_path.exists() or not full_path.is_file():
            raise HTTPException(status_code=404, detail="File not found")
    
        # Determine MIME type
        mime_type, _ = mimetypes.guess_type(str(full_path))
        if mime_type is None:
            mime_type = "application/octet-stream"
    
        # Stream file content
        async def file_streamer():
            async with aiofiles.open(full_path, mode="rb") as f:
                while chunk := await f.read(1024 * 1024):  # 1MB chunks
                    yield chunk
    
        return StreamingResponse(
            file_streamer(),
            media_type=mime_type,
            headers={"Content-Disposition": f"attachment; filename={full_path.name}"},
        )
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 and does well by disclosing key behavioral traits: it explains the source and destination mapping, mentions automatic parent directory creation, and implies file transfer from container to host. However, it doesn't cover error conditions, file size limits, or permissions requirements.

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 appropriately sized and front-loaded: the first sentence states the core purpose, followed by clarifying sentences that each add useful context without redundancy. There is no wasted text, and the structure supports quick comprehension.

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 moderate complexity (file transfer between container and host), no annotations, and no output schema, the description is fairly complete—it covers purpose, usage context, and key behavior. However, it lacks details on error handling, return values, or limitations, leaving some gaps for an 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?

Schema description coverage is 100%, so the schema already fully documents both parameters. The description adds minimal value beyond the schema by clarifying the '/app/{relpath}' mapping and the host filesystem context, but doesn't provide additional syntax or format details. This meets the baseline for high schema coverage.

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 the container's /app directory to the host filesystem'), distinguishing it from sibling tools like upload_file (which moves in the opposite direction) and execute_ipython_cell/reset (which are unrelated file operations).

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 this tool ('Retrieves files created or modified during code execution from the container'), but does not explicitly state when not to use it or name alternatives (e.g., it doesn't contrast with upload_file beyond the directional implication).

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

Related 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/gradion-ai/ipybox'

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