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

Function refreshRoots

examples/pdf-server/server.ts:954–985  ·  view source on GitHub ↗

* Query the client for roots and update allowedLocalDirs with any file:// roots * that point to existing directories.

(server: Server)

Source from the content-addressed store, hash-verified

952 * that point to existing directories.
953 */
954async function refreshRoots(server: Server): Promise<void> {
955 if (!server.getClientCapabilities()?.roots) return;
956
957 try {
958 const { roots } = await server.listRoots();
959 allowedLocalDirs.clear();
960 for (const root of roots) {
961 if (isFileUrl(root.uri)) {
962 const dir = fileUrlToPath(root.uri);
963 const resolved = path.resolve(dir);
964 try {
965 const s = fs.statSync(resolved);
966 if (s.isFile()) {
967 console.error(
968 `[pdf-server] Root is a file, not a directory (skipped): ${resolved}`,
969 );
970 allowedLocalFiles.add(resolved);
971 } else if (s.isDirectory()) {
972 allowedLocalDirs.add(resolved);
973 console.error(`[pdf-server] Root directory allowed: ${resolved}`);
974 }
975 } catch {
976 // stat failed — skip non-existent roots
977 }
978 }
979 }
980 } catch (err) {
981 console.error(
982 `[pdf-server] Failed to list roots: ${err instanceof Error ? err.message : err}`,
983 );
984 }
985}
986
987// =============================================================================
988// PDF Form Field Extraction

Callers 1

createServerFunction · 0.85

Calls 2

isFileUrlFunction · 0.85
fileUrlToPathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…