get_object
Retrieve an object from an S3 bucket by specifying the bucket name and object key. Returns the S3 response in JSON format.
Instructions
Gets an object from an S3 bucket.
Args: bucket (str): The name of the bucket. key (str): The key (name) of the object.
Returns: str: JSON formatted S3 response.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | ||
| key | Yes |
Implementation Reference
- src/s3_mcp.py:164-164 (registration)Registration of the get_object tool using @mcp.tool() decorator.@mcp.tool()
- src/s3_mcp.py:165-176 (handler)Handler function that executes the tool logic by calling the helper and formatting the response as JSON.def get_object(bucket: str, key: str) -> str: """Gets an object from an S3 bucket. Args: bucket (str): The name of the bucket. key (str): The key (name) of the object. Returns: str: JSON formatted S3 response. """ result = _get_object_logic(bucket=bucket, key=key) return format_response(result)
- src/s3_mcp.py:165-174 (schema)Input schema defined by function parameters and docstring (bucket: str, key: str), output str (JSON).def get_object(bucket: str, key: str) -> str: """Gets an object from an S3 bucket. Args: bucket (str): The name of the bucket. key (str): The key (name) of the object. Returns: str: JSON formatted S3 response. """
- src/s3_mcp.py:145-162 (helper)Helper function implementing the core S3 get_object logic using boto3 client.def _get_object_logic(bucket: str, key: str) -> Dict[str, Any]: """Core logic to get an object from an S3 bucket. Args: bucket (str): The S3 bucket name. key (str): The S3 object key. Returns: Dict[str, Any]: Raw boto3 response from get_object. """ client = get_s3_client() response = client.get_object(Bucket=bucket, Key=key) # The body is a StreamingBody, which is not directly JSON serializable. # We read it and decode it to a string. if 'Body' in response: response['Body'] = response['Body'].read().decode('utf-8') return response