diff --git a/src/filesystem/__tests__/roots-utils.test.ts b/src/filesystem/__tests__/roots-utils.test.ts index 1a39483953..d279a5ae60 100644 --- a/src/filesystem/__tests__/roots-utils.test.ts +++ b/src/filesystem/__tests__/roots-utils.test.ts @@ -3,6 +3,7 @@ import { getValidRootDirectories } from '../roots-utils.js'; import { mkdtempSync, rmSync, mkdirSync, writeFileSync, realpathSync } from 'fs'; import { tmpdir } from 'os'; import { join } from 'path'; +import { pathToFileURL } from 'url'; import type { Root } from '@modelcontextprotocol/sdk/types.js'; describe('getValidRootDirectories', () => { @@ -45,6 +46,21 @@ describe('getValidRootDirectories', () => { expect(result).toHaveLength(3); }); + it('should handle standard file URIs from pathToFileURL', async () => { + // pathToFileURL produces properly-encoded URIs (e.g. file:///C:/... on Windows) + // This is the format VS Code and other editors send via MCP roots + const roots: Root[] = [ + { uri: pathToFileURL(testDir1).href, name: 'Standard File URI' }, + { uri: pathToFileURL(testDir2).href, name: 'Standard File URI 2' }, + ]; + + const result = await getValidRootDirectories(roots); + + expect(result).toContain(testDir1); + expect(result).toContain(testDir2); + expect(result).toHaveLength(2); + }); + it('should normalize complex paths', async () => { const subDir = join(testDir1, 'subdir'); mkdirSync(subDir); diff --git a/src/filesystem/roots-utils.ts b/src/filesystem/roots-utils.ts index 5e26bb246b..2a97cbdb0e 100644 --- a/src/filesystem/roots-utils.ts +++ b/src/filesystem/roots-utils.ts @@ -3,7 +3,7 @@ import path from 'path'; import os from 'os'; import { normalizePath } from './path-utils.js'; import type { Root } from '@modelcontextprotocol/sdk/types.js'; -import { fileURLToPath } from "url"; +import { fileURLToPath } from 'url'; /** * Converts a root URI to a normalized directory path with basic security validation.