Skip to main content
Glama
KonMam

s3-mcp

by KonMam

put_object

Uploads an object to an S3 bucket using bucket name, object key, and content. Returns a JSON-formatted S3 response for AWS S3 integration.

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
NameRequiredDescriptionDefault
bodyYes
bucketYes
keyYes

Implementation Reference

  • The handler function for the 'put_object' tool. Registered via @mcp.tool() decorator with FastMCP. Calls internal helper 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)
  • Internal helper function containing the core boto3 logic for uploading an object to S3 using put_object.
    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)
  • Utility helper used by put_object (and other tools) to format boto3 responses as indented JSON strings.
    def format_response(data: Any) -> str: """Format response data as JSON string. Args: data (Any): Data to format Returns: str: JSON formatted string """ return json.dumps(data, indent=2, default=str)
  • Global S3 client initializer used by _put_object_logic to obtain the boto3 S3 client.
    def get_s3_client() -> BaseClient: """Get or create the S3 boto3 client. Returns: BaseClient: S3 client Raises: NoCredentialsError: If AWS credentials are not found. """ global s3_client if s3_client is None: logger.info("Initializing S3 client") try: s3_client = boto3.client("s3") s3_client.list_buckets() # Validate credentials logger.info("Successfully initialized and validated S3 client.") except NoCredentialsError as e: logger.error("AWS credentials not found.") raise e except Exception as e: logger.error(f"Unexpected error initializing S3 client: {e}") raise e return s3_client

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/KonMam/s3-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server