Skip to content

Commit 8850798

Browse files
committed
fix(filesystem): respect CLI directories when client supports MCP roots
1 parent f424458 commit 8850798

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎src/filesystem/index.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030

3131
// Command line argument parsing
3232
const args = process.argv.slice(2);
33+
const cliDirectoriesProvided = args.length > 0;
3334
if (args.length === 0) {
3435
console.error("Usage: mcp-server-filesystem [allowed-directory] [additional-directories...]");
3536
console.error("Note: Allowed directories can be provided via:");
@@ -716,8 +717,10 @@ async function updateAllowedDirectoriesFromRoots(requestedRoots: Root[]) {
716717

717718
// 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.
718719
server.server.setNotificationHandler(RootsListChangedNotificationSchema, async () => {
720+
if (cliDirectoriesProvided) {
721+
return;
722+
}
719723
try {
720-
// Request the updated roots list from the client
721724
const response = await server.server.listRoots();
722725
if (response && 'roots' in response) {
723726
await updateAllowedDirectoriesFromRoots(response.roots);
@@ -731,7 +734,7 @@ server.server.setNotificationHandler(RootsListChangedNotificationSchema, async (
731734
server.server.oninitialized = async () => {
732735
const clientCapabilities = server.server.getClientCapabilities();
733736

734-
if (clientCapabilities?.roots) {
737+
if (clientCapabilities?.roots && !cliDirectoriesProvided) {
735738
try {
736739
const response = await server.server.listRoots();
737740
if (response && 'roots' in response) {

0 commit comments

Comments
 (0)