put_object
Upload files or data to an Amazon S3 bucket by specifying bucket name, object key, and content body.
Instructions
Puts an object into an S3 bucket.
Args: bucket (str): The name of the bucket. key (str): The key (name) of the object. body (str): The content of the object.
Returns: str: JSON formatted S3 response.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | ||
| key | Yes | ||
| body | Yes |
Implementation Reference
- src/s3_mcp.py:125-142 (handler)The primary handler for the 'put_object' MCP tool. Decorated with @mcp.tool() for registration. Defines input schema via type hints and docstring. Executes core logic and formats response as JSON.@mcp.tool() def put_object( bucket: str, key: str, body: str, ) -> str: """Puts an object into an S3 bucket. Args: bucket (str): The name of the bucket. key (str): The key (name) of the object. body (str): The content of the object. Returns: str: JSON formatted S3 response. """ result = _put_object_logic(bucket=bucket, key=key, body=body) return format_response(result)
- src/s3_mcp.py:99-123 (helper)Internal helper function implementing the core S3 put_object logic using boto3 client, handling body encoding.def _put_object_logic( bucket: str, key: str, body: Union[str, bytes], ) -> Dict[str, Any]: """Core logic to put an object into an S3 bucket. Args: bucket (str): The S3 bucket name. key (str): The S3 object key. body (Union[str, bytes]): The content of the object. Returns: Dict[str, Any]: Raw boto3 response from put_object. """ client = get_s3_client() params: Dict[str, Any] = {"Bucket": bucket, "Key": key} if isinstance(body, str): params["Body"] = body.encode("utf-8") else: params["Body"] = body # Assuming bytes or file-like object return client.put_object(**params)