File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -292,6 +292,16 @@ describe("validateUrl with MCP roots (allowedLocalDirs)", () => {
292292 const result = validateUrl ( pathToFileUrl ( filePath ) ) ;
293293 expect ( result . valid ) . toBe ( true ) ;
294294 } ) ;
295+
296+ it ( "should accept computer:// URLs as local files" , ( ) => {
297+ const dir = path . resolve ( import . meta. dirname ) ;
298+ allowedLocalDirs . add ( dir ) ;
299+
300+ const filePath = path . join ( dir , "server.ts" ) ;
301+ const encoded = encodeURIComponent ( filePath ) . replace ( / % 2 F / g, "/" ) ;
302+ const result = validateUrl ( `computer://${ encoded } ` ) ;
303+ expect ( result . valid ) . toBe ( true ) ;
304+ } ) ;
295305} ) ;
296306
297307describe ( "isAncestorDir" , ( ) => {
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ const DIST_DIR = import.meta.filename.endsWith(".ts")
6060// =============================================================================
6161
6262export function isFileUrl ( url : string ) : boolean {
63- return url . startsWith ( "file://" ) ;
63+ return url . startsWith ( "file://" ) || url . startsWith ( "computer://" ) ;
6464}
6565
6666export function isArxivUrl ( url : string ) : boolean {
@@ -81,7 +81,10 @@ export function normalizeArxivUrl(url: string): string {
8181}
8282
8383export function fileUrlToPath ( fileUrl : string ) : string {
84- return decodeURIComponent ( fileUrl . replace ( "file://" , "" ) ) ;
84+ // Support both file:// and computer:// (used by some clients for local files)
85+ return decodeURIComponent (
86+ fileUrl . replace ( / ^ (?: f i l e | c o m p u t e r ) : \/ \/ / , "" ) ,
87+ ) ;
8588}
8689
8790export function pathToFileUrl ( filePath : string ) : string {
@@ -365,7 +368,7 @@ async function refreshRoots(server: Server): Promise<void> {
365368 const { roots } = await server . listRoots ( ) ;
366369 allowedLocalDirs . clear ( ) ;
367370 for ( const root of roots ) {
368- if ( root . uri . startsWith ( "file://" ) ) {
371+ if ( isFileUrl ( root . uri ) ) {
369372 const dir = fileUrlToPath ( root . uri ) ;
370373 const resolved = path . resolve ( dir ) ;
371374 try {
You can’t perform that action at this time.
0 commit comments