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}"}
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