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 f3222de
Browse filesBrowse the repository at this point in the historyBrowse files
fix(filesystem): close two read-only-dir bypasses found in review
move_file now validates both ends in a "move" mode that also refuses a
path containing a read-only directory, so moving its parent cannot carry
a protected subtree out from under the marking. A read-only directory
that does not exist yet is resolved through its nearest existing
ancestor, so a symlinked ancestor cannot leave it unprotected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Copy file name to clipboardExpand all lines: .changeset/filesystem-5348-read-only-dirs.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,4 +2,4 @@
2
2
"@modelcontextprotocol/server-filesystem": minor
3
3
---
4
4
5
-
Add `--read-only-dir <path>`, repeatable, to make one allowed directory read-only while the others stay writable. Every write tool stays listed but refuses a target inside a read-only directory (`move_file` on either end, `copy_file` on its destination), checked on the resolved path so a symlink cannot route around it; a 2025-era client's Roots never lift the marking. `list_allowed_directories` names the read-only directories.
5
+
Add `--read-only-dir <path>`, repeatable, to make one allowed directory read-only while the others stay writable. Every write tool stays listed but refuses a target inside a read-only directory (`move_file` on either end, including moving a directory that contains one, and `copy_file` on its destination), checked on the resolved path so a symlink cannot route around it; a 2025-era client's Roots never lift the marking. `list_allowed_directories` names the read-only directories.
Copy file name to clipboardExpand all lines: src/filesystem/README.md
+42-30Lines changed: 42 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,9 @@ Published on npm as [`@modelcontextprotocol/server-filesystem`](https://www.npmj
19
19
The server may touch only its **allowed directories**. Pass them on the command line. A 2025-era client that supports [Roots](https://modelcontextprotocol.io/docs/learn/client-concepts#roots) can also replace them at runtime, but Roots is [deprecated as of protocol version 2026-07-28](https://modelcontextprotocol.io/specification/2026-07-28/deprecated) and a 2026-07-28 connection cannot use it.
- A read-only directory is an allowed directory too, so it need not also be listed on its own.
50
-
- Every write tool (`write_file`, `append_file`, `edit_file`, `create_directory`, `move_file` and `copy_file`) stays listed, since the other directories are writable, but refuses a target inside a read-only directory with an error such as `Access denied - read-only directory: /path/to/reference/notes.md is in /path/to/reference, which the server was started with --read-only-dir`. `move_file` is refused when either its source or its destination is inside one; `copy_file` may copy out of one, never into it. `edit_file` is refused there even with `dryRun`.
51
-
- The check runs on a path's resolved location, so a symlink in a writable directory cannot route a write into a read-only one.
56
+
- Every write tool (`write_file`, `append_file`, `edit_file`, `create_directory`, `move_file` and `copy_file`) stays listed, since the other directories are writable, but refuses a target inside a read-only directory with an error such as `Access denied - read-only directory: /path/to/reference/notes.md is in /path/to/reference, which the server was started with --read-only-dir`. `move_file` is refused when either its source or its destination is inside one or contains one, so a protected directory cannot be carried away by moving its parent; `copy_file` may copy out of one, never into it. `edit_file` is refused there even with `dryRun`.
57
+
- The check runs on a path's resolved location, so a symlink in a writable directory cannot route a write into a read-only one. A read-only directory that does not exist yet is still protected: it is resolved through its nearest existing ancestor, so it covers the path a write would create.
52
58
- A path inside any read-only directory is refused, so a directory nested inside a read-only one is read-only too, even if it is also given as a writable directory.
53
59
- The marking is fixed at startup and holds on both protocol eras. A 2025-era client's Roots can replace the allowed directories (see Method 2), but Roots say nothing about writing, so they never lift it: a write into a read-only directory is refused whichever directories are in force, with or without `--confine-roots`.
54
60
-`list_allowed_directories` lists the read-only directories after the allowed ones, and the server logs them to stderr at startup.
55
61
56
62
The option may appear anywhere among the arguments, and takes the next argument as its directory, whatever it is. `--` ends the options, so after it `--read-only-dir` is a directory name. With `--read-only` as well, every write tool is withheld anyway. For defence in depth, make the protected directories read-only at the operating-system level as well, with file permissions or, with Docker, a bind mount's `ro` flag.
A client that connects with a 2025-era protocol version (the `initialize` handshake) and supports [Roots](https://modelcontextprotocol.io/docs/learn/client-concepts#roots) can dynamically update the Allowed directories.
60
67
61
68
Roots notified by Client to Server, completely replace any server-side Allowed directories when provided.
62
69
63
70
#### Confining Roots to the command-line directories
71
+
64
72
To keep a client's Roots inside the directories you gave on the command line, add `--confine-roots`:
@@ -92,7 +101,6 @@ The server's directory access control follows this flow:
92
101
- The client's first message picks the protocol era of the connection
93
102
- A **2026-07-28** client sends `server/discover` (or any request carrying the per-request `_meta` envelope): the server uses the command-line directories, and steps 3 and 4 do not apply
94
103
- A **2025-era** client sends `initialize` with its capabilities, and the server checks whether it supports roots (`capabilities.roots`)
95
-
96
104
3.**Roots Protocol Handling** (2025-era clients that support roots)
97
105
-**On initialization**: Server requests roots from client via `roots/list`
98
106
- Client responds with its configured roots
@@ -120,8 +128,6 @@ The server's directory access control follows this flow:
120
128
121
129
**Note**: The server will only allow operations within directories specified either via `args` or, for a 2025-era client, via Roots.
122
130
123
-
124
-
125
131
## API
126
132
127
133
### Resources
@@ -295,7 +301,6 @@ Files inside the allowed directories are also [resources](https://modelcontextpr
295
301
entries below it do not count toward the 100,000-entry bound
296
302
- Output is formatted with 2-space indentation for readability
297
303
- Bounded: see [Slow and very large trees](#slow-and-very-large-trees)
298
-
299
304
- **get_file_info**
300
305
- Get detailed file/directory metadata
301
306
- Input: `path` (string)
@@ -326,11 +331,11 @@ request from stalling the server:
326
331
- **Resolving a path (in any tool), and each directory read in `search_files`
327
332
and `directory_tree`, waits at most 15 seconds.** A call that takes longer ends
328
333
the request with an error naming the path (`Filesystem call timed out after
329
-
15000 ms: ...`). A path whose real location cannot be read in time is
334
+
15000 ms: ...`). A path whose real location cannot be read in time is
330
335
refused, never admitted.
331
336
- **`search_files` and `directory_tree` visit at most 100,000 entries.** A walk
332
337
that reaches the cap ends with an error (`... stopped after visiting 100000
333
-
entries ...`) rather than a partial result. Excluded entries do not count.
338
+
entries ...`) rather than a partial result. Excluded entries do not count.
334
339
335
340
Either error means: narrow `path`, or name the slow or large folder in
336
341
`excludePatterns`. A timed-out call cannot be cancelled and finishes in the
@@ -349,23 +354,23 @@ on each tool so clients can:
| `copy_file` | `false` | `true` | `false` | Never overwrites; a repeat fails, changing nothing |
370
375
371
376
> Note: the MCP spec gives `idempotentHint` and `destructiveHint` meaning only when `readOnlyHint` is `false`, but every tool sets them anyway, so a client that reads them without checking `readOnlyHint` first still sees the truth: a read can be repeated safely and changes nothing. Every tool also sets `openWorldHint: false` — this server only accesses the local filesystem within its allowed directories, never an open or external world.
@@ -375,11 +380,13 @@ The mapping for filesystem tools is:
375
380
Node.js 24 or later, when the server runs through `npx` or from source.
376
381
377
382
## Usage with Claude Desktop
383
+
378
384
Add this to your `claude_desktop_config.json`:
379
385
380
386
Note: you can provide sandboxed directories to the server by mounting them to `/projects`. Adding the `ro` flag will make the directory readonly by the server.
381
387
382
388
### Docker
389
+
383
390
Note: all directories must be mounted to `/projects` by default.
384
391
385
392
```json
@@ -391,9 +398,12 @@ Note: all directories must be mounted to `/projects` by default.
@@ -461,7 +471,8 @@ Alternatively, you can add the configuration to a file called `.vscode/mcp.json`
461
471
You can provide sandboxed directories to the server by mounting them to `/projects`. Adding the `ro` flag will make the directory readonly by the server.
462
472
463
473
### Docker
464
-
Note: all directories must be mounted to `/projects` by default.
474
+
475
+
Note: all directories must be mounted to `/projects` by default.
465
476
466
477
```json
467
478
{
@@ -472,7 +483,8 @@ Note: all directories must be mounted to `/projects` by default.
0 commit comments