download_file
Download objects from an S3 bucket to a specified file path. Requires bucket name, key, and filename inputs to retrieve and save the desired content.
Instructions
Downloads an object from an S3 bucket to a file.
Args: bucket (str): The name of the bucket to download from. key (str): The name of the key to download from. filename (str): The path to the file to download to.
Returns: str: JSON formatted success message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | ||
| filename | Yes | ||
| key | Yes |
Implementation Reference
- src/s3_mcp.py:395-414 (handler)The primary handler for the download_file tool, registered via @mcp.tool() decorator. It invokes the helper function and returns a formatted success message.@mcp.tool() def download_file( bucket: str, key: str, filename: str, ) -> str: """Downloads an object from an S3 bucket to a file. Args: bucket (str): The name of the bucket to download from. key (str): The name of the key to download from. filename (str): The path to the file to download to. Returns: str: JSON formatted success message. """ _download_file_logic(bucket=bucket, key=key, filename=filename) return format_response( {"status": "success", "message": f"File '{key}' from bucket '{bucket}' downloaded to '{filename}'."} )
- src/s3_mcp.py:375-393 (helper)Supporting function that performs the actual S3 download using boto3 client.download_file.def _download_file_logic( bucket: str, key: str, filename: str, ) -> None: """Core logic to download an object from an S3 bucket. Args: bucket (str): The S3 bucket name. key (str): The S3 object key. filename (str): The local path to download the file to. """ client = get_s3_client() client.download_file( Bucket=bucket, Key=key, Filename=filename, )