discover_pdfs
Scan directories to find PDF files recursively, enabling systematic document organization and processing workflows.
Instructions
Recursively scan directory trees to locate all PDF files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory_path | Yes | Path to directory to scan for PDF files | |
| recursive | No | Search subdirectories recursively |
Implementation Reference
- src/index.ts:1484-1501 (handler)Handler for the discover_pdfs tool: parses arguments, calls findPdfFiles utility, formats and returns JSON response with discovered PDF files list and statistics.case "document_organizer__discover_pdfs": { const { directory_path, recursive } = DiscoverPdfsArgsSchema.parse(args); const pdfFiles = await findPdfFiles(directory_path, recursive); return { content: [ { type: "text", text: JSON.stringify({ found_pdfs: pdfFiles.length, pdf_files: pdfFiles, scanned_directory: directory_path, recursive_scan: recursive }, null, 2) } ] }; }
- src/index.ts:21-24 (schema)Zod schema defining input parameters for the discover_pdfs tool: directory_path (required string) and recursive (optional boolean, defaults to true).const DiscoverPdfsArgsSchema = z.object({ directory_path: z.string().describe("Path to directory to scan for PDF files"), recursive: z.boolean().optional().default(true).describe("Search subdirectories recursively") });
- src/index.ts:1301-1305 (registration)Tool registration entry in the tools array, specifying name, description, and input schema reference.name: "document_organizer__discover_pdfs", description: "🔍 PDF FILE DISCOVERY - Recursively scan directory trees to locate all PDF files. Returns complete inventory with file paths, directory structure analysis, and scan statistics. Supports both recursive deep scanning and single-level directory inspection for comprehensive document discovery.", inputSchema: zodToJsonSchema(DiscoverPdfsArgsSchema) as ToolInput, }, {
- src/index.ts:829-852 (helper)Core utility function that recursively scans the specified directory for PDF files using fs.readdir, collects absolute paths, handles errors gracefully.async function findPdfFiles(dirPath: string, recursive: boolean = true): Promise<string[]> { const pdfFiles: string[] = []; async function scanDirectory(currentPath: string) { try { const items = await fs.readdir(currentPath, { withFileTypes: true }); for (const item of items) { const fullPath = path.join(currentPath, item.name); if (item.isFile() && path.extname(item.name).toLowerCase() === '.pdf') { pdfFiles.push(fullPath); } else if (item.isDirectory() && recursive) { await scanDirectory(fullPath); } } } catch (error) { console.error(`Error scanning directory ${currentPath}:`, error); } } await scanDirectory(dirPath); return pdfFiles; }