list-objects
Retrieve and display objects stored in an S3 bucket, with options to filter by prefix and limit results.
Instructions
List objects in an S3 bucket
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | Name of the S3 bucket | |
| prefix | No | Prefix to filter objects (like a folder) | |
| maxKeys | No | Maximum number of objects to return |
Implementation Reference
- src/tools/listObjects.ts:50-73 (handler)The execute method implements the core logic of the 'list-objects' tool: validates args, calls S3Resource.listObjects, returns JSON stringified objects or error response.async execute(args: InferZodParams<typeof this.parameters>) { const { bucket, prefix, maxKeys } = args; try { // Handle both undefined and null values for optional parameters const validPrefix = prefix === null || prefix === undefined ? "" : prefix; const validMaxKeys = maxKeys === null || maxKeys === undefined ? 1000 : maxKeys; const objects = await this.s3Resource.listObjects(bucket, validPrefix, validMaxKeys); return { content: [ { type: "text" as const, text: JSON.stringify(objects, null, 2), }, ], }; } catch (error) { return createErrorResponse( error, `Error listing objects in bucket ${bucket}: ${error instanceof Error ? error.message : String(error)}`, ); } }
- src/tools/listObjects.ts:23-33 (schema)Zod schema defining input parameters for the 'list-objects' tool: bucket (string), prefix (string|null optional), maxKeys (number|null optional).readonly parameters = { bucket: z.string().describe("Name of the S3 bucket"), prefix: z .union([z.string(), z.null()]) .optional() .describe("Prefix to filter objects (like a folder)"), maxKeys: z .union([z.number(), z.null()]) .optional() .describe("Maximum number of objects to return"), } as const;
- src/tools/index.ts:12-18 (registration)Instantiates the ListObjectsTool with S3Resource dependency and includes it in the array of all tools returned by createTools.export function createTools(s3Resource: S3Resource): IMCPTool[] { return [ new ListBucketsTool(s3Resource), new ListObjectsTool(s3Resource), new GetObjectTool(s3Resource), ]; }
- src/server.ts:27-32 (registration)Retrieves tools via createTools and registers each tool (including 'list-objects') to the MCP server using server.tool with name, description, parameters, and bound execute method.// Create and register all tools const tools = createTools(s3Resource); for (const tool of tools) { server.tool(tool.name, tool.description, tool.parameters, tool.execute.bind(tool)); }