Skip to content

Commit 7161afa

Browse files
committed
feat: support environment variables
1 parent 8177514 commit 7161afa

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ glob = "0.3"
2828
walkdir = "2.5"
2929
similar = "=2.7"
3030
chrono = "0.4"
31-
clap = { version = "4.5", features = ["derive"] }
31+
clap = { version = "4.5", features = ["derive","env"] }
3232
tokio = "1.4"
3333
serde = "1.0"
3434
serde_json = "1.0"

docs/_configs/claude-desktop.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ Incorporate the following into your `claude_desktop_config.json`, based on your
3535

3636
## Running via Docker
3737

38-
**Note:** In the example below, all allowed directories are mounted to `/projects`, and `/projects` is passed as the allowed directory argument to the server CLI. You can modify this as needed to fit your requirements.
38+
**Note:** In the example below, all allowed directories are mounted to `/projects`, and `/projects` is passed as the allowed directory argument to the server CLI. You can modify this as needed to fit your requirements.
39+
40+
`ALLOW_WRITE` and `ENABLE_ROOTS` environments could be used to enable write and MCP Roots support.
3941

4042
```json
4143
{
@@ -46,6 +48,10 @@ Incorporate the following into your `claude_desktop_config.json`, based on your
4648
"run",
4749
"-i",
4850
"--rm",
51+
"-e",
52+
"ALLOW_WRITE=false",
53+
"-e",
54+
"ENABLE_ROOTS=false",
4955
"--mount",
5056
"type=bind,src=/Users/username/Documents,dst=/projects/Documents",
5157
"--mount",

docs/guide/cli-command-options.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ Arguments:
1111
Example: rust-mcp-filesystem /path/to/dir1 /path/to/dir2 /path/to/dir3
1212

1313
Options:
14-
-w, --allow-write
15-
Enables read/write mode for the app, allowing both reading and writing. Defaults to disabled.
14+
-w, --allow-write [<ALLOW_WRITE>]
15+
Enables write mode for the app, allowing both reading and writing. Defaults to disabled.
1616

17-
-t, --enable-roots
17+
[env: ALLOW_WRITE=]
18+
[default: false]
19+
[possible values: true, false]
20+
21+
-t, --enable-roots [<ENABLE_ROOTS>]
1822
Enables dynamic directory access control via Roots from the MCP client side. Defaults to disabled.
1923
When enabled, MCP clients that support Roots can dynamically update the allowed directories.
2024
Any directories provided by the client will completely replace the initially configured allowed directories on the server.
2125

26+
[env: ENABLE_ROOTS=true]
27+
[default: false]
28+
[possible values: true, false]
29+
2230
-h, --help
2331
Print help (see a summary with '-h')
2432

src/cli.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,31 @@ pub struct CommandArguments {
99
#[arg(
1010
short = 'w',
1111
long,
12-
help = "Enables read/write mode for the app, allowing both reading and writing. Defaults to disabled."
12+
action = clap::ArgAction::SetTrue,
13+
num_args = 0..=1,
14+
value_parser = clap::value_parser!(bool),
15+
help = "Enables write mode for the app, allowing both reading and writing. Defaults to disabled.",
16+
env = "ALLOW_WRITE"
1317
)]
1418
pub allow_write: bool,
15-
#[arg(
16-
help = "List of directories that are permitted for the operation. It is required when 'enable-roots' is not provided OR client does not support Roots.",
17-
long_help = concat!("Provide a space-separated list of directories that are permitted for the operation.\nThis list allows multiple directories to be provided.\n\nExample: ", env!("CARGO_PKG_NAME"), " /path/to/dir1 /path/to/dir2 /path/to/dir3"),
18-
required = false
19-
)]
20-
pub allowed_directories: Vec<String>,
2119

2220
#[arg(
2321
short = 't',
2422
long,
25-
help = "Enables dynamic directory access control via Roots from the MCP client side. Defaults to disabled.\nWhen enabled, MCP clients that support Roots can dynamically update the allowed directories.\nAny directories provided by the client will completely replace the initially configured allowed directories on the server."
23+
help = "Enables dynamic directory access control via Roots from the MCP client side. Defaults to disabled.\nWhen enabled, MCP clients that support Roots can dynamically update the allowed directories.\nAny directories provided by the client will completely replace the initially configured allowed directories on the server.",
24+
action = clap::ArgAction::SetTrue,
25+
num_args = 0..=1,
26+
value_parser = clap::value_parser!(bool),
27+
env = "ENABLE_ROOTS"
2628
)]
2729
pub enable_roots: bool,
30+
31+
#[arg(
32+
help = "List of directories that are permitted for the operation. It is required when 'enable-roots' is not provided OR client does not support Roots.",
33+
long_help = concat!("Provide a space-separated list of directories that are permitted for the operation.\nThis list allows multiple directories to be provided.\n\nExample: ", env!("CARGO_PKG_NAME"), " /path/to/dir1 /path/to/dir2 /path/to/dir3"),
34+
required = false
35+
)]
36+
pub allowed_directories: Vec<String>,
2837
}
2938

3039
impl CommandArguments {

0 commit comments

Comments
 (0)