available-files
List and identify available files and resources by retrieving details like URI, name, size, last modified, and mime type in a markdown table. Use to pinpoint specific resources such as recent images or audio files.
Instructions
A list of available file and resources. If the User requests things like 'most recent image' or 'the audio' use this tool to identify the intended resource.This tool returns 'resource uri', 'name', 'size', 'last modified' and 'mime type' in a markdown table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:81-91 (registration)Tool registration for 'available-files' with name, description, and empty input schemaname: AVAILABLE_FILES, description: "A list of available file and resources. " + "If the User requests things like 'most recent image' or 'the audio' use " + "this tool to identify the intended resource." + "This tool returns 'resource uri', 'name', 'size', 'last modified' and 'mime type' in a markdown table", inputSchema: { type: "object", properties: {}, }, },
- src/index.ts:117-131 (handler)Main handler for 'available-files' tool call that returns a resource with the generated file tableserver.setRequestHandler(CallToolRequestSchema, async (request) => { if (AVAILABLE_FILES === request.params.name) { return { content: [ { type: `resource`, resource: { uri: `resource://mcp-hfspace/available-files`, mimeType: `text/markdown`, text: await workingDir.generateResourceTable(), }, }, ], }; }
- src/working_directory.ts:132-156 (handler)Core implementation logic that generates the markdown table of available files with URI, name, MIME type, size, and last modified detailsasync generateResourceTable(): Promise<string> { const files = await this.listFiles(); const resources = await Promise.all( files .filter((entry) => entry.isFile()) .map(async (entry) => await this.getResourceFile(entry)), ); if (resources.length === 0) { return "No resources available."; } return ` The following resources are available for tool calls: | Resource URI | Name | MIME Type | Size | Last Modified | |--------------|------|-----------|------|---------------| ${resources .map( (f) => `| ${f.uri} | ${f.name} | ${f.mimeType} | ${this.formatFileSize(f.size)} | ${f.lastModified.toISOString()} |`, ) .join("\n")} Prefer using the Resource URI for tool parameters which require a file input. URLs are also accepted.`.trim(); }
- src/working_directory.ts:39-53 (helper)Helper method to get file metadata including URI, name, MIME type, size, and last modified timestampasync getResourceFile(file: Dirent): Promise<ResourceFile> { const fullPath = path.join(file.parentPath || "", file.name); const relativePath = path .relative(this.directory, fullPath) .replace(/\\/g, "/"); const stats = await fs.stat(fullPath); return { uri: `file:./${relativePath}`, name: file.name, mimeType: mime.getType(file.name) || FALLBACK_MIME_TYPE, size: stats.size, lastModified: stats.mtime, }; }
- src/working_directory.ts:119-130 (helper)Helper method to format file sizes from bytes to human-readable format (B, KB, MB, GB)formatFileSize(bytes: number): string { const units = ["B", "KB", "MB", "GB"]; let size = bytes; let unitIndex = 0; while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024; unitIndex++; } return `${size.toFixed(1)} ${units[unitIndex]}`; }