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
Copy file name to clipboardExpand all lines: src/filesystem/README.md
+44-10Lines changed: 44 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio
4
4
5
5
## Features
6
6
7
-
- Read/write files
7
+
- Read/write files (or run in **strict read-only** mode)
8
8
- Create/list/delete directories
9
9
- Move files/directories
10
10
- Search files
@@ -30,6 +30,29 @@ Roots notified by Client to Server, completely replace any server-side Allowed d
30
30
31
31
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.
32
32
33
+
## Strict Read-Only Mode
34
+
35
+
Strict read-only mode enforces a server-side capability boundary.
36
+
37
+
When enabled, all write-capable tools are not registered, so only read and metadata tools are exposed. This goes beyond `readOnlyHint` annotations, which are advisory metadata for clients/models and not authorization controls.
38
+
39
+
If a client attempts to call a write tool in this mode, the request fails at the protocol layer with `METHOD_NOT_FOUND`.
-`DEFAULT_READ_ONLY=1` starts the server in read-only mode unless explicitly overridden with `--write-enabled` or `READ_ONLY=false`.
49
+
- Use `DEFAULT_READ_ONLY` to set a baseline in images/configuration; use `--write-enabled` for intentional maintenance runs without changing that baseline.
50
+
- If a directory path begins with `--`, include a `--` separator (e.g., `mcp-server-filesystem -- /path/--looks-like-a-flag`).
51
+
52
+
When strict read-only is on, these tools are **not** available: `write_file`, `edit_file`, `create_directory`, `move_file`.
53
+
54
+
The server logs `Read-only mode enabled. Write operations will be disabled.` at startup for visibility.
55
+
33
56
### How It Works
34
57
35
58
The server's directory access control follows this flow:
@@ -43,20 +66,20 @@ The server's directory access control follows this flow:
43
66
- Server checks if client supports roots protocol (`capabilities.roots`)
-**On initialization**: Server requests roots from client via `roots/list`
47
-
- Client responds with its configured roots
48
-
- Server replaces ALL allowed directories with client's roots
49
-
-**On runtime updates**: Client can send `notifications/roots/list_changed`
50
-
- Server requests updated roots and replaces allowed directories again
69
+
-**On initialization**: Server requests roots from client via `roots/list`
70
+
- Client responds with its configured roots
71
+
- Server replaces all allowed directories with the client's roots
72
+
-**On runtime updates**: Client can send `notifications/roots/list_changed`
73
+
- Server requests updated roots and replaces allowed directories again
51
74
52
75
4.**Fallback Behavior** (if client doesn't support roots)
53
76
- Server continues using command-line directories only
54
77
- No dynamic updates possible
55
78
56
79
5.**Access Control**
57
-
- All filesystem operations are restricted to allowed directories
58
-
- Use `list_allowed_directories` tool to see current directories
59
-
- Server requires at least ONE allowed directory to operate
80
+
- All filesystem operations are restricted to allowed directories
81
+
- Use `list_allowed_directories` tool to see current directories
82
+
- Server requires at least one allowed directory to operate
60
83
61
84
**Note**: The server will only allow operations within directories specified either via `args` or via Roots.
62
85
@@ -184,6 +207,8 @@ on each tool so clients can:
184
207
- Understand which write operations are **idempotent** (safe to retry with the same arguments).
185
208
- Highlight operations that may be **destructive** (overwriting or heavily mutating data).
186
209
210
+
These hints are client/model-facing metadata for planning and UX; they do not enforce permissions on the server. For server-side enforcement, use **Strict Read-Only Mode**.
@@ -210,7 +235,7 @@ Add this to your `claude_desktop_config.json`:
210
235
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.
211
236
212
237
### Docker
213
-
Note: all directories must be mounted to `/projects` by default.
238
+
Note: all directories must be mounted to `/projects` by default. The example below starts in read-only mode by default.
214
239
215
240
```json
216
241
{
@@ -221,10 +246,12 @@ Note: all directories must be mounted to `/projects` by default.
0 commit comments