list_buckets
Retrieve a JSON-formatted list of all S3 buckets in an AWS account using this tool, enabling quick access to bucket data for integration and management.
Instructions
Lists all buckets in the AWS account.
Returns: str: JSON formatted list of buckets.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/s3_mcp.py:87-95 (handler)The main handler function for the 'list_buckets' MCP tool. It is registered via the @mcp.tool() decorator with FastMCP. Calls the helper to get raw data and formats it as a JSON string for the response.@mcp.tool() def list_buckets() -> str: """Lists all buckets in the AWS account. Returns: str: JSON formatted list of buckets. """ result = _list_buckets_logic() return format_response(result)
- src/s3_mcp.py:77-84 (helper)Helper function implementing the core S3 bucket listing logic using boto3's list_buckets() method.def _list_buckets_logic() -> Dict[str, Any]: """Core logic to list S3 buckets. Returns: Dict[str, Any]: Raw boto3 response from list_buckets. """ client = get_s3_client() return client.list_buckets()
- src/s3_mcp.py:64-73 (helper)Utility helper function used by list_buckets (and other tools) to format the boto3 response as a pretty-printed JSON string.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)
- src/s3_mcp.py:37-61 (helper)Helper function to initialize and return the global S3 boto3 client, used by _list_buckets_logic. Includes credential validation via list_buckets().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