You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2309e08
Browse filesBrowse the repository at this point in the historyBrowse files
fix(filesystem): wait for initial roots; fail visibly with no directories
Tool calls now wait for the client's initial roots/list to settle before
they run, so a call sent right after initialize is checked against the
client's roots rather than refused with "Access denied" (#3204).
With no command-line directories and a client without Roots support, the
server no longer throws from oninitialized (an error the client never
saw). It logs the reason, closes the connection, and the stdio entry
point exits with status 1, as the README describes (#4992). The README
now also says what happens when a Roots client provides no roots.
The pinning tests assert the fixed behavior and lose their KNOWN BUG
markers.
Closes#3204Closes#4992
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
Tool calls now wait for the client's initial roots before checking paths, so a call sent right after connecting is no longer refused with "Access denied" (#3204). A server started with no directories, connected to a client without Roots support, now fails visibly: it logs the reason, closes the connection and exits with status 1, instead of staying up and refusing every call (#4992).
Copy file name to clipboardExpand all lines: src/filesystem/README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ MCP clients that support [Roots](https://modelcontextprotocol.io/docs/learn/clie
28
28
29
29
Roots notified by Client to Server, completely replace any server-side Allowed directories when provided.
30
30
31
-
**Important**: If server starts without command-line arguments AND client doesn't support roots protocol(or provides empty roots), the server will throw an error during initialization.
31
+
**Important**: If server starts without command-line arguments AND client doesn't support roots protocol, the server fails at initialization: it logs the reason to stderr, closes the connection and exits with status 1. A client that supports roots but provides none (or none that are valid) keeps the connection, with no allowed directories until it sends `roots/list_changed` with valid roots.
32
32
33
33
This is the recommended method, as this enables runtime directory updates via `roots/list_changed` notifications without server restart, providing a more flexible and modern integration experience.
34
34
@@ -48,12 +48,14 @@ The server's directory access control follows this flow:
48
48
-**On initialization**: Server requests roots from client via `roots/list`
49
49
- Client responds with its configured roots
50
50
- Server replaces ALL allowed directories with client's roots
51
+
- Tool calls that arrive before the initial roots are loaded wait for them, so they are checked against the client's roots
51
52
-**On runtime updates**: Client can send `notifications/roots/list_changed`
52
53
- Server requests updated roots and replaces allowed directories again
53
54
54
55
4.**Fallback Behavior** (if client doesn't support roots)
55
56
- Server continues using command-line directories only
56
57
- No dynamic updates possible
58
+
- With no command-line directories either, the server logs an error, closes the connection and exits with status 1
57
59
58
60
5.**Access Control**
59
61
- All filesystem operations are restricted to allowed directories
@@ -247,15 +286,18 @@ describe("a client without the roots capability", () => {
247
286
);
248
287
});
249
288
250
-
// KNOWN BUG #4992: with no directories and no Roots, the initialization error the README promises is swallowed and the session stays up with nothing allowed; the fix changes this assertion.
251
-
// With no directories from either source, oninitialized throws. The SDK
252
-
// routes a notification handler's rejection to the server's onerror, which
253
-
// the server leaves unset, so the error is invisible to the client: the
254
-
// session stays up and every path is refused.
255
-
it("stays connected with nothing allowed when no directories were given",async()=>{
289
+
// #4992: with no directories from either source nothing could ever be
290
+
// allowed, so the server says why on stderr and closes the connection
291
+
// rather than staying up and refusing every call.
292
+
it("closes the connection with an error when no directories were given (#4992)",async()=>{
Copy file name to clipboardExpand all lines: src/filesystem/server.ts
+54-7Lines changed: 54 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -131,19 +131,56 @@ async function readFileAsBase64Stream(filePath: string): Promise<string> {
131
131
});
132
132
}
133
133
134
+
/**
135
+
* Why the server cannot operate when it has no allowed directories from either
136
+
* the command line or the client's Roots (#4992).
137
+
*/
138
+
exportconstNO_ALLOWED_DIRECTORIES_ERROR=
139
+
"Server cannot operate: No allowed directories available. Server was started without command-line directories and client does not support MCP roots protocol. Please either: 1) Start server with directory arguments, or 2) Use a client that supports MCP roots protocol and provides valid root directories.";
140
+
141
+
exportinterfaceServerOptions{
142
+
/**
143
+
* Called after the server has closed the connection because it cannot
144
+
* operate: no directories were given and the client does not support
145
+
* Roots (#4992). The stdio entry point exits the process from here.
146
+
*/
147
+
onCannotOperate?: (error: Error)=>void;
148
+
}
149
+
134
150
/**
135
151
* Build a filesystem server that may touch only `initialAllowedDirectories`
136
152
* (already resolved and normalized by the caller) until the client's Roots
@@ -767,12 +809,17 @@ export function createServer(initialAllowedDirectories: string[]): McpServer {
767
809
allowedDirectories,
768
810
);
769
811
}else{
770
-
thrownewError(
771
-
`Server cannot operate: No allowed directories available. Server was started without command-line directories and client either does not support MCP roots protocol or provided empty roots. Please either: 1) Start server with directory arguments, or 2) Use a client that supports MCP roots protocol and provides valid root directories.`,
772
-
);
812
+
// Nothing could ever be allowed in this session, so fail visibly
813
+
// rather than serve every call with "Access denied" (#4992): log the
814
+
// reason and close the connection. Throwing here would only reach the
0 commit comments