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
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"directory_path": "<directory_path>"
},
"name": "discover_pdfs"
}
}Input 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; }