MCPcopy Create free account
hub / github.com/modelcontextprotocol/ext-apps / walk

Function walk

examples/pdf-server/server.ts:1316–1341  ·  view source on GitHub ↗
(dir: string, depth: number)

Source from the content-addressed store, hash-verified

1314 const WALK_MAX_FILES = 500;
1315 let truncated = false;
1316 const walk = async (dir: string, depth: number): Promise<void> => {
1317 if (depth > WALK_MAX_DEPTH || localFiles.length >= WALK_MAX_FILES) {
1318 truncated ||= localFiles.length >= WALK_MAX_FILES;
1319 return;
1320 }
1321 let entries;
1322 try {
1323 entries = await fs.promises.readdir(dir, { withFileTypes: true });
1324 } catch {
1325 return; // unreadable — skip silently
1326 }
1327 for (const e of entries) {
1328 if (localFiles.length >= WALK_MAX_FILES) {
1329 truncated = true;
1330 return;
1331 }
1332 // Skip dotfiles/dirs and common noise
1333 if (e.name.startsWith(".") || e.name === "node_modules") continue;
1334 const full = path.join(dir, e.name);
1335 if (e.isDirectory()) {
1336 await walk(full, depth + 1);
1337 } else if (e.isFile() && /\.pdf$/i.test(e.name)) {
1338 addLocal(full);
1339 }
1340 }
1341 };
1342 for (const dir of allowedLocalDirs) await walk(dir, 0);
1343
1344 // Build text

Callers 1

createServerFunction · 0.85

Calls 1

addLocalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…