Skip to main content
Glama

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
NameRequiredDescriptionDefault
bucketYesName of the S3 bucket
prefixNoPrefix to filter objects (like a folder)
maxKeysNoMaximum number of objects to return

Implementation Reference

  • 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)}`, ); } }
  • 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;
  • 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)); }
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/samuraikun/aws-s3-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server