list_files
Retrieve file details from a storage bucket, including names, sizes, and modification dates, to manage and organize project data.
Instructions
List files in a storage bucket. Shows file names, sizes, and last modified dates.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | The project ID | |
| bucket | Yes | Storage bucket name |
Implementation Reference
- src/tools/list-files.ts:11-59 (handler)The handleListFiles async function is the main handler for the list_files tool. It retrieves project credentials, makes an API request to list storage objects, and formats the response as a markdown table showing file names, sizes, and modification dates.
export async function handleListFiles(args: { project_id: string; bucket: string; }): Promise<{ content: Array<{ type: "text"; text: string }>; isError?: boolean }> { const project = getProject(args.project_id); if (!project) return projectNotFound(args.project_id); const res = await apiRequest(`/storage/v1/object/list/${args.bucket}`, { method: "GET", headers: { apikey: project.anon_key, Authorization: `Bearer ${project.anon_key}`, }, }); if (!res.ok) return formatApiError(res, "listing files"); const body = res.body as { objects: Array<{ key: string; size: number; last_modified: string }>; }; if (body.objects.length === 0) { return { content: [ { type: "text", text: `## Files in \`${args.bucket}\`\n\n_No files found._`, }, ], }; } const lines = [ `## Files in \`${args.bucket}\` (${body.objects.length})`, ``, `| File | Size | Modified |`, `|------|------|----------|`, ]; for (const obj of body.objects) { const size = obj.size < 1024 ? `${obj.size}B` : `${(obj.size / 1024).toFixed(1)}KB`; lines.push(`| ${obj.key} | ${size} | ${obj.last_modified} |`); } return { content: [{ type: "text", text: lines.join("\n") }] }; } - src/tools/list-files.ts:6-9 (schema)The listFilesSchema defines the input validation schema for the list_files tool using Zod. It requires a project_id (string) and bucket (string) parameter.
export const listFilesSchema = { project_id: z.string().describe("The project ID"), bucket: z.string().describe("Storage bucket name"), }; - src/index.ts:130-135 (registration)Registration of the list_files tool with the MCP server. Associates the tool name with its description, schema, and handler function.
server.tool( "list_files", "List files in a storage bucket. Shows file names, sizes, and last modified dates.", listFilesSchema, async (args) => handleListFiles(args), ); - src/index.ts:35-35 (registration)Import statement that brings in listFilesSchema and handleListFiles from the tools/list-files module.
import { listFilesSchema, handleListFiles } from "./tools/list-files.js";