s3_list_objects
List and filter objects within an S3-compatible storage bucket to manage files and directories.
Instructions
List objects in an S3 bucket
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | The name of the bucket | |
| prefix | No | Optional prefix to filter objects | |
| maxKeys | No | Maximum number of keys to return (default 1000) |
Implementation Reference
- src/index.ts:171-196 (handler)Handler implementation for the s3_list_objects tool. Extracts bucket, optional prefix and maxKeys from arguments, sends ListObjectsV2Command to S3 client, maps response Contents to simplified file objects (key, size, lastModified), and returns as JSON text content.case "s3_list_objects": { const { bucket, prefix, maxKeys } = request.params.arguments as { bucket: string; prefix?: string; maxKeys?: number; }; const command = new ListObjectsV2Command({ Bucket: bucket, Prefix: prefix, MaxKeys: maxKeys, }); const response = await s3Client.send(command); const files = (response.Contents || []).map((item) => ({ key: item.Key, size: item.Size, lastModified: item.LastModified, })); return { content: [ { type: "text", text: JSON.stringify(files, null, 2), }, ], }; }
- src/index.ts:74-91 (schema)Input schema definition for s3_list_objects tool, specifying required bucket and optional prefix/maxKeys.inputSchema: { type: "object", properties: { bucket: { type: "string", description: "The name of the bucket", }, prefix: { type: "string", description: "Optional prefix to filter objects", }, maxKeys: { type: "number", description: "Maximum number of keys to return (default 1000)", }, }, required: ["bucket"], },
- src/index.ts:71-92 (registration)Registration of the s3_list_objects tool in the ListToolsRequestSchema handler, including name, description, and input schema.{ name: "s3_list_objects", description: "List objects in an S3 bucket", inputSchema: { type: "object", properties: { bucket: { type: "string", description: "The name of the bucket", }, prefix: { type: "string", description: "Optional prefix to filter objects", }, maxKeys: { type: "number", description: "Maximum number of keys to return (default 1000)", }, }, required: ["bucket"], }, },