MCPcopy Index your code
hub / github.com/modelcontextprotocol/servers / parseRootUri

Function parseRootUri

src/filesystem/roots-utils.ts:13–25  ·  view source on GitHub ↗

* Converts a root URI to a normalized directory path with basic security validation. * @param rootUri - File URI (file://...) or plain directory path * @returns Promise resolving to validated path or null if invalid

(rootUri: string)

Source from the content-addressed store, hash-verified

11 * @returns Promise resolving to validated path or null if invalid
12 */
13async function parseRootUri(rootUri: string): Promise<string | null> {
14 try {
15 const rawPath = rootUri.startsWith('file://') ? fileURLToPath(rootUri) : rootUri;
16 const expandedPath = rawPath.startsWith('~/') || rawPath === '~'
17 ? path.join(os.homedir(), rawPath.slice(1))
18 : rawPath;
19 const absolutePath = path.resolve(expandedPath);
20 const resolvedPath = await fs.realpath(absolutePath);
21 return normalizePath(resolvedPath);
22 } catch {
23 return null; // Path doesn't exist or other error
24 }
25}
26
27/**
28 * Formats error message for directory validation failures.

Callers 1

getValidRootDirectoriesFunction · 0.85

Calls 1

normalizePathFunction · 0.85

Tested by

no test coverage detected