list_objects_v2
Retrieve a JSON-formatted list of objects from an S3 bucket, with options to filter by prefix, set maximum keys, paginate using a token, and group keys with a delimiter.
Instructions
Lists objects in an S3 bucket.
Args: bucket (str): The name of the bucket. prefix (Optional[str]): Filter for keys starting with this prefix. max_keys (Optional[int]): Maximum number of keys to return. continuation_token (Optional[str]): Token for paginating results. delimiter (Optional[str]): Delimiter for grouping keys.
Returns: str: JSON formatted S3 response.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | ||
| continuation_token | No | ||
| delimiter | No | ||
| max_keys | No | ||
| prefix | No |
Implementation Reference
- src/s3_mcp.py:240-267 (handler)Main handler function for list_objects_v2 tool, decorated with @mcp.tool() for registration. Handles parameters, calls helper logic, and formats response as JSON.@mcp.tool() def list_objects_v2( bucket: str, prefix: Optional[str] = None, max_keys: Optional[int] = None, continuation_token: Optional[str] = None, delimiter: Optional[str] = None, ) -> str: """Lists objects in an S3 bucket. Args: bucket (str): The name of the bucket. prefix (Optional[str]): Filter for keys starting with this prefix. max_keys (Optional[int]): Maximum number of keys to return. continuation_token (Optional[str]): Token for paginating results. delimiter (Optional[str]): Delimiter for grouping keys. Returns: str: JSON formatted S3 response. """ result = _list_objects_v2_logic( bucket=bucket, prefix=prefix, max_keys=max_keys, continuation_token=continuation_token, delimiter=delimiter, ) return format_response(result)
- src/s3_mcp.py:208-238 (helper)Helper function containing the core boto3 client.list_objects_v2 call with parameter preparation.def _list_objects_v2_logic( bucket: str, prefix: Optional[str] = None, max_keys: Optional[int] = None, continuation_token: Optional[str] = None, delimiter: Optional[str] = None, ) -> Dict[str, Any]: """Core logic to list objects in an S3 bucket. Args: bucket (str): The S3 bucket name. prefix (Optional[str]): Filter for keys starting with this prefix. max_keys (Optional[int]): Maximum number of keys to return. continuation_token (Optional[str]): Token for paginating results. delimiter (Optional[str]): Delimiter for grouping keys. Returns: Dict[str, Any]: Raw boto3 response from list_objects_v2. """ client = get_s3_client() params: Dict[str, Any] = {"Bucket": bucket} if prefix: params["Prefix"] = prefix if max_keys: params["MaxKeys"] = max_keys if continuation_token: params["ContinuationToken"] = continuation_token if delimiter: params["Delimiter"] = delimiter return client.list_objects_v2(**params)
- src/s3_mcp.py:240-240 (registration)The @mcp.tool() decorator registers the list_objects_v2 function as an MCP tool.@mcp.tool()
- src/s3_mcp.py:248-258 (schema)Docstring in handler defines input schema (parameters) and output for FastMCP tool schema generation."""Lists objects in an S3 bucket. Args: bucket (str): The name of the bucket. prefix (Optional[str]): Filter for keys starting with this prefix. max_keys (Optional[int]): Maximum number of keys to return. continuation_token (Optional[str]): Token for paginating results. delimiter (Optional[str]): Delimiter for grouping keys. Returns: str: JSON formatted S3 response.