Skip to content

Commit b241a97

Browse files
authored
feat: support environment variables (#46)
* feat: support environment variables * chore: update clap
1 parent 58d97b2 commit b241a97

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,29 @@ 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+
value_parser = clap::value_parser!(bool),
14+
help = "Enables write mode for the app, allowing both reading and writing. Defaults to disabled.",
15+
env = "ALLOW_WRITE"
1316
)]
1417
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>,
2118

2219
#[arg(
2320
short = 't',
2421
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."
22+
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+
action = clap::ArgAction::SetTrue,
24+
value_parser = clap::value_parser!(bool),
25+
env = "ENABLE_ROOTS"
2626
)]
2727
pub enable_roots: bool,
28+
29+
#[arg(
30+
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.",
31+
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"),
32+
required = false
33+
)]
34+
pub allowed_directories: Vec<String>,
2835
}
2936

3037
impl CommandArguments {

0 commit comments

Comments
 (0)