Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Loading