list_files
Access and display files and folders stored in Proton Drive by specifying a directory path, enabling organized file management and retrieval.
Instructions
List files and folders in Proton Drive
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Path relative to Proton Drive root (e.g., "Documents" or "Projects/2024") |
Implementation Reference
- src/index.ts:260-305 (handler)Handler function for the 'list_files' tool. Validates the path, reads the directory entries, filters out hidden files, retrieves stats for each entry, formats the results with relative paths, sorts folders first then files alphabetically, and returns a JSON string of the file list.case 'list_files': { const listPath = validatePath(args?.path as string || ''); try { const entries = await readdir(listPath, { withFileTypes: true }); const files = await Promise.all( entries .filter(entry => !entry.name.startsWith('.')) .map(async (entry) => { const fullPath = join(listPath, entry.name); const relativePath = getRelativePath(fullPath); const stats = await stat(fullPath); return { name: entry.name, path: relativePath, type: entry.isDirectory() ? 'folder' : 'file', size: stats.size, modified: stats.mtime.toISOString(), }; }) ); // Sort folders first, then files files.sort((a, b) => { if (a.type === b.type) { return a.name.localeCompare(b.name); } return a.type === 'folder' ? -1 : 1; }); return { content: [ { type: 'text', text: JSON.stringify(files, null, 2), }, ], }; } catch (error: any) { throw new McpError( ErrorCode.InternalError, `Cannot list directory: ${error.message}` ); } }
- src/index.ts:133-144 (schema)Input schema definition for the 'list_files' tool, specifying an optional 'path' parameter as a string relative to the Proton Drive root.name: 'list_files', description: 'List files and folders in Proton Drive', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path relative to Proton Drive root (e.g., "Documents" or "Projects/2024")' }, }, }, },
- src/index.ts:122-220 (registration)Registration of all tools including 'list_files' in the ListToolsRequestSchema handler, which returns the list of available tools with their schemas.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'check_mount', description: 'Check if Proton Drive is mounted and accessible', inputSchema: { type: 'object', properties: {}, }, }, { name: 'list_files', description: 'List files and folders in Proton Drive', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path relative to Proton Drive root (e.g., "Documents" or "Projects/2024")' }, }, }, }, { name: 'read_file', description: 'Read a text file from Proton Drive', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'File path relative to Proton Drive root' }, }, required: ['path'], }, }, { name: 'write_file', description: 'Write or create a file in Proton Drive', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'File path relative to Proton Drive root' }, content: { type: 'string', description: 'Text content to write to the file' }, }, required: ['path', 'content'], }, }, { name: 'delete_file', description: 'Delete a file or folder from Proton Drive', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to delete relative to Proton Drive root' }, }, required: ['path'], }, }, { name: 'create_folder', description: 'Create a new folder in Proton Drive', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Folder path relative to Proton Drive root' }, }, required: ['path'], }, }, { name: 'get_file_info', description: 'Get information about a file or folder', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file or folder' }, }, required: ['path'], }, }, ], }));