From 64d97ccf30aa1483efa74ead4b11ae60bd924bc8 Mon Sep 17 00:00:00 2001 From: olaservo Date: Thu, 19 Feb 2026 05:53:09 -0700 Subject: [PATCH] fix(filesystem): fix quote style and add fileURLToPath regression test Follow-up to #3205. Fixes import quote style inconsistency (double to single quotes) and adds a regression test using pathToFileURL() to verify properly-encoded file:// URIs are handled correctly on all platforms. Co-Authored-By: Claude Opus 4.6 --- src/filesystem/__tests__/roots-utils.test.ts | 16 ++++++++++++++++ src/filesystem/roots-utils.ts | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) 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.