storage_list_files
List files from a specified directory path in Firebase Storage to view available stored objects.
Instructions
List files in a given path in Firebase Storage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directoryPath | No | The optional path to list files from. If not provided, the root is used. |
Implementation Reference
- src/lib/firebase/storageClient.ts:10-51 (handler)Core handler function implementing the storage_list_files tool logic: lists files and directories in Firebase Storage bucket with pagination, generates signed URLs for files and console links for directories, returns JSON-formatted result.export async function listDirectoryFiles(path?: string, pageSize: number = 10, pageToken?: string): Promise<{ content: { type: string , text: string }[] }> { const prefix = path ? (path === '' ? '' : (path.endsWith('/') ? path : `${path}/`)) : ''; const [files, , apiResponse] = await admin.storage().bucket().getFiles({ prefix, delimiter: '/', maxResults: pageSize, pageToken }); const nextPageToken = apiResponse.nextPageToken as string || undefined; const fileNames = await Promise.all(files.map(async (file) => { const [signedUrl] = await file.getSignedUrl({ action: 'read', expires: Date.now() + 1000 * 60 * 60 // 1 hour }); return { type: "file", name: file.name, downloadURL: signedUrl }; })); const projectId = getProjectId(); const bucketName = admin.storage().bucket().name; const directoryNames = (apiResponse.prefixes || []).map((prefix:string) => { //const encodedPrefix = encodeURIComponent(prefix).replace(/'/g, '%27').replace(/%20/g, '+'); const tmpPrefix = prefix.replace(/\/$/, ''); const encodedPrefix = `~2F${tmpPrefix.replace(/\//g, '~2F')}`; const consoleUrl = `https://console.firebase.google.com/project/${projectId}/storage/${bucketName}/files/${encodedPrefix}`; return { type: "directory", name: prefix, url: consoleUrl }; }); const result = { nextPageToken: nextPageToken, files: [...fileNames, ...directoryNames], hasMore: nextPageToken !== undefined }; return { content:[ { type: "text", text: JSON.stringify(result,null,2) } ] } }
- src/index.ts:196-208 (schema)Input schema definition for the storage_list_files tool, specifying optional directoryPath parameter."name": "storage_list_files", "description": "List files in a given path in Firebase Storage", "inputSchema": { "type": "object", "properties": { "directoryPath": { "type": "string", "description": "The optional path to list files from. If not provided, the root is used." } }, "required": [] } },
- src/index.ts:252-257 (registration)Tool dispatch/registration in the main switch handler for CallToolRequestSchema, invoking the listDirectoryFiles implementation.case 'storage_list_files': return listDirectoryFiles( args.directoryPath as string | undefined, args.pageSize as number | undefined, args.pageToken as string | undefined );
- src/index.ts:37-224 (registration)Registration of the tool in the ListToolsRequestSchema response, including it in the list of available tools.{ name: 'firestore_add_document', description: 'Add a document to a Firestore collection', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name' }, data: { type: 'object', description: 'Document data' } }, required: ['collection', 'data'] } }, { name: 'firestore_list_collections', description: 'List collections in Firestore. If documentPath is provided, returns subcollections under that document; otherwise returns root collections.', inputSchema: { type: 'object', properties: { documentPath: { type: 'string', description: 'Optional parent document path' }, limit: { type: 'number', description: 'Number of collections to return', default: 20 }, pageToken: { type: 'string', description: 'Token for pagination to get the next page of results' } }, required: [] } }, { name: 'firestore_list_documents', description: 'List documents from a Firestore collection with optional filtering', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name' }, filters: { type: 'array', description: 'Array of filter conditions', items: { type: 'object', properties: { field: { type: 'string', description: 'Field name to filter' }, operator: { type: 'string', description: 'Comparison operator' }, value: { type: 'any', description: 'Value to compare against (use ISO format for dates)' } }, required: ['field', 'operator', 'value'] } }, limit: { type: 'number', description: 'Number of documents to return', default: 20 }, pageToken: { type: 'string', description: 'Token for pagination to get the next page of results' } }, required: ['collection'] } }, { name: 'firestore_get_document', description: 'Get a document from a Firestore collection', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name' }, id: { type: 'string', description: 'Document ID' } }, required: ['collection', 'id'] } }, { name: 'firestore_update_document', description: 'Update a document in a Firestore collection', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name' }, id: { type: 'string', description: 'Document ID' }, data: { type: 'object', description: 'Updated document data' } }, required: ['collection', 'id', 'data'] } }, { name: 'firestore_delete_document', description: 'Delete a document from a Firestore collection', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name' }, id: { type: 'string', description: 'Document ID' } }, required: ['collection', 'id'] } }, { name: "auth_get_user", description: "Get a user by ID or email from Firebase Authentication", inputSchema: { type: "object", properties: { identifier: { type: "string", description: "User ID or email address" } }, required: ["identifier"] } }, { "name": "storage_list_files", "description": "List files in a given path in Firebase Storage", "inputSchema": { "type": "object", "properties": { "directoryPath": { "type": "string", "description": "The optional path to list files from. If not provided, the root is used." } }, "required": [] } }, { "name": "storage_get_file_info", "description": "Get file information including metadata and download URL", "inputSchema": { "type": "object", "properties": { "filePath": { "type": "string", "description": "The path of the file to get information for" } }, "required": ["filePath"] } } ] }));