Skip to main content
Glama
list-objects.ts2.56 kB
/** * list_objects tool implementation * Lists objects in a storage bucket with optional filtering */ import { z } from "zod"; import { ProviderManager } from "../providers/manager.js"; import { createToolSuccessResponse, createToolErrorResponse } from "../utils/response-formatter.js"; /** * Schema for list_objects tool */ export const listObjectsSchema = { bucket: z.string().describe("The name of the bucket to list objects from"), prefix: z.string().optional().describe("Filter objects by key prefix (e.g., 'folder/subfolder/')"), delimiter: z.string().optional().describe("Character to use for grouping keys (e.g., '/' for folder-like listing)"), max_keys: z.number().optional().describe("Maximum number of objects to return (default: 1000)"), continuation_token: z.string().optional().describe("Token for pagination, returned from previous request"), }; /** * Get metadata for list_objects tool */ export function getListObjectsMetadata(sourceId: string, maxKeys?: number) { const toolName = sourceId === "default" ? "list_objects" : `list_objects_${sourceId}`; return { name: toolName, title: `List Objects (${sourceId})`, description: `List objects in a bucket from the '${sourceId}' source. Supports prefix filtering, delimiter for hierarchical listing, and pagination.${maxKeys ? ` Default max_keys: ${maxKeys}` : ""}`, schema: listObjectsSchema, annotations: { title: `list_objects (${sourceId})`, readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }; } /** * Create list_objects tool handler for a specific source */ export function createListObjectsToolHandler(sourceId?: string, defaultMaxKeys?: number) { return async (args: any, _extra: any) => { const { bucket, prefix, delimiter, max_keys, continuation_token, } = args as { bucket: string; prefix?: string; delimiter?: string; max_keys?: number; continuation_token?: string; }; try { const provider = ProviderManager.getCurrentProvider(sourceId); const result = await provider.listObjects(bucket, { prefix, delimiter, maxKeys: max_keys || defaultMaxKeys || 1000, continuationToken: continuation_token, }); return createToolSuccessResponse({ ...result, source_id: sourceId || "default", }); } catch (error) { return createToolErrorResponse((error as Error).message, "LIST_OBJECTS_ERROR"); } }; }

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/zq940222/OssHub'

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