From 88507985dced5fbf5d9d4f5ca2e428d2d41a6ac0 Mon Sep 17 00:00:00 2001 From: Samaresh Kumar Singh Date: Mon, 13 Apr 2026 16:41:35 -0500 Subject: [PATCH] fix(filesystem): respect CLI directories when client supports MCP roots --- src/filesystem/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 7b67e63e58..aa73122339 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -30,6 +30,7 @@ import { // Command line argument parsing const args = process.argv.slice(2); +const cliDirectoriesProvided = args.length > 0; if (args.length === 0) { console.error("Usage: mcp-server-filesystem [allowed-directory] [additional-directories...]"); console.error("Note: Allowed directories can be provided via:"); @@ -716,8 +717,10 @@ async function updateAllowedDirectoriesFromRoots(requestedRoots: Root[]) { // Handles dynamic roots updates during runtime, when client sends "roots/list_changed" notification, server fetches the updated roots and replaces all allowed directories with the new roots. server.server.setNotificationHandler(RootsListChangedNotificationSchema, async () => { + if (cliDirectoriesProvided) { + return; + } try { - // Request the updated roots list from the client const response = await server.server.listRoots(); if (response && 'roots' in response) { await updateAllowedDirectoriesFromRoots(response.roots); @@ -731,7 +734,7 @@ server.server.setNotificationHandler(RootsListChangedNotificationSchema, async ( server.server.oninitialized = async () => { const clientCapabilities = server.server.getClientCapabilities(); - if (clientCapabilities?.roots) { + if (clientCapabilities?.roots && !cliDirectoriesProvided) { try { const response = await server.server.listRoots(); if (response && 'roots' in response) {