Skip to main content
Glama

upload_file

Transfer files from your host system to the /app directory of the container for code execution. Specify source file path and destination relative path to make files accessible within the container.

Instructions

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

    Makes a file from the host available inside the container for code execution.
    The uploaded file can then be accessed in execute_ipython_cell using the
    path '/app/{relpath}'.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
local_pathYesAbsolute path to the source file on host filesystem that will be uploaded
relpathYesDestination path relative to container's /app directory (e.g., 'data/input.csv' saves to /app/data/input.csv)

Implementation Reference

  • The MCP tool handler for 'upload_file'. Validates the host-side local_path using PathValidator, confirms it exists and is a file, then delegates upload to ResourceClient.upload_file.
    async def upload_file(
        self,
        relpath: Annotated[
            str,
            Field(
                description="Destination path relative to container's /app directory (e.g., 'data/input.csv' saves to /app/data/input.csv)"
            ),
        ],
        local_path: Annotated[
            str, Field(description="Absolute path to the source file on host filesystem that will be uploaded")
        ],
    ):
        """Upload a file from the host filesystem to the container's /app directory.
    
        Makes a file from the host available inside the container for code execution.
        The uploaded file can then be accessed in execute_ipython_cell using the
        path '/app/{relpath}'.
        """
        await self.setup_task
        assert self.resource_client is not None
    
        local_path_obj = Path(local_path)
        self.path_validator.validate(local_path_obj, "upload")
    
        if not local_path_obj.exists():
            raise FileNotFoundError(f"File not found: {local_path_obj}")
    
        if not local_path_obj.is_file():
            raise ValueError(f"Not a file: {local_path_obj}")
    
        await self.resource_client.upload_file(relpath, local_path_obj)
    
    async def download_file(
  • Registration of the 'upload_file' tool handler using FastMCP's tool() decorator.
    self.mcp.tool()(self.upload_file)
  • Helper method in ResourceClient that performs the actual HTTP POST of file content to the resource server's /files/{relpath} endpoint, called by the MCP handler.
    async def upload_file(self, relpath: str, local_path: Path) -> None:
        """Upload a file to the container.
    
        Args:
            relpath: Path relative to the container's `/app` directory
            local_path: Local file path to upload
    
        Raises:
            FileNotFoundError: If the local file doesn't exist
            HTTPError: If the upload fails
        """
        if not local_path.exists() or not local_path.is_file():
            raise FileNotFoundError(f"Local file not found: {local_path}")
    
        # Determine MIME type
        mime_type, _ = mimetypes.guess_type(str(local_path))
        headers = {"Content-Type": mime_type} if mime_type else {}
    
        # Read and upload file
        async with aiofiles.open(local_path, mode="rb") as f:
            content = await f.read()
    
        url = f"{self._base_url}/files/{relpath}"
        async with self._session.post(url, data=content, headers=headers) as response:
            response.raise_for_status()
  • Helper HTTP POST endpoint /files/{relpath:path} in ResourceServer that receives the file content, validates and resolves the path within root_dir (/app), creates dirs, and writes the content to disk.
    async def upload_file(self, relpath: Path, request: Request):
        """Upload a file to the container."""
        full_path = self._validate_path(relpath)
    
        # Create parent directories if needed
        full_path.parent.mkdir(parents=True, exist_ok=True)
    
        # Read file content from request body
        content = await request.body()
    
        # Write file
        async with aiofiles.open(full_path, mode="wb") as f:
            await f.write(content)
    
        return {"message": f"File uploaded to {relpath}"}
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 explains the tool's effect ('makes a file available inside the container') and how the uploaded file can be accessed later, but doesn't cover important behavioral aspects like error conditions (e.g., what happens if the local file doesn't exist), permissions, or whether the operation overwrites existing files. It adds some context but leaves gaps.

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 efficiently structured with three sentences that each serve a clear purpose: stating the core action, explaining the utility, and providing access instructions. There's no wasted text, and information is front-loaded appropriately for an AI agent.

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

Completeness3/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 operation), no annotations, and no output schema, the description provides adequate but incomplete coverage. It explains the basic functionality and integration with execute_ipython_cell, but lacks details about error handling, performance characteristics, or what the tool returns upon completion. It's minimally viable but has clear gaps.

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 (local_path and relpath). The description adds minimal value beyond the schema by mentioning the destination path format ('/app/{relpath}'), but doesn't provide additional semantic context like file size limits or supported file types. Baseline 3 is appropriate when the schema does the heavy lifting.

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 ('upload a file') and resource ('from the host filesystem to the container's /app directory'), distinguishing it from sibling tools like download_file (reverse operation) and execute_ipython_cell (different function). It provides a concrete purpose beyond just the tool name.

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 explicitly states when to use this tool ('to make a file available inside the container for code execution') and mentions its relationship with execute_ipython_cell for accessing the uploaded file. However, it doesn't provide explicit alternatives or exclusions (e.g., when not to use it vs. other file management tools).

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