list_objects
Retrieve a list of objects stored in an S3-compatible bucket, with optional prefix filtering to narrow results.
Instructions
List objects in a bucket
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | Bucket name | |
| prefix | No | Optional prefix to filter objects |
Implementation Reference
- src/server.ts:74-90 (handler)Handler function for list_objects tool: calls s3Client.listObjects and formats response as JSON text.async ({ bucket, prefix }: ListObjectsParams) => { const objects = await this.s3Client.listObjects(bucket, prefix); return { content: [ { type: "text", text: JSON.stringify( objects.map((obj) => ({ key: obj.Key, size: obj.Size, lastModified: obj.LastModified, })) ), }, ], }; }
- src/server.ts:67-73 (schema)Zod input schema defining parameters for list_objects tool.{ bucket: z.string().describe("Bucket name"), prefix: z .string() .optional() .describe("Optional prefix to filter objects"), },
- src/server.ts:6-9 (schema)TypeScript interface for ListObjectsParams used in handler type annotation.interface ListObjectsParams { bucket: string; prefix?: string; }
- src/server.ts:64-92 (registration)Registration of the list_objects tool on the MCP server.this.server.tool( "list_objects", "List objects in a bucket", { bucket: z.string().describe("Bucket name"), prefix: z .string() .optional() .describe("Optional prefix to filter objects"), }, async ({ bucket, prefix }: ListObjectsParams) => { const objects = await this.s3Client.listObjects(bucket, prefix); return { content: [ { type: "text", text: JSON.stringify( objects.map((obj) => ({ key: obj.Key, size: obj.Size, lastModified: obj.LastModified, })) ), }, ], }; } );
- src/s3Client.ts:41-48 (helper)S3Client helper method that performs the actual ListObjectsV2Command to AWS S3-compatible service.async listObjects(bucket: string, prefix?: string) { const command = new ListObjectsV2Command({ Bucket: bucket, Prefix: prefix, }); const response = await this.client.send(command); return response.Contents || []; }