fix(filesystem): respect CLI directories when client supports MCP roots#3938
fix(filesystem): respect CLI directories when client supports MCP roots#3938ssam18 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
|
@claude review |
|
Claude finished @cliffhall's task in 1m 47s —— View job PR Review
The fix is correct and minimal — only 7 lines changed across three logical locations. The approach of capturing What works well
Issues1. Misleading log message in the
} else {
if (allowedDirectories.length > 0) {
console.error("Client does not support MCP Roots, using allowed directories set from server args:", allowedDirectories);
} else {
throw new Error(`Server cannot operate: No allowed directories available...`);
}
}The
The log message "Client does not support MCP Roots…" is wrong in case 2. Anyone debugging why the server isn't picking up the client's roots will be confused by the false claim. The fix should add a separate log path: } else {
if (cliDirectoriesProvided) {
console.error("CLI directories provided — ignoring client MCP roots:", allowedDirectories);
} else if (allowedDirectories.length > 0) {
console.error("Client does not support MCP Roots, using allowed directories set from server args:", allowedDirectories);
} else {
throw new Error(`Server cannot operate: ...`);
}
}2. No test coverage for the new behavior The existing suite ( it('should keep CLI directories when client sends roots/list_changed', async () => {
// Start server with a CLI dir, perform MCP init with roots capability,
// send roots/list_changed with a different dir, assert allowed dirs unchanged
});This is more involved (requires MCP handshake simulation), but there's a precedent in the test file structure for integration-style tests. Worth considering for a follow-up. SummaryThe core logic is correct and the fix addresses the bug. The only meaningful issue is the misleading log message in the |
When a client advertises roots support, the server was unconditionally replacing CLI-provided directories with whatever the client returned, making it impossible to scope the server to a directory outside the project root.
The fix tracks whether directories were passed via CLI args at startup and skips the roots fetch in both the
oninitializedhandler and theroots/list_changednotification handler when they were. MCP roots now only kick in as a fallback when no CLI args are given. Fixes #3929