Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/filesystem/__tests__/roots-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/roots-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down