list_downloaded_files
Retrieve a list of downloaded markdown files from the Markdown Downloader MCP server, optionally filtered by subdirectory, for easy file management and organization.
Instructions
List all downloaded markdown files
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| subdirectory | No | Optional subdirectory to list files from |
Input Schema (JSON Schema)
{
"properties": {
"subdirectory": {
"description": "Optional subdirectory to list files from",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/index.ts:248-276 (handler)The main handler logic for the 'list_downloaded_files' tool. It retrieves the download directory from config, optionally uses a subdirectory, lists the .md files using fs.readdir, and returns the filenames or an error.if (request.params.name === 'list_downloaded_files') { try { const config = getConfig(); const subdirectory = request.params.arguments?.subdirectory; const listDir = subdirectory && typeof subdirectory === 'string' ? path.join(config.downloadDirectory, subdirectory) : config.downloadDirectory; const files = await fs.readdir(listDir); return { content: [ { type: 'text', text: files.join('\n') } ] }; } catch (listError) { const errorMessage = listError instanceof Error ? listError.message : 'Unknown error'; return { content: [ { type: 'text', text: `Failed to list files: ${errorMessage}` } ], isError: true }; } }
- src/index.ts:132-144 (registration)Registration of the 'list_downloaded_files' tool in the server's ListTools response, defining its name, description, and input schema.{ name: 'list_downloaded_files', description: 'List all downloaded markdown files', inputSchema: { type: 'object', properties: { subdirectory: { type: 'string', description: 'Optional subdirectory to list files from' } } } },
- src/index.ts:35-56 (helper)Helper function getConfig() that loads the download directory configuration, used by the list_downloaded_files handler.function getConfig(): MarkdownDownloaderConfig { try { fs.ensureDirSync(CONFIG_DIR); if (!fs.existsSync(CONFIG_FILE)) { // Default to platform-specific directory if no config exists const defaultDownloadDir = getDefaultDownloadDir(); const defaultConfig: MarkdownDownloaderConfig = { downloadDirectory: defaultDownloadDir }; fs.writeJsonSync(CONFIG_FILE, defaultConfig); fs.ensureDirSync(defaultConfig.downloadDirectory); return defaultConfig; } return fs.readJsonSync(CONFIG_FILE); } catch (error) { console.error('Error reading config:', error); // Fallback to default const defaultDownloadDir = getDefaultDownloadDir(); return { downloadDirectory: defaultDownloadDir }; }